Browse Source

Test erl_files/1 app_src_files/1 is_app_src/1 app_src_to_app/1 erl_to_beam/2 is_compiled/2

Sina Samavati 11 years ago
parent
commit
52dabd7522
2 changed files with 48 additions and 1 deletions
  1. 8 0
      src/mad_compile.erl
  2. 40 1
      test/mad_compile_SUITE.erl

+ 8 - 0
src/mad_compile.erl

@@ -3,6 +3,14 @@
 -export([deps/2]).
 -export([deps/2]).
 -export([app/1]).
 -export([app/1]).
 
 
+%% internal
+-export([erl_files/1]).
+-export([app_src_files/1]).
+-export([is_app_src/1]).
+-export([app_src_to_app/1]).
+-export([erl_to_beam/2]).
+-export([is_compiled/2]).
+
 -define(COMPILE_OPTS(Inc, Ebin), [report, {i, Inc}, {outdir, Ebin}]).
 -define(COMPILE_OPTS(Inc, Ebin), [report, {i, Inc}, {outdir, Ebin}]).
 
 
 
 

+ 40 - 1
test/mad_compile_SUITE.erl

@@ -1,13 +1,45 @@
 -module(mad_compile_SUITE).
 -module(mad_compile_SUITE).
 
 
 -export([all/0]).
 -export([all/0]).
+-export([erl_files/1]).
+-export([app_src_files/1]).
+-export([is_app_src/1]).
+-export([app_src_to_app/1]).
+-export([erl_to_beam/1]).
+-export([is_compiled/1]).
 -export([deps/1]).
 -export([deps/1]).
 
 
 -import(helper, [get_value/2]).
 -import(helper, [get_value/2]).
 
 
 
 
 all() ->
 all() ->
-    [deps].
+    [
+     erl_files, app_src_files, is_app_src, app_src_to_app, erl_to_beam, deps,
+     is_compiled
+    ].
+
+erl_files(Config) ->
+    DataDir = get_value(data_dir, Config),
+    SrcDir = filename:join([DataDir, "deps", "one", "src"]),
+    ErlFile = filename:join(SrcDir, "one.erl"),
+    [ErlFile] = mad_compile:erl_files(SrcDir).
+
+app_src_files(Config) ->
+    DataDir = get_value(data_dir, Config),
+    SrcDir = filename:join([DataDir, "deps", "one", "src"]),
+    AppSrcFile = filename:join(SrcDir, "one.app.src"),
+    [AppSrcFile] = mad_compile:app_src_files(SrcDir).
+
+is_app_src(_) ->
+    false = mad_compile:is_app_src("/path/to/file.erl"),
+    true = mad_compile:is_app_src("/path/to/file.app.src").
+
+app_src_to_app(_) ->
+    "file.app" = mad_compile:app_src_to_app("/path/to/file.app.src").
+
+erl_to_beam(_) ->
+    "/path/to/ebin/file.beam" = mad_compile:erl_to_beam("/path/to/ebin",
+                                                        "/path/to/file.erl").
 
 
 deps(Config) ->
 deps(Config) ->
     DataDir = get_value(data_dir, Config),
     DataDir = get_value(data_dir, Config),
@@ -19,3 +51,10 @@ deps(Config) ->
     ok = application:load(two),
     ok = application:load(two),
     {ok, [one]} = application:get_key(one, modules),
     {ok, [one]} = application:get_key(one, modules),
     {ok, [two]} = application:get_key(two, modules).
     {ok, [two]} = application:get_key(two, modules).
+
+is_compiled(Config) ->
+    DataDir = get_value(data_dir, Config),
+    SrcDir = filename:join([DataDir, "deps", "one", "src"]),
+    EbinDir = filename:join([SrcDir, "..", "ebin"]),
+    false = mad_compile:is_compiled(EbinDir, filename:join(SrcDir, "x.erl")),
+    true = mad_compile:is_compiled(EbinDir, filename:join(SrcDir, "one.erl")).