diff options
Diffstat (limited to 'test/rebar_compile_SUITE.erl')
-rw-r--r-- | test/rebar_compile_SUITE.erl | 100 |
1 files changed, 95 insertions, 5 deletions
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index 7e72404..3f95e4f 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -19,7 +19,9 @@ delete_beam_if_source_deleted/1, checkout_priority/1, highest_version_of_pkg_dep/1, - parse_transform_test/1]). + parse_transform_test/1, + erl_first_files_test/1, + mib_test/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -46,7 +48,8 @@ all() -> build_all_srcdirs, recompile_when_hrl_changes, recompile_when_opts_change, dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl, delete_beam_if_source_deleted, - deps_in_path, checkout_priority, highest_version_of_pkg_dep, parse_transform_test]. + deps_in_path, checkout_priority, highest_version_of_pkg_dep, + parse_transform_test, erl_first_files_test, mib_test]. build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -161,9 +164,10 @@ recompile_when_hrl_changes(Config) -> ModTime = [filelib:last_modified(filename:join([EbinDir, F])) || F <- Files, filename:extension(F) == ".beam"], + timer:sleep(1000), - os:cmd("touch " ++ HeaderFile), + rebar_file_utils:touch(HeaderFile), rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), @@ -272,9 +276,9 @@ delete_beam_if_source_deleted(Config) -> rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]), - SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]), + _SrcDir = filename:join([AppDir, "_build", "default", "lib", Name, "src"]), ?assert(filelib:is_regular(filename:join(EbinDir, "not_a_real_src_" ++ Name ++ ".beam"))), - file:delete(filename:join(SrcDir, "not_a_real_src_" ++ Name ++ ".erl")), + file:delete(filename:join([AppDir, "src", "not_a_real_src_" ++ Name ++ ".erl"])), rebar_test_utils:run_and_check(Config, [], ["compile"], {ok, [{app, Name}]}), @@ -305,6 +309,7 @@ deps_in_path(Config) -> ?assertEqual([], [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, DepName)]]), %% Hope not to find pkg name in there + ?assertEqual([], [Path || Path <- code:get_path(), {match, _} <- [re:run(Path, PkgName)]]), %% Build things @@ -441,3 +446,88 @@ parse_transform_test(Config) -> EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]), true = filelib:is_file(filename:join([EbinDir, "pascal.beam"])). + +erl_first_files_test(Config) -> + AppDir = ?config(apps, Config), + RebarConfig = [{erl_opts, [{parse_transform, mark_time}]}, + {erl_first_files, ["src/mark_time.erl", + "src/b.erl", + "src/d.erl", + "src/a.erl"]}], + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + rebar_test_utils:write_src_file(AppDir, "a.erl"), + rebar_test_utils:write_src_file(AppDir, "b.erl"), + rebar_test_utils:write_src_file(AppDir, "d.erl"), + rebar_test_utils:write_src_file(AppDir, "e.erl"), + + ExtraSrc = <<"-module(mark_time). " + "-export([parse_transform/2]). " + "parse_transform([Form={attribute,_,module,Mod}|Forms], Options) -> " + " [Form, {attribute,1,number, os:timestamp()} | Forms];" + "parse_transform([Form|Forms], Options) -> " + " [Form | parse_transform(Forms, Options)].">>, + + ok = file:write_file(filename:join([AppDir, "src", "mark_time.erl"]), ExtraSrc), + + rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}), + + EbinDir = filename:join([AppDir, "_build", "default", "lib", Name, "ebin"]), + true = filelib:is_file(filename:join([EbinDir, "mark_time.beam"])), + + code:load_abs(filename:join([EbinDir, "a"])), + code:load_abs(filename:join([EbinDir, "b"])), + code:load_abs(filename:join([EbinDir, "d"])), + code:load_abs(filename:join([EbinDir, "e"])), + A = proplists:get_value(number, a:module_info(attributes)), + B = proplists:get_value(number, b:module_info(attributes)), + D = proplists:get_value(number, d:module_info(attributes)), + E = proplists:get_value(number, e:module_info(attributes)), + ?assertEqual([B,D,A,E], lists:sort([A,B,D,E])). + +mib_test(Config) -> + AppDir = ?config(apps, Config), + + RebarConfig = [], + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + MibsSrc = <<"-- SIMPLE-MIB.\n" +"-- This is just a simple MIB used for testing!\n" +"--\n" +"SIMPLE-MIB DEFINITIONS ::= BEGIN\n" +"IMPORTS\n" +" MODULE-IDENTITY, enterprises\n" +" FROM SNMPv2-SMI;\n" +"\n" +"ericsson MODULE-IDENTITY\n" +" LAST-UPDATED\n" +" \"201403060000Z\"\n" +" ORGANIZATION\n" +" \"rebar\"\n" +" CONTACT-INFO\n" +" \"rebar <rebar@example.com>\n" +" or\n" +" whoever is currently responsible for the SIMPLE\n" +" enterprise MIB tree branch (enterprises.999).\"\n" +" DESCRIPTION\n" +" \"This very small module is made available\n" +" for mib-compilation testing.\"\n" +" ::= { enterprises 999 }\n" +"END\n">>, + + ok = filelib:ensure_dir(filename:join([AppDir, "mibs", "dummy"])), + ok = file:write_file(filename:join([AppDir, "mibs", "SIMPLE-MIB.mib"]), MibsSrc), + + rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], {ok, [{app, Name}]}), + + %% check a beam corresponding to the src in the extra src_dir exists in ebin + PrivMibsDir = filename:join([AppDir, "_build", "default", "lib", Name, "priv", "mibs"]), + true = filelib:is_file(filename:join([PrivMibsDir, "SIMPLE-MIB.bin"])), + + %% check the extra src_dir was linked into the _build dir + true = filelib:is_dir(filename:join([AppDir, "_build", "default", "lib", Name, "mibs"])). |