From 4d6c5fc2f0591944efa2b361eb60da03d4d2d56b Mon Sep 17 00:00:00 2001 From: Peter Lemenkov Date: Tue, 15 Mar 2016 22:44:49 +0300 Subject: [PATCH] Fix tests Signed-off-by: Peter Lemenkov --- erlang-rebar.spec | 35 ++-- ...Don-t-load-templates-from-the-bundle.patch | 65 ------- ...-templates-from-the-filesystem-first.patch | 25 +++ rebar-0002-Remove-bundled-mustache.patch | 9 +- rebar-0014-Fix-windows-eunit-tests.patch | 165 ++++++++++++++++++ 5 files changed, 218 insertions(+), 81 deletions(-) delete mode 100644 rebar-0001-Don-t-load-templates-from-the-bundle.patch create mode 100644 rebar-0001-Load-templates-from-the-filesystem-first.patch create mode 100644 rebar-0014-Fix-windows-eunit-tests.patch diff --git a/erlang-rebar.spec b/erlang-rebar.spec index 8ead6d0..d42ed32 100644 --- a/erlang-rebar.spec +++ b/erlang-rebar.spec @@ -12,7 +12,7 @@ Name: erlang-%{realname} Version: 2.6.1 -Release: 9%{?dist} +Release: 10%{?dist} Summary: Erlang Build Tools Group: Development/Tools License: MIT @@ -20,7 +20,7 @@ URL: https://github.com/%{upstream}/%{realname} Source0: https://github.com/%{upstream}/%{realname}/archive/%{version}/%{realname}-%{version}.tar.gz Source1: rebar.escript # Fedora/EPEL-specific -Patch1: rebar-0001-Don-t-load-templates-from-the-bundle.patch +Patch1: rebar-0001-Load-templates-from-the-filesystem-first.patch # Fedora/EPEL-specific Patch2: rebar-0002-Remove-bundled-mustache.patch # The bundled getopt is necessary to do the initial bootstrap since @@ -45,6 +45,8 @@ Patch12: rebar-0012-Try-shell-variable-VSN-first.patch # Fedora/EPEL-specific - allow overriding missind deps error (versions # mismatch) Patch13: rebar-0013-Allow-ignoring-missing-deps.patch +# Backported from upstream +Patch14: rebar-0014-Fix-windows-eunit-tests.patch %if 0%{?need_bootstrap} < 1 BuildRequires: erlang-rebar @@ -68,13 +70,13 @@ BuildRequires: erlang-neotoma BuildRequires: erlang-parsetools BuildRequires: erlang-protobuffs BuildRequires: erlang-reltool +BuildRequires: erlang-rpm-macros BuildRequires: erlang-sasl BuildRequires: erlang-snmp BuildRequires: erlang-stdlib BuildRequires: erlang-syntax_tools BuildRequires: erlang-tools %endif -BuildRequires: erlang-rpm-macros # FIXME wip #Requires: erlang-abnfc%{?_isa} @@ -90,7 +92,7 @@ Requires: erlang-erl_interface%{?_isa} # See https://bugzilla.redhat.com/960079 Requires: erlang-parsetools%{?_isa} -Requires: erlang-rpm-macros +Requires: erlang-rpm-macros >= 0.2.2 Provides: %{realname} = %{version}-%{release} @@ -100,7 +102,7 @@ Erlang Build Tools. %prep %setup -q -n %{realname}-%{version} -%patch1 -p1 -b .dont_load_templates +%patch1 -p1 -b .load_templates_from_fs %patch2 -p1 -b .remove_bundled_mustache %if 0%{?need_bootstrap} < 1 %patch3 -p1 -b .remove_bundled_getopt @@ -115,11 +117,15 @@ Erlang Build Tools. %patch11 -p1 -b .typo_fix %patch12 -p1 -b .vsn_override %patch13 -p1 -b .skip_deps_checking +%patch14 -p1 -b .fix_eunit_tests %build %if 0%{?need_bootstrap} < 1 -%{rebar_compile} +%{erlang_compile} +# For using during tests +install -D -p -m 0755 %{SOURCE1} ./rebar +sed -i -e "s,-noshell -noinput,-noshell -noinput -pa %{buildroot}%{_erllibdir}/%{realname}-%{version}/ebin,g" ./rebar %else ./bootstrap ./rebar compile -v @@ -127,26 +133,31 @@ Erlang Build Tools. %install +%{erlang_install} +# Install rebar script itself install -D -p -m 0755 %{SOURCE1} %{buildroot}%{_bindir}/rebar -mkdir -p %{buildroot}%{_erllibdir}/%{realname}-%{version}/{ebin,include} -install -p -m 0644 ebin/%{realname}.app ebin/*.beam %{buildroot}%{_erllibdir}/%{realname}-%{version}/ebin -install -p -m 0644 include/*.hrl %{buildroot}%{_erllibdir}/%{realname}-%{version}/include +# Copy the contents of priv folder cp -a priv %{buildroot}%{_erllibdir}/%{realname}-%{version}/ %check -# FIXME -#rebar eunit -v +%if 0%{?need_bootstrap} < 1 +%{rebar_eunit} +%endif %files %doc README.md THANKS rebar.config.sample %license LICENSE %{_bindir}/rebar -%{_erllibdir}/%{realname}-%{version}/ +%{erlang_appdir}/ %changelog +* Tue Mar 15 2016 Peter Lemenkov - 2.6.1-10 +- Fixed tests +- Fixed incompatibility with a newest erlang-mustache + * Mon Mar 7 2016 Peter Lemenkov - 2.6.1-9 - Allow skipping check for apps (not recommended for the end users - we'll use it only during rpm building so we won't introduce this functionality diff --git a/rebar-0001-Don-t-load-templates-from-the-bundle.patch b/rebar-0001-Don-t-load-templates-from-the-bundle.patch deleted file mode 100644 index 3105665..0000000 --- a/rebar-0001-Don-t-load-templates-from-the-bundle.patch +++ /dev/null @@ -1,65 +0,0 @@ -From: Peter Lemenkov -Date: Mon, 4 Mar 2013 19:03:03 +0400 -Subject: [PATCH] Don't load templates from the bundle - -Signed-off-by: Peter Lemenkov - -diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl -index 085ac1c..efee394 100644 ---- a/src/rebar_templater.erl -+++ b/src/rebar_templater.erl -@@ -205,27 +205,11 @@ create1(Config, TemplateId) -> - execute_template(Files, FinalTemplate, Type, Template, Context, Force, []). - - find_templates(Config) -> -- %% Load a list of all the files in the escript -- cache them since -- %% we'll potentially need to walk it several times over the course of -- %% a run. -- Files = cache_escript_files(Config), -- - %% Build a list of available templates - AvailTemplates = find_disk_templates(Config) -- ++ find_escript_templates(Files), -- -- {AvailTemplates, Files}. -+ ++ find_escript_templates(), - --%% --%% Scan the current escript for available files --%% --cache_escript_files(Config) -> -- {ok, Files} = rebar_utils:escript_foldl( -- fun(Name, _, GetBin, Acc) -> -- [{Name, GetBin()} | Acc] -- end, -- [], rebar_config:get_xconf(Config, escript)), -- Files. -+ {AvailTemplates, []}. - - template_id(Config) -> - case rebar_config:get_global(Config, template, undefined) of -@@ -235,10 +219,8 @@ template_id(Config) -> - TemplateId - end. - --find_escript_templates(Files) -> -- [{escript, Name} -- || {Name, _Bin} <- Files, -- re:run(Name, ?TEMPLATE_RE, [{capture, none}]) == match]. -+find_escript_templates() -> -+ [{file, Name} || Name <- rebar_utils:find_files(code:priv_dir(rebar) ++ "/templates", ?TEMPLATE_RE)]. - - find_disk_templates(Config) -> - OtherTemplates = find_other_templates(Config), -@@ -269,10 +251,7 @@ select_template([{Type, Avail} | Rest], Template) -> - %% - %% Read the contents of a file from the appropriate source - %% --load_file(Files, escript, Name) -> -- {Name, Bin} = lists:keyfind(Name, 1, Files), -- Bin; --load_file(_Files, file, Name) -> -+load_file(_Files, _, Name) -> - {ok, Bin} = file:read_file(Name), - Bin. - diff --git a/rebar-0001-Load-templates-from-the-filesystem-first.patch b/rebar-0001-Load-templates-from-the-filesystem-first.patch new file mode 100644 index 0000000..3b9dd1c --- /dev/null +++ b/rebar-0001-Load-templates-from-the-filesystem-first.patch @@ -0,0 +1,25 @@ +From: Peter Lemenkov +Date: Mon, 4 Mar 2013 19:03:03 +0400 +Subject: [PATCH] Load templates from the filesystem first. + +Signed-off-by: Peter Lemenkov + +diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl +index 085ac1c..7e8554e 100644 +--- a/src/rebar_templater.erl ++++ b/src/rebar_templater.erl +@@ -241,12 +241,13 @@ find_escript_templates(Files) -> + re:run(Name, ?TEMPLATE_RE, [{capture, none}]) == match]. + + find_disk_templates(Config) -> ++ BaseTemplates = rebar_utils:find_files(code:priv_dir(rebar) ++ "/templates", ?TEMPLATE_RE), + OtherTemplates = find_other_templates(Config), + HomeTemplates = filename:join([os:getenv("HOME"), ".rebar", "templates"]), + HomeFiles = rebar_utils:find_files_by_ext(HomeTemplates, ".template"), + Recursive = rebar_config:is_recursive(Config), + LocalFiles = rebar_utils:find_files_by_ext(".", ".template", Recursive), +- [{file, F} || F <- OtherTemplates ++ HomeFiles ++ LocalFiles]. ++ [{file, F} || F <- BaseTemplates ++ OtherTemplates ++ HomeFiles ++ LocalFiles]. + + find_other_templates(Config) -> + case rebar_config:get_global(Config, template_dir, undefined) of diff --git a/rebar-0002-Remove-bundled-mustache.patch b/rebar-0002-Remove-bundled-mustache.patch index 9437642..488d5da 100644 --- a/rebar-0002-Remove-bundled-mustache.patch +++ b/rebar-0002-Remove-bundled-mustache.patch @@ -252,15 +252,16 @@ index 9016c0f..0000000 - Out = render(list_to_atom(T)), - io:format(Out ++ "~n", []). diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl -index efee394..77c5bd8 100644 +index 7e8554e..2d20e86 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl -@@ -103,7 +103,7 @@ render(Bin, Context) -> +@@ -102,8 +102,7 @@ render(Bin, Context) -> + %% Be sure to escape any double-quotes before rendering... ReOpts = [global, {return, list}], Str0 = re:replace(Bin, "\\\\", "\\\\\\", ReOpts), - Str1 = re:replace(Str0, "\"", "\\\\\"", ReOpts), +- Str1 = re:replace(Str0, "\"", "\\\\\"", ReOpts), - rebar_mustache:render(Str1, Context). -+ mustache:render(Str1, Context). ++ mustache:render(Str0, Context). %% =================================================================== %% Internal functions diff --git a/rebar-0014-Fix-windows-eunit-tests.patch b/rebar-0014-Fix-windows-eunit-tests.patch new file mode 100644 index 0000000..2d7edef --- /dev/null +++ b/rebar-0014-Fix-windows-eunit-tests.patch @@ -0,0 +1,165 @@ +From: =?UTF-8?q?Luis=20Rasc=C3=A3o?= +Date: Mon, 12 Oct 2015 13:48:09 +0100 +Subject: [PATCH] Fix windows eunit tests + +File tests: windows file operations should abort on error +the same as unix operations invoked through sh. Also +windows does not support the '?' character in filenames. + +Eunit tests: the 'All' prefix is missing on the 'x tests passed' +message. Eunit only prints the 'All' prefix if there are more +than 2 passed tests, dropping the prefix on the match works +for all cases. + +diff --git a/src/rebar_file_utils.erl b/src/rebar_file_utils.erl +index 0fc1403..a4d3be7 100644 +--- a/src/rebar_file_utils.erl ++++ b/src/rebar_file_utils.erl +@@ -88,7 +88,7 @@ mv(Source, Dest) -> + ?FMT("move /y \"~s\" \"~s\" 1> nul", + [filename:nativename(Source), + filename:nativename(Dest)]), +- [{use_stdout, false}, return_on_error]), ++ [{use_stdout, false}, abort_on_error]), + case R of + [] -> + ok; +@@ -131,14 +131,14 @@ delete_each_dir_win32([]) -> ok; + delete_each_dir_win32([Dir | Rest]) -> + {ok, []} = rebar_utils:sh(?FMT("rd /q /s \"~s\"", + [filename:nativename(Dir)]), +- [{use_stdout, false}, return_on_error]), ++ [{use_stdout, false}, abort_on_error]), + delete_each_dir_win32(Rest). + + xcopy_win32(Source,Dest)-> + {ok, R} = rebar_utils:sh( + ?FMT("xcopy \"~s\" \"~s\" /q /y /e 2> nul", + [filename:nativename(Source), filename:nativename(Dest)]), +- [{use_stdout, false}, return_on_error]), ++ [{use_stdout, false}, abort_on_error]), + case length(R) > 0 of + %% when xcopy fails, stdout is empty and and error message is printed + %% to stderr (which is redirected to nul) +@@ -162,8 +162,10 @@ cp_r_win32({false, Source} = S,{true, DestDir}) -> + cp_r_win32(S, {false, filename:join(DestDir, filename:basename(Source))}); + cp_r_win32({false, Source},{false, Dest}) -> + %% from file to file +- {ok,_} = file:copy(Source, Dest), +- ok; ++ case file:copy(Source, Dest) of ++ {ok,_} -> ok; ++ _ -> throw(rebar_abort) ++ end; + cp_r_win32({true, SourceDir}, {false, DestDir}) -> + case filelib:is_regular(DestDir) of + true -> +diff --git a/test/rebar_compiler_tests.erl b/test/rebar_compiler_tests.erl +index 3ed600b..104a7d8 100644 +--- a/test/rebar_compiler_tests.erl ++++ b/test/rebar_compiler_tests.erl +@@ -84,11 +84,11 @@ not_keep_going_test_() -> + setup, + fun() -> + setup_basic_project(), +- setup_rebar_config(), +- rebar("compile") ++ setup_rebar_config() + end, + fun teardown/1, +- fun(RebarOut)-> ++ fun()-> ++ RebarOut = rebar("compile"), + [ + {"Exit after error", + ?_assert(string:str(RebarOut, "ERROR: compile failed") =/= 0)} +diff --git a/test/rebar_eunit_tests.erl b/test/rebar_eunit_tests.erl +index cb331a4..d481dae 100644 +--- a/test/rebar_eunit_tests.erl ++++ b/test/rebar_eunit_tests.erl +@@ -56,7 +56,7 @@ eunit_test_() -> + ?_assert(string:str(RebarOut, "myapp_mymod:") =/= 0)}, + + {"Tests are only run once", +- ?_assert(string:str(RebarOut, "All 2 tests passed") =/= 0)}] ++ ?_assert(string:str(RebarOut, "2 tests passed") =/= 0)}] + end}. + + eunit_with_suites_and_tests_test_() -> +@@ -80,7 +80,7 @@ eunit_with_suites_and_tests_test_() -> + ?_assert(string:str(RebarOut, "myapp_mymod:") =:= 0)}, + + {"Selected suite tests are only run once", +- ?_assert(string:str(RebarOut, "All 4 tests passed") =/= 0)}] ++ ?_assert(string:str(RebarOut, "4 tests passed") =/= 0)}] + end}, + {"Ensure EUnit runs selected _tests suites", + setup, fun() -> +@@ -102,7 +102,7 @@ eunit_with_suites_and_tests_test_() -> + ?_assert(string:str(RebarOut, "myapp_mymod:") =:= 0)}, + + {"Selected suite tests are only run once", +- ?_assert(string:str(RebarOut, "All 2 tests passed") =/= 0)}] ++ ?_assert(string:str(RebarOut, "2 tests passed") =/= 0)}] + end}, + {"Ensure EUnit runs a specific test defined in a selected suite", + setup, fun() -> +@@ -154,7 +154,7 @@ eunit_with_suites_and_tests_test_() -> + "myapp_mymod2_tests:myfunc2_test/0") =/= 0)]}, + + {"Selected suite tests are run once", +- ?_assert(string:str(RebarOut, "All 3 tests passed") =/= 0)}] ++ ?_assert(string:str(RebarOut, "3 tests passed") =/= 0)}] + end}, + {"Ensure EUnit runs specific test in a _tests suite", + setup, +@@ -190,7 +190,7 @@ eunit_with_suites_and_tests_test_() -> + =/= 0)]}, + + {"Selected suite tests is run once", +- ?_assert(string:str(RebarOut, "All 2 tests passed") =/= 0)}] ++ ?_assert(string:str(RebarOut, "2 tests passed") =/= 0)}] + end}, + {"Ensure EUnit runs a specific test by qualified function name", + setup, +@@ -325,7 +325,11 @@ environment_test_() -> + + assert_rebar_runs() -> + prepare_rebar_script(), +- ?assert(string:str(os:cmd(filename:nativename("./" ++ ?TMP_DIR ++ "rebar")), ++ {ok, Cwd} = file:get_cwd(), ++ ok = file:set_cwd(?TMP_DIR), ++ RebarOut = os:cmd(filename:nativename("./rebar")), ++ ok = file:set_cwd(Cwd), ++ ?assert(string:str(RebarOut, + "No command to run specified!") =/= 0). + + basic_setup_test_() -> +diff --git a/test/rebar_file_utils_tests.erl b/test/rebar_file_utils_tests.erl +index fc76d58..c9b4192 100644 +--- a/test/rebar_file_utils_tests.erl ++++ b/test/rebar_file_utils_tests.erl +@@ -36,7 +36,7 @@ + + -define(TMP_DIR, "tmp_file_utils"). + +--define(SRC, "source dir?"). ++-define(SRC, "source dir"). + -define(DST, "dest (dir)"). + -define(FILE1, "file 1"). + -define(FILE2, "file(2)"). +diff --git a/test/rebar_xref_eunit.erl b/test/rebar_xref_eunit.erl +index 341fe2e..f32ea46 100644 +--- a/test/rebar_xref_eunit.erl ++++ b/test/rebar_xref_eunit.erl +@@ -192,8 +192,8 @@ prepare_rebar_script() -> + {unix, _} -> + [] = os:cmd("chmod u+x " ++ Rebar); + {win32, _} -> +- {ok, _} = file:copy(?REBAR_SCRIPT ++ ".bat", +- ?TMP_DIR ++ "rebar.bat") ++ {ok, _} = file:copy(?REBAR_SCRIPT ++ ".cmd", ++ ?TMP_DIR ++ "rebar.cmd") + end. + + rebar() ->