包含对os:cmd的调用的eurls在Mac OSX 10.6中失败

时间:2012-02-22 08:55:32

标签: erlang otp

我刚刚在我的工作场所“继承”了一个OTP项目,我遇到了以下问题: 一组测试包括对使用os:cmd的函数的调用,这似乎是测试失败的原因,这是我在失败和成功测试之间找到的唯一区别。我在Mac OS X 10.6.8和Erlang 14A上运行测试。

这些是失败的功能:

execute_shell_command(Config, Event, Params, output) ->
    execute_with_output(Config, Event, Params);
execute_shell_command(Config, Event, Params, status) ->
    execute_with_status(Config, Event, Params).

execute_with_output(Config, Event, Params) ->
    Command = executable(Config, Event),
    String = string:join([Command|Params], " "),
    error_logger:info_msg("Command to be invoked:~n~p", [String]),
    os:cmd(String). 

以下是失败的测试:

execute_with_output_test() ->
    Config = [{click, [{log_path, "fixtures"}, {executable, "echo"}]},
      {processing_stat_path, "fixtures"}],
    ?assertMatch("OK", execute_with_output(Config, click, ["-n", "OK"])).

execute_with_output_success_test() ->
  Config = [{click, [{log_path, "fixtures"}, {executable, "true"}]},
      {processing_stat_path, "fixtures"}],
  ?assertMatch("success", execute_with_output(Config, click,
                      [status_as_output_suffix()])).

execute_with_output_failure_test() ->
   Config = [{click, [{log_path, "fixtures"}, {executable, "false"}]},
      {processing_stat_path, "fixtures"}],
   ?assertMatch("error", execute_with_output(Config, click,
                    [status_as_output_suffix()])).

execute_with_status_success_test() ->
    Config = [{click, [{log_path, "fixtures"}, {executable, "true"}]},
      {processing_stat_path, "fixtures"}],
    ?assertMatch(ok, execute_with_status(Config, click, [])).

execute_with_status_failure_test() ->
    Config = [{click, [{log_path, "fixtures"}, {executable, "false"}]},
      {processing_stat_path, "fixtures"}],
    ?assertMatch(error, execute_with_status(Config, click, [])).

hdfs_put_command_parameters_echoed_test() ->
    Config = [{click, [{log_path, "fixtures"},
           {executable, "echo -n"},
           {delete_after_copy, false},
           {hdfs_url, "hdfs://localhost/unprocessed/clicks"}]},
      {processing_stat_path, "fixtures"}],
    {ok, Hostname} = inet:gethostname(),
    Expected = "fs -put test_file hdfs://localhost/unprocessed/clicks/" ++ Hostname ++ "-test_file",
    ?assertMatch(Expected, hdfs_put_command(Config, click, "test_file", output)).

click_upload_success_test() ->
    Config = [{click, [{log_path, "fixtures"},
           {executable, "fixtures/hadoop_mock_success"},
           {delete_after_copy, false},
           {hdfs_url, "hdfs://testhost"}]},
      {processing_state_path, "fixtures"}],
    unconsult(configuration_file(test), Config),
    Callback = click_upload(test),
    ?assertMatch([ok, ok], Callback(click, test_message)),
    write_last_processed(Config, click, "click-2009-04-10-17-00").

测试套件的输出

