|
| 1 | +-module( dia_tests ). |
| 2 | + |
| 3 | +-include_lib( "eunit/include/eunit.hrl" ). |
| 4 | + |
| 5 | + |
| 6 | +compile_test_() -> |
| 7 | + {setup, |
| 8 | + fun () -> setup() end, |
| 9 | + [fun () -> test_compile() end] |
| 10 | + }. |
| 11 | + |
| 12 | + |
| 13 | +%% Internal |
| 14 | + |
| 15 | +diameter_basename() -> "diameter_3gpp_base". |
| 16 | + |
| 17 | + |
| 18 | +setup() -> |
| 19 | + {ok, Repo} = file:get_cwd(), |
| 20 | + Branch = setup_git_branch(), |
| 21 | + Test_target = test_target( Repo ), |
| 22 | + setup_delete( Test_target ), |
| 23 | + setup_create( Test_target, Repo, Branch ). |
| 24 | + |
| 25 | +setup_create( Test_target, Repo, Branch ) -> |
| 26 | + ok = setup_create_dia( Test_target ), |
| 27 | + ok = setup_create_src( Test_target ), |
| 28 | + ok = setup_create_rebar_config( Test_target, Repo, Branch ). |
| 29 | + |
| 30 | +setup_create_dia( Test_target ) -> |
| 31 | + Diameter_file = diameter_basename() ++ ".dia", |
| 32 | + File = filename:join( [Test_target, "dia", Diameter_file] ), |
| 33 | + ok = filelib:ensure_dir( File ), |
| 34 | + {ok, _} = file:copy( filename:join( "test", Diameter_file ), File ), |
| 35 | + ok. |
| 36 | + |
| 37 | +setup_create_src( Test_target ) -> |
| 38 | + App = "compile", |
| 39 | + File = filename:join( [Test_target, "src", App ++ ".app.src"] ), |
| 40 | + ok = filelib:ensure_dir( File ), |
| 41 | + file:write_file( File, setup_create_src_content(App) ). |
| 42 | + |
| 43 | +setup_create_src_content(App) -> |
| 44 | + " |
| 45 | +{application, " ++ App ++ ", [ |
| 46 | + {description, \"" ++ App ++ "\"}, |
| 47 | + {vsn, \"1.0\"}, |
| 48 | + {applications, [kernel,stdlib]} |
| 49 | +]}. |
| 50 | +". |
| 51 | + |
| 52 | +setup_create_rebar_config( Test_target, Repo, Branch ) -> |
| 53 | + File = filename:join( Test_target, "rebar.config" ), |
| 54 | + ok = filelib:ensure_dir( File ), |
| 55 | + file:write_file( File, setup_rebar_config_content(Repo, Branch) ). |
| 56 | + |
| 57 | +setup_delete( Directory ) -> |
| 58 | + Paths = filelib:wildcard( filename:join(Directory, "*") ), |
| 59 | + {Directories, Files} = lists:partition( fun filelib:is_dir/1, Paths ), |
| 60 | + [file:delete(X) || X <- Files], |
| 61 | + [setup_delete(X) || X <- Directories], |
| 62 | + file:del_dir( Directory ). |
| 63 | + |
| 64 | +setup_git_branch() -> string:trim( os:cmd("git branch --show-current") ). |
| 65 | + |
| 66 | +setup_rebar_config_content( Repo, Branch ) -> |
| 67 | + " |
| 68 | +{plugins, [ |
| 69 | + {rebar3_diameter_compiler, {git, \"file://" ++ Repo ++ "\", {branch, \"" ++ Branch ++ "\"}}} |
| 70 | +]}. |
| 71 | +{provider_hooks, [ |
| 72 | + {pre, [ |
| 73 | + {clean, {diameter, clean}}, |
| 74 | + {compile, {diameter, compile}} |
| 75 | + ]} |
| 76 | +]}. |
| 77 | +". |
| 78 | + |
| 79 | + |
| 80 | +test_compile() -> |
| 81 | + {ok, Repo} = file:get_cwd(), |
| 82 | + Test_target = test_target( Repo ), |
| 83 | + ok = file:set_cwd( Test_target ), |
| 84 | +% Result = os:cmd( "DIAGNOSTIC=1 rebar3 eunit" ), |
| 85 | +% ?debugMsg( Result ), |
| 86 | + ?assertCmd( "rebar3 eunit" ), |
| 87 | + true = filelib:is_regular( filename:join("include", diameter_basename() ++ ".hrl") ), |
| 88 | + true = filelib:is_regular( filename:join("src", diameter_basename() ++ ".erl") ), |
| 89 | + file:set_cwd( Repo ). |
| 90 | + |
| 91 | + |
| 92 | +test_target( Repo ) -> |
| 93 | + filename:join( [Repo, "_build", "test", "lib", "rebar3_diameter_compiler", "test", "compile"] ). |
0 commit comments