erlang常用测试:如何启动iconv应用程序?

时间:2014-03-23 17:54:11

标签: erlang common-test

在我的应用程序中,我使用了this erlang-iconv的实现。 简单的测试套件:

-module(example_SUITE).

-include_lib("common_test/include/ct.hrl").

-export([all/0, suite/0, init_per_suite/1, end_per_suite/1,
         simple_test_case/1]).

all() ->
    [simple_test_case].

suite() ->
    [{timetrap, {minutes, 1}}].

init_per_suite(Config) ->
    application:start(iconv),
    Config.

end_per_suite(Config) ->
    application:stop(iconv),
    Config.

simple_test_case(_Config) ->
    ok.

尝试运行此套件时:

ct_run -pa ebin/ deps/*/ebin/ deps/*/deps/*/ebin/ -dir test/ -logdir logs/ -suite example_SUITE

...
=INFO REPORT==== 23-Mar-2014::19:45:30 ===
    application: iconv
    exited: {{shutdown,
                 {failed_to_start_child,iconv,
                     {{case_clause,{error,{open_error,-10}}},
                      [{iconv,init,1,[{file,"src/iconv.erl"},{line,49}]},
                       {gen_server,init_it,6,
                           [{file,"gen_server.erl"},{line,304}]},
                       {proc_lib,init_p_do_apply,3,
                           [{file,"proc_lib.erl"},{line,239}]}]}}},
             {iconv_app,start,[normal,[]]}}
    type: temporary
Testing web.wasearch.example_SUITE: TEST COMPLETE, 1 ok, 0 failed of 1 test cases
....

这个错误很明显,因为erlang-iconv依赖于priv_dir中的C盘:

init([]) ->
    case erl_ddll:load_driver(get_so_path(), iconv_drv) of
        ok -> ok;
        {error, already_loaded} -> ok
    end,
    Port = open_port({spawn, "iconv_drv"}, []),
    ets:new(iconv_table, [set, public, named_table]),
    ets:insert(iconv_table, {port, Port}),
    {ok, Port}.

get_so_path() ->
    case code:priv_dir(iconv) of
        {error, _} -> "./priv";
        Path -> Path

如何欺骗erlang-iconv并强制它在其他位置查找C驱动程序(在我的项目的deps目录中,禁止使用iconv' s priv_dir)?

1 个答案:

答案 0 :(得分:0)

从臀部拍摄:适当设置ERL_LIBS。

您的priv_dir应该设置正确且属于iconv应用程序,但由于Erlang系统没有选择,我猜您的-pa添加不会跟踪这个。将ERL_LIBS设置为包含deps可能会为构建提供技巧。