From 42a363dbdf2c212833159edaa3391efc4d33c73c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Fri, 5 Feb 2016 12:25:41 +0100
Subject: compile_SUITE: Replace confusing files/2 with get_files/3

The files/2 function is confusing. The second argument names
the output directory, not the name of the source module. It is
common trap to attempt to point a different source file using
files/2.

Introduce the new get_files/3 which explicitly names the module
name.
---
 lib/compiler/test/compile_SUITE.erl | 42 ++++++++++++++++++-------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

(limited to 'lib/compiler')

diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index 806cb58bab..212cbcb16b 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -86,7 +86,7 @@ file_1(Config) when is_list(Config) ->
 
     process_flag(trap_exit, true),
 
-    ?line {Simple, Target} = files(Config, "file_1"),
+    {Simple, Target} = get_files(Config, simple, "file_1"),
     ?line {ok, Cwd} = file:get_cwd(),
     ?line ok = file:set_cwd(filename:dirname(Target)),
 
@@ -179,7 +179,7 @@ big_file(Config) when is_list(Config) ->
 
 outdir(Config) when is_list(Config) ->
     ?line Dog = test_server:timetrap(test_server:seconds(60)),
-    ?line {Simple, Target} = files(Config, "outdir"),
+    {Simple, Target} = get_files(Config, simple, "outdir"),
     ?line {ok, simple} = compile:file(Simple, [{outdir, filename:dirname(Target)}]),
     ?line true = exists(Target),
     ?line passed = run(Target, test, []),
@@ -192,7 +192,7 @@ outdir(Config) when is_list(Config) ->
 
 binary(Config) when is_list(Config) ->
     ?line Dog = test_server:timetrap(test_server:seconds(60)),
-    ?line {Simple, Target} = files(Config, "binary"),
+    {Simple, Target} = get_files(Config, simple, "binary"),
     ?line {ok, simple, Binary} = compile:file(Simple, [binary]),
     ?line code:load_binary(simple, Target, Binary),
     ?line passed = simple:test(),
@@ -206,7 +206,7 @@ binary(Config) when is_list(Config) ->
 
 makedep(Config) when is_list(Config) ->
     ?line Dog = test_server:timetrap(test_server:seconds(60)),
-    ?line {Simple,Target} = files(Config, "makedep"),
+    {Simple,Target} = get_files(Config, simple, "makedep"),
     ?line DataDir = ?config(data_dir, Config),
     ?line SimpleRootname = filename:rootname(Simple),
     ?line IncludeDir = filename:join(filename:dirname(Simple), "include"),
@@ -282,7 +282,7 @@ makedep_modify_target(Mf, Target) ->
 
 cond_and_ifdef(Config) when is_list(Config) ->
     ?line Dog = test_server:timetrap(test_server:seconds(60)),
-    ?line {Simple, Target} = files(Config, "cond_and_ifdef"),
+    {Simple, Target} = get_files(Config, simple, "cond_and_ifdef"),
     ?line IncludeDir = filename:join(filename:dirname(Simple), "include"),
     ?line Options = [{outdir, filename:dirname(Target)},
 		     {d, need_foo}, {d, foo_value, 42},
@@ -434,7 +434,7 @@ other_output(Config) when is_list(Config) ->
 
 encrypted_abstr(Config) when is_list(Config) ->
     ?line Dog = test_server:timetrap(test_server:minutes(10)),
-    ?line {Simple,Target} = files(Config, "encrypted_abstr"),
+    {Simple,Target} = get_files(Config, simple, "encrypted_abstr"),
 
     Res = case has_crypto() of
 	      false ->
@@ -582,17 +582,17 @@ do_listing(Source, TargetDir, Type, Ext) ->
     Target = filename:join(TargetDir, SourceBase ++ Ext),
     true = exists(Target).
 
-files(Config, Name) ->
-    ?line code:delete(simple),
-    ?line code:purge(simple),
-    ?line DataDir = ?config(data_dir, Config),
-    ?line PrivDir = ?config(priv_dir, Config),
-    ?line Simple = filename:join(DataDir, "simple"),
-    ?line TargetDir = filename:join(PrivDir, Name),
-    ?line ok = file:make_dir(TargetDir),
-    ?line Target = filename:join(TargetDir, "simple"++code:objfile_extension()),
-    {Simple, Target}.
-
+get_files(Config, Module, OutputName) ->
+    code:delete(Module),
+    code:purge(Module),
+    DataDir = ?config(data_dir, Config),
+    PrivDir = ?config(priv_dir, Config),
+    Src = filename:join(DataDir, atom_to_list(Module)),
+    TargetDir = filename:join(PrivDir, OutputName),
+    ok = file:make_dir(TargetDir),
+    File = atom_to_list(Module) ++ code:objfile_extension(),
+    Target = filename:join(TargetDir, File),
+    {Src, Target}.
 
 run(Target, Func, Args) ->
     ?line Module = list_to_atom(filename:rootname(filename:basename(Target))),
@@ -715,7 +715,7 @@ init(ReplyTo, Fun, _Filler) ->
     ReplyTo ! {result, Fun()}.
 
 env(Config) when is_list(Config) ->
-    ?line {Simple,Target} = files(Config, "file_1"),
+    {Simple,Target} = get_files(Config, simple, env),
     ?line {ok,Cwd} = file:get_cwd(),
     ?line ok = file:set_cwd(filename:dirname(Target)),
 
@@ -724,9 +724,9 @@ env(Config) when is_list(Config) ->
 	env_1(Simple, Target)
     after
 	true = os:putenv("ERL_COMPILER_OPTIONS", "ignore_me"),
-      file:set_cwd(Cwd),
-      file:delete(Target),
-      file:del_dir(filename:dirname(Target))
+	file:set_cwd(Cwd),
+	file:delete(Target),
+	file:del_dir(filename:dirname(Target))
     end,
     ok.
 
-- 
cgit v1.2.3


From bf11b8fc3e9ac0f3cd48d8a3a834bd7d709ecc9e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Fri, 5 Feb 2016 12:38:19 +0100
Subject: compile_SUITE: Use get_files/3 in more places

---
 lib/compiler/test/compile_SUITE.erl | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)