erl -noshell -setcookie colonel_hathi -sname test_units_talkative_client -eval 'error_logger:tty(false).' -pa ./ebin -eval 'case lists:member({test,0}, hdfs_loader:module_info(exports)) of true -> hdfs_loader:test(); false -> io:format("  [No test in ~p]~n", [hdfs_loader]) end' -eval 'case lists:member({test,0}, talkative_client_app:module_info(exports)) of true -> talkative_client_app:test(); false -> io:format("  [No test in ~p]~n", [talkative_client_app]) end' -eval 'case lists:member({test,0}, talkative_client_connection:module_info(exports)) of true -> talkative_client_connection:test(); false -> io:format("  [No test in ~p]~n", [talkative_client_connection]) end' -eval 'case lists:member({test,0}, talkative_client_control:module_info(exports)) of true -> talkative_client_control:test(); false -> io:format("  [No test in ~p]~n", [talkative_client_control]) end' -eval 'case lists:member({test,0}, talkative_client_sup:module_info(exports)) of true -> talkative_client_sup:test(); false -> io:format("  [No test in ~p]~n", [talkative_client_sup]) end' -s init stop
hdfs_loader: execute_with_output_test...*failed*
::error:{assertMatch_failed,
      [{module,hdfs_loader},
       {line,310},
       {expression,
           "execute_with_output ( Config , click , [ \"-n\" , \"OK\" ] )"},
       {expected,"\"OK\""},
       {value,"-n OK\n"}]}
 in function hdfs_loader:'-execute_with_output_test/0-fun-0-'/0


hdfs_loader: execute_with_output_success_test...*failed*
::error:{assertMatch_failed,
      [{module,hdfs_loader},
       {line,315},
       {expression,
           "execute_with_output ( Config , click , [ status_as_output_suffix ( ) ] )"},
       {expected,"\"success\""},
       {value,"-n success\n"}]}
     in function hdfs_loader:'-execute_with_output_success_test/0-fun-0-'/0


hdfs_loader: execute_with_output_failure_test...*failed*
::error:{assertMatch_failed,
      [{module,hdfs_loader},
       {line,321},
       {expression,
           "execute_with_output ( Config , click , [ status_as_output_suffix ( ) ] )"},
       {expected,"\"error\""},
       {value,"-n error\n"}]}
     in function hdfs_loader:'-execute_with_output_failure_test/0-fun-0-'/0


hdfs_loader: execute_with_status_success_test...*failed*
::error:{assertMatch_failed,
      [{module,hdfs_loader},
       {line,327},
       {expression,"execute_with_status ( Config , click , [ ] )"},
       {expected,"ok"},
       {value,"-n success\n"}]}
     in function hdfs_loader:'-execute_with_status_success_test/0-fun-0-'/0


hdfs_loader: execute_with_status_failure_test...*failed*
::error:{assertMatch_failed,
      [{module,hdfs_loader},
       {line,332},
       {expression,"execute_with_status ( Config , click , [ ] )"},
       {expected,"error"},
       {value,"-n error\n"}]}
    in function hdfs_loader:'-execute_with_status_failure_test/0-fun-0-'/0


hdfs_loader: hdfs_put_command_parameters_echoed_test...*failed*
::error:{assertMatch_failed,
      [{module,hdfs_loader},
       {line,342},
       {expression,
           "hdfs_put_command ( Config , click , \"test_file\" , output )"},
       {expected,"Expected"},
       {value,
           "-n fs -put test_file hdfs://localhost/unprocessed/clicks/ws-dhcp_3_156-test_file\n"}]}
  in function hdfs_loader:'-hdfs_put_command_parameters_echoed_test/0-fun-0-'/1


hdfs_loader: click_upload_success_test...*failed*
::error:{assertMatch_failed,[{module,hdfs_loader},
                       {line,352},
                       {expression,"Callback ( click , test_message )"},
                       {expected,"[ ok , ok ]"},
                       {value,[error,error]}]}
    in function hdfs_loader:'-click_upload_success_test/0-fun-0-'/1
    in call from hdfs_loader:click_upload_success_test/0


 =======================================================
 Failed: 7.  Skipped: 0.  Passed: 17.
 All 5 tests passed.
 All 46 tests passed.
[No test in talkative_client_control]
rake aborted!
Tests failed

任何帮助表示赞赏!

1 个答案:

答案 0 :(得分:1)

在Linux机上:

1> os:cmd(["echo -n test"]).
"test"
2> os:cmd(["echo test"]).
"test\n"

echo在Mac上表现不同。具体来说,-n默认不起作用。这可能是一个可能的解决方案:http://hints.macworld.com/article.php?story=20071106192548833

另一个解决方案是在测试中停止使用-n,并在换行符上删除或匹配。