Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

escript: add test for ./archive_script workarounds

  • Loading branch information...
commit 2fd3ffe6cd5be778c1a9042c087d4c0d6afdf96a 1 parent 6c9f90c
@tuncer authored
View
47 lib/stdlib/test/escript_SUITE.erl
@@ -462,6 +462,53 @@ archive_script(Config) when is_list(Config) ->
"priv:{ok,<<\"Some private data...\\n\">>}\n"
"ExitCode:0">>]),
+ %%%%%%%
+ %% Create and run archive script with a special zip archive which
+ %% used to provoke the following issues when the script was run as
+ %% "./archive_script":
+ %% 1. erl_prim_loader:read_file_info/1 returning 'error'
+ %% 2. erl_prim_loader:list_dir/1 returning {ok, ["dir1", [], "file1"]}
+ %% leading to an infinite loop in reltool_target:spec_dir/1
+
+ %% Generate dummy file in a subdir for zip archive
+ {ok, OldDir} = file:get_cwd(),
+ ok = file:set_cwd(TopDir),
+ SpecialDummySubDir = filename:join("dir1", "subdir1"),
+ SpecialDummyFile = filename:join([TopDir, SpecialDummySubDir, "file1"]),
+ ok = filelib:ensure_dir(SpecialDummyFile),
+ ok = file:write_file(SpecialDummyFile, ["foo\nbar\nbaz"]),
+
+ %% Create special zip archive
+ LoadFiles =
+ fun(Wildcard, Dir) ->
+ [begin
+ {ok, Bin} = file:read_file(filename:join(Dir, Filename)),
+ {Filename, Bin}
+ end || Filename <- filelib:wildcard(Wildcard, Dir)]
+ end,
+ SpecialMain = "archive_script_main3",
+ SpecialFiles = LoadFiles(SpecialMain ++ ".beam", ".")
+ ++ LoadFiles(filename:join([SpecialDummySubDir, "*"]), "."),
+ ok = file:set_cwd(OldDir),
+ {ok, {"mem", SpecialBin}} = zip:create("mem", SpecialFiles, [memory]),
+
+ SpecialBase = "archive_script_special",
+ SpecialScript = filename:join([PrivDir, SpecialBase]),
+ SpecialFlags = "%%! -escript main " ++ SpecialMain,
+ ok = file:write_file(SpecialScript,
+ [Shebang, "\n",
+ SpecialFlags, "\n",
+ SpecialBin]),
+ ok = file:write_file_info(SpecialScript, OrigFI),
+
+ %% Change to script's directory and run "./archive_script_special"
+ ok = file:set_cwd(PrivDir),
+ do_run(PrivDir, "./" ++ SpecialBase,
+ [<<"main3:[]\n",
+ "false\n"
+ "ExitCode:0">>]),
+ ok = file:set_cwd(OldDir),
+
ok.
compile_app(TopDir, AppName) ->
View
30 lib/stdlib/test/escript_SUITE_data/archive_script/archive_script_main3.erl
@@ -0,0 +1,30 @@
+%%
+%% %CopyrightBegin%
+%%
+%% Copyright Ericsson AB 2008-2012. All Rights Reserved.
+%%
+%% The contents of this file are subject to the Erlang Public License,
+%% Version 1.1, (the "License"); you may not use this file except in
+%% compliance with the License. You should have received a copy of the
+%% Erlang Public License along with this software. If not, it can be
+%% retrieved online at http://www.erlang.org/.
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and limitations
+%% under the License.
+%%
+%% %CopyrightEnd%
+%%
+-module(archive_script_main3).
+-behaviour(escript).
+
+-export([main/1]).
+
+main(MainArgs) ->
+ io:format("main3:~p\n", [MainArgs]),
+ ArchiveFile = escript:script_name(),
+ {ok, Listing} = erl_prim_loader:list_dir(ArchiveFile),
+ io:format("~p~n", [lists:member([], Listing)]),
+
+ ok.
Please sign in to comment.
Something went wrong with that request. Please try again.