(limited to 'lib/compiler')

diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index 212cbcb16b..b68d039681 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -161,11 +161,8 @@ module_mismatch(Config) when is_list(Config) ->
 
 big_file(Config) when is_list(Config) ->
     ?line Dog = test_server:timetrap(test_server:minutes(5)),
-    ?line DataDir = ?config(data_dir, Config),
-    ?line PrivDir = ?config(priv_dir, Config),
-    ?line Big = filename:join(DataDir, "big.erl"),
-    ?line Target = filename:join(PrivDir, "big.beam"),
-    ?line ok = file:set_cwd(PrivDir),
+    {Big,Target} = get_files(Config, big, "big_file"),
+    ok = file:set_cwd(filename:dirname(Target)),
     ?line compile_and_verify(Big, Target, []),
     ?line compile_and_verify(Big, Target, [debug_info]),
     ?line compile_and_verify(Big, Target, [no_postopt]),
@@ -362,21 +359,18 @@ do_file_listings(DataDir, PrivDir, [File|Files]) ->
 
 listings_big(Config) when is_list(Config) ->
     ?line Dog = test_server:timetrap(test_server:minutes(10)),
-    ?line DataDir = ?config(data_dir, Config),
-    ?line PrivDir = ?config(priv_dir, Config),
-    ?line Big = filename:join(DataDir, big),
-    ?line TargetDir = filename:join(PrivDir, listings_big),
-    ?line ok = file:make_dir(TargetDir),
+    {Big,Target} = get_files(Config, big, listings_big),
+    TargetDir = filename:dirname(Target),
     ?line do_listing(Big, TargetDir, 'S'),
     ?line do_listing(Big, TargetDir, 'E'),
     ?line do_listing(Big, TargetDir, 'P'),
     ?line do_listing(Big, TargetDir, dkern, ".kernel"),
 
-    ?line Target = filename:join(TargetDir, big),
-    {ok,big} = compile:file(Target, [from_asm,{outdir,TargetDir}]),
+    TargetNoext = filename:rootname(Target, code:objfile_extension()),
+    {ok,big} = compile:file(TargetNoext, [from_asm,{outdir,TargetDir}]),
 
     %% Cleanup.
-    ?line ok = file:delete(Target ++ ".beam"),
+    ok = file:delete(Target),
     ?line lists:foreach(fun(F) -> ok = file:delete(F) end,
 			filelib:wildcard(filename:join(TargetDir, "*"))),
     ?line ok = file:del_dir(TargetDir),
@@ -385,11 +379,7 @@ listings_big(Config) when is_list(Config) ->
 
 other_output(Config) when is_list(Config) ->
     ?line Dog = test_server:timetrap(test_server:minutes(8)),
-    ?line DataDir = ?config(data_dir, Config),
-    ?line PrivDir = ?config(priv_dir, Config),
-    ?line Simple = filename:join(DataDir, simple),
-    ?line TargetDir = filename:join(PrivDir, other_output),
-    ?line ok = file:make_dir(TargetDir),
+    {Simple,_Target} = get_files(Config, simple, "other_output"),
 
     io:put_chars("to_pp"),
     ?line {ok,[],PP} = compile:file(Simple, [to_pp,binary,time]),
-- 
cgit v1.2.3


From 6fbe8cd45ee7f9f63dd0cad38dd6529598dcb21e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Fri, 5 Feb 2016 13:10:38 +0100
Subject: Move record compilation errors to erl_lint_SUITE

The two bad record usage test cases in compile_SUITE do not
belong there, as the errors are detected in erl_lint. Move the
test to the erl_lint_SUITE.
---
 lib/compiler/test/compile_SUITE.erl                | 29 +++------------------
 .../test/compile_SUITE_data/bad_record_use.erl     | 29 ---------------------
 .../test/compile_SUITE_data/bad_record_use2.erl    | 30 ----------------------
 3 files changed, 3 insertions(+), 85 deletions(-)
 delete mode 100644 lib/compiler/test/compile_SUITE_data/bad_record_use.erl
 delete mode 100644 lib/compiler/test/compile_SUITE_data/bad_record_use2.erl

(limited to 'lib/compiler')

diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl
index b68d039681..ab9910f555 100644
--- a/lib/compiler/test/compile_SUITE.erl
+++ b/lib/compiler/test/compile_SUITE.erl
@@ -29,7 +29,7 @@
 	 file_1/1, forms_2/1, module_mismatch/1, big_file/1, outdir/1,
 	 binary/1, makedep/1, cond_and_ifdef/1, listings/1, listings_big/1,
 	 other_output/1, encrypted_abstr/1,
-	 bad_record_use1/1, bad_record_use2/1, strict_record/1,
+	 strict_record/1,
 	 missing_testheap/1, cover/1, env/1, core/1, asm/1,
 	 sys_pre_attributes/1, dialyzer/1,
 	 warnings/1
@@ -48,13 +48,12 @@ all() ->
     [app_test, appup_test, file_1, forms_2, module_mismatch, big_file, outdir,
      binary, makedep, cond_and_ifdef, listings, listings_big,
      other_output, encrypted_abstr,
-     {group, bad_record_use}, strict_record,
+     strict_record,
      missing_testheap, cover, env, core, asm,
      sys_pre_attributes, dialyzer, warnings].
 
 groups() -> 
-    [{bad_record_use, [],
-      [bad_record_use1, bad_record_use2]}].
+    [].
 
 init_per_suite(Config) ->
     Config.
@@ -599,28 +598,6 @@ exists(Name) ->
     end.
 
 
-%% Tests that the compiler does not accept
-%% bad use of records.
-bad_record_use1(Config) when is_list(Config) ->
-    ?line {ok, Cwd} = file:get_cwd(),
-    ?line file:set_cwd(?config(data_dir, Config)),
-    ?line true=exists("bad_record_use.erl"),
-    ?line Ret=c:c(bad_record_use),
-    ?line file:set_cwd(Cwd),
-    ?line error=Ret,
-    ok.
-
-%% Tests that the compiler does not accept
-%% bad use of records.
-bad_record_use2(Config) when is_list(Config) ->
-    ?line {ok, Cwd} = file:get_cwd(),
-    ?line file:set_cwd(?config(data_dir, Config)),
-    ?line true=exists("bad_record_use2.erl"),
-    ?line Ret=c:c(bad_record_use),
-    ?line file:set_cwd(Cwd),
-    ?line error=Ret,
-    ok.
-
 strict_record(Config) when is_list(Config) ->
     ?line Priv = ?config(priv_dir, Config),
     ?line file:set_cwd(?config(data_dir, Config)),
diff --git a/lib/compiler/test/compile_SUITE_data/bad_record_use.erl b/lib/compiler/test/compile_SUITE_data/bad_record_use.erl
deleted file mode 100644
index 0fb6fc3045..0000000000
--- a/lib/compiler/test/compile_SUITE_data/bad_record_use.erl
+++ /dev/null
@@ -1,29 +0,0 @@
-%%
-%% %CopyrightBegin%
-%% 
-%% Copyright Ericsson AB 1998-2009. All Rights Reserved.
-%% 
-%% Licensed under the Apache License, Version 2.0 (the "License");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%%     http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an "AS IS" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%% 
-%% %CopyrightEnd%
-%%
--module(bad_record_use).
--export([test/0]).
-
--record(bad_use, {a=undefined,
-		  b=undefined,
-		  c=undefined}).
-
-test() ->
-    NewRecord=#bad_use{a=1, b=2, a=2}.
-
diff --git a/lib/compiler/test/compile_SUITE_data/bad_record_use2.erl b/lib/compiler/test/compile_SUITE_data/bad_record_use2.erl
deleted file mode 100644
index 7c898af00f..0000000000
--- a/lib/compiler/test/compile_SUITE_data/bad_record_use2.erl
+++ /dev/null
@@ -1,30 +0,0 @@
-%%
-%% %CopyrightBegin%
-%% 
-%% Copyright Ericsson AB 1998-2009. All Rights Reserved.
-%% 
-%% Licensed under the Apache License, Version 2.0 (the "License");
-%% you may not use this file except in compliance with the License.
-%% You may obtain a copy of the License at
-%%
-%%     http://www.apache.org/licenses/LICENSE-2.0
-%%
-%% Unless required by applicable law or agreed to in writing, software
-%% distributed under the License is distributed on an "AS IS" BASIS,
-%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-%% See the License for the specific language governing permissions and
-%% limitations under the License.
-%% 
-%% %CopyrightEnd%
-%%
--module(bad_record_use2).
--export([test/0]).
-
--record(bad_use, {a=undefined,
-		  b=undefined,
-		  c=undefined}).
-
-test() ->
-    R=#bad_use{a=1, b=2},
-    R2=R#bad_use{a=1, b=2, a=2},
-    ok.
-- 
cgit v1.2.3