summaryrefslogtreecommitdiff
path: root/inttest
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-01-26 18:54:19 -0500
committerFred Hebert <mononcqc@ferd.ca>2015-01-26 18:54:19 -0500
commitb488179030944d24a3a559cf45aac461e6155470 (patch)
tree7044dc1d83f0e54b07b1a4a97e08921267f4c62a /inttest
parent930d2c7f34eaee63889a0131073b7a749c33cdd9 (diff)
parent9b1f807f0c5a41d147372f1801d969cdb03ff570 (diff)
downloadrebar-b488179030944d24a3a559cf45aac461e6155470.tar.gz
Merge pull request #424 from tomas-abrahamsson/gpb-recompilation-detection-2
Gpb recompilation detection (using base compiler)
Diffstat (limited to 'inttest')
-rw-r--r--inttest/proto_gpb/proto_gpb_rt.erl56
1 files changed, 56 insertions, 0 deletions
diff --git a/inttest/proto_gpb/proto_gpb_rt.erl b/inttest/proto_gpb/proto_gpb_rt.erl
index 2cc5052..263e9db 100644
--- a/inttest/proto_gpb/proto_gpb_rt.erl
+++ b/inttest/proto_gpb/proto_gpb_rt.erl
@@ -29,6 +29,8 @@
run/1]).
-include_lib("eunit/include/eunit.hrl").
+-include_lib("kernel/include/file.hrl").
+-include_lib("deps/retest/include/retest.hrl").
-define(MODULES,
[foo,
@@ -42,6 +44,13 @@
test4_gpb,
test5_gpb]).
+-define(SOURCE_PROTO_FILES,
+ ["test.proto",
+ "a/test2.proto",
+ "a/b/test3.proto",
+ "c/test4.proto",
+ "c/d/test5.proto"]).
+
files() ->
[
{copy, "../../rebar", "rebar"},
@@ -60,6 +69,23 @@ run(_Dir) ->
%% generating the test_gpb.hrl file, and also that it generated
%% the .hrl file was generated before foo was compiled.
ok = check_beams_generated(),
+
+ ?DEBUG("Verifying recompilation~n", []),
+ TestErl = hd(generated_erl_files()),
+ TestProto = hd(source_proto_files()),
+ make_proto_newer_than_erl(TestProto, TestErl),
+ TestMTime1 = read_mtime(TestErl),
+ ?assertMatch({ok, _}, retest_sh:run("./rebar compile", [])),
+ TestMTime2 = read_mtime(TestErl),
+ ?assert(TestMTime2 > TestMTime1),
+
+ ?DEBUG("Verifying recompilation with no changes~n", []),
+ TestMTime3 = read_mtime(TestErl),
+ ?assertMatch({ok, _}, retest_sh:run("./rebar compile", [])),
+ TestMTime4 = read_mtime(TestErl),
+ ?assert(TestMTime3 =:= TestMTime4),
+
+ ?DEBUG("Verify cleanup~n", []),
?assertMatch({ok, _}, retest_sh:run("./rebar clean", [])),
ok = check_files_deleted(),
ok.
@@ -81,6 +107,12 @@ generated_erl_files() ->
generated_hrl_files() ->
add_dir("include", add_ext(?GENERATED_MODULES, ".hrl")).
+generated_beam_files() ->
+ add_dir("ebin", add_ext(?GENERATED_MODULES, ".beam")).
+
+source_proto_files() ->
+ add_dir("src", ?SOURCE_PROTO_FILES).
+
file_does_not_exist(F) ->
not filelib:is_regular(F).
@@ -90,6 +122,30 @@ add_ext(Modules, Ext) ->
add_dir(Dir, Files) ->
[filename:join(Dir, File) || File <- Files].
+read_mtime(File) ->
+ {ok, #file_info{mtime=MTime}} = file:read_file_info(File),
+ MTime.
+
+
+make_proto_newer_than_erl(Proto, Erl) ->
+ %% Do this by back-dating the erl file instead of touching the
+ %% proto file. Do this instead of sleeping for a second to get a
+ %% reliable test. Sleeping would have been needed sin ce the
+ %% #file_info{} (used by eg. filelib:last_modified) does not have
+ %% sub-second resolution (even though most file systems have).
+ {ok, #file_info{mtime=ProtoMTime}} = file:read_file_info(Proto),
+ {ok, ErlInfo} = file:read_file_info(Erl),
+ OlderMTime = update_seconds_to_datetime(ProtoMTime, -2),
+ OlderErlInfo = ErlInfo#file_info{mtime = OlderMTime},
+ ok = file:write_file_info(Erl, OlderErlInfo).
+
+update_seconds_to_datetime(DT, ToAdd) ->
+ calendar:gregorian_seconds_to_datetime(
+ calendar:datetime_to_gregorian_seconds(DT) + ToAdd).
+
+touch_file(File) ->
+ ?assertMatch({ok, _}, retest_sh:run("touch " ++ File, [])).
+
check(Check, Files) ->
lists:foreach(
fun(F) ->