From 803f6e8ecd6ef2e40e97cce6b514dd44279cd0f9 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Thu, 9 Aug 2012 13:25:01 +0200 Subject: Replace test-compile with compile_only=true option --- src/rebar.erl | 4 +--- src/rebar_eunit.erl | 38 ++++++++++++++++++-------------------- src/rebar_qc.erl | 11 +++++++++++ src/rebar_utils.erl | 11 +++++++++++ 4 files changed, 41 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/rebar.erl b/src/rebar.erl index 7680d5a..44ba00b 100644 --- a/src/rebar.erl +++ b/src/rebar.erl @@ -297,7 +297,6 @@ generate-upgrade previous_release=path Build an upgrade package generate-appups previous_release=path Generate appup files -test-compile Compile sources for eunit/qc run eunit [suites=foo] Run eunit [test/foo_tests.erl] tests ct [suites=] [case=] Run common_test suites @@ -366,8 +365,7 @@ command_names() -> ["check-deps", "clean", "compile", "create", "create-app", "create-node", "ct", "delete-deps", "doc", "eunit", "generate", "generate-appups", "generate-upgrade", "get-deps", "help", "list-deps", "list-templates", - "test-compile", "qc", "update-deps", "overlay", "shell", "version", - "xref"]. + "qc", "update-deps", "overlay", "shell", "version", "xref"]. unabbreviate_command_names([]) -> []; diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index b1bcdaf..772c671 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -54,8 +54,7 @@ -module(rebar_eunit). -export([eunit/2, - clean/2, - 'test-compile'/2]). + clean/2]). -include("rebar.hrl"). @@ -67,9 +66,25 @@ eunit(Config, _AppFile) -> ok = ensure_dirs(), %% Save code path CodePath = setup_code_path(), - + CompileOnly = rebar_utils:get_experimental_global(Config, compile_only, + false), {ok, SrcErls} = rebar_erlc_compiler:test_compile(Config), + case CompileOnly of + "true" -> + true = code:set_path(CodePath), + ?CONSOLE("Compiled modules for eunit~n", []); + false -> + run_eunit(Config, CodePath, SrcErls) + end. + +clean(_Config, _File) -> + rebar_file_utils:rm_rf(?TEST_DIR). +%% =================================================================== +%% Internal functions +%% =================================================================== + +run_eunit(Config, CodePath, SrcErls) -> %% Build a list of all the .beams in ?TEST_DIR -- use this for %% cover and eunit testing. Normally you can just tell cover %% and/or eunit to scan the directory for you, but eunit does a @@ -128,23 +143,6 @@ eunit(Config, _AppFile) -> true = code:set_path(CodePath), ok. -clean(_Config, _File) -> - rebar_file_utils:rm_rf(?TEST_DIR). - -'test-compile'(Config, _File) -> - ?CONSOLE("NOTICE: Using experimental 'test-compile' command~n", []), - ok = ensure_dirs(), - %% Save code path - CodePath = setup_code_path(), - {ok, _SrcErls} = rebar_erlc_compiler:test_compile(Config), - %% Restore code path - true = code:set_path(CodePath), - ok. - -%% =================================================================== -%% Internal functions -%% =================================================================== - ensure_dirs() -> %% Make sure ?TEST_DIR/ and ebin/ directory exists (append dummy module) ok = filelib:ensure_dir(filename:join(rebar_utils:test_dir(), "dummy")), diff --git a/src/rebar_qc.erl b/src/rebar_qc.erl index 051400f..1800540 100644 --- a/src/rebar_qc.erl +++ b/src/rebar_qc.erl @@ -114,11 +114,22 @@ run(Config, QC, QCOpts) -> ok = filelib:ensure_dir(?TEST_DIR ++ "/foo"), CodePath = setup_codepath(), + CompileOnly = rebar_utils:get_experimental_global(Config, compile_only, + false), %% Compile erlang code to ?TEST_DIR, using a tweaked config %% with appropriate defines, and include all the test modules %% as well. {ok, _SrcErls} = rebar_erlc_compiler:test_compile(Config), + case CompileOnly of + "true" -> + true = code:set_path(CodePath), + ?CONSOLE("Compiled modules for qc~n", []); + false -> + run1(QC, QCOpts, CodePath) + end. + +run1(QC, QCOpts, CodePath) -> TestModule = fun(M) -> qc_module(QC, QCOpts, M) end, case lists:flatmap(TestModule, find_prop_mods()) of [] -> diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 66cd7e2..a39e263 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -45,6 +45,7 @@ vcs_vsn/3, deprecated/3, deprecated/4, get_deprecated_global/4, get_deprecated_global/5, + get_experimental_global/3, get_deprecated_list/4, get_deprecated_list/5, get_deprecated_local/4, get_deprecated_local/5, delayed_halt/1, @@ -230,6 +231,16 @@ get_deprecated_global(Config, OldOpt, NewOpt, Default, When) -> New end. +get_experimental_global(Config, Opt, Default) -> + Val = rebar_config:get_global(Config, Opt, Default), + case Val of + Default -> + Default; + Val -> + ?CONSOLE("NOTICE: Using experimental option '~p'~n", [Opt]), + Val + end. + get_deprecated_list(Config, OldOpt, NewOpt, When) -> get_deprecated_list(Config, OldOpt, NewOpt, undefined, When). -- cgit v1.1