You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.5 KiB

  1. -module(logging_rt).
  2. -export([files/0,
  3. run/1]).
  4. -define(APP_FILE, "ebin/logging.app").
  5. files() ->
  6. [
  7. {copy, "../../rebar", "rebar"},
  8. {create, ?APP_FILE, app(invalid_name, [])}
  9. ].
  10. run(_Dir) ->
  11. SharedExpected = "==> logging_rt \\(compile\\)",
  12. %% provoke ERROR due to an invalid app file
  13. retest:log(info, "Check 'compile' failure output~n"),
  14. ok = check_output("./rebar compile -q", should_fail,
  15. [SharedExpected, "ERROR: "],
  16. ["WARN: ", "INFO: ", "DEBUG: "]),
  17. %% fix bad app file
  18. ok = file:write_file(?APP_FILE, app(logging, [])),
  19. retest:log(info, "Check 'compile' success output~n"),
  20. ok = check_output("./rebar compile", should_succeed,
  21. [SharedExpected],
  22. ["ERROR: ", "WARN: ", "INFO: ", "DEBUG: "]),
  23. retest:log(info, "Check 'compile -v' success output~n"),
  24. ok = check_output("./rebar compile -v", should_succeed,
  25. [SharedExpected],
  26. ["ERROR: ", "INFO: ", "DEBUG: "]),
  27. retest:log(info, "Check 'compile -vv' success output~n"),
  28. ok = check_output("./rebar compile -vv", should_succeed,
  29. [SharedExpected, "DEBUG: "],
  30. ["ERROR: ", "INFO: "]),
  31. ok.
  32. check_output(Cmd, FailureMode, Expected, Unexpected) ->
  33. case {retest:sh(Cmd), FailureMode} of
  34. {{error, _}=Error, should_succeed} ->
  35. retest:log(error, "cmd '~s' failed:~n~p~n", [Cmd, Error]),
  36. Error;
  37. {{ok, Captured}, should_succeed} ->
  38. Joined = string:join(Captured, "\n"),
  39. check_output1(Cmd, Joined, Expected, Unexpected);
  40. {{error, {stopped, {_Rc, Captured}}}, should_fail} ->
  41. Joined = string:join(Captured, "\n"),
  42. check_output1(Cmd, Joined, Expected, Unexpected)
  43. end.
  44. check_output1(Cmd, Captured, Expected, Unexpected) ->
  45. ReOpts = [{capture, all, list}],
  46. ExMatches =
  47. lists:zf(
  48. fun(Pattern) ->
  49. case re:run(Captured, Pattern, ReOpts) of
  50. nomatch ->
  51. retest:log(error,
  52. "Expected pattern '~s' missing "
  53. "in the following output:~n"
  54. "=== BEGIN ===~n~s~n=== END ===~n",
  55. [Pattern, Captured]),
  56. {true, Pattern};
  57. {match, _} ->
  58. false
  59. end
  60. end, Expected),
  61. UnExMatches =
  62. lists:zf(
  63. fun(Pattern) ->
  64. case re:run(Captured, Pattern, ReOpts) of
  65. nomatch ->
  66. false;
  67. {match, [Match]} ->
  68. retest:log(
  69. console,
  70. "Unexpected output when running cmd '~s':~n~s~n",
  71. [Cmd, Match]),
  72. {true, Match}
  73. end
  74. end, Unexpected),
  75. case {ExMatches, UnExMatches} of
  76. {[], []} ->
  77. ok;
  78. _ ->
  79. error
  80. end.
  81. %%
  82. %% Generate the contents of a simple .app file
  83. %%
  84. app(Name, Modules) ->
  85. App = {application, Name,
  86. [{description, atom_to_list(Name)},
  87. {vsn, "1"},
  88. {modules, Modules},
  89. {registered, []},
  90. {applications, [kernel, stdlib]}]},
  91. io_lib:format("~p.\n", [App]).