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.

40 regels
1.5 KiB

  1. -module(rebar_unlock_SUITE).
  2. -include_lib("common_test/include/ct.hrl").
  3. -include_lib("eunit/include/eunit.hrl").
  4. -compile(export_all).
  5. all() -> [unlock, unlock_all].
  6. init_per_testcase(Case, Config0) ->
  7. Config = rebar_test_utils:init_rebar_state(Config0, atom_to_list(Case)),
  8. Lockfile = filename:join(?config(apps, Config), "rebar.lock"),
  9. ec_file:copy(filename:join(?config(data_dir, Config), "rebar.lock"),
  10. Lockfile),
  11. [{lockfile, Lockfile} | Config].
  12. end_per_testcase(_, Config) ->
  13. Config.
  14. unlock(Config) ->
  15. Locks = read_locks(Config),
  16. rebar_test_utils:run_and_check(Config, [], ["unlock", "fakeapp"], {ok, []}),
  17. Locks = read_locks(Config),
  18. rebar_test_utils:run_and_check(Config, [], ["unlock", "uuid"], {ok, []}),
  19. ?assertEqual(Locks -- ["uuid"], read_locks(Config)),
  20. rebar_test_utils:run_and_check(Config, [], ["unlock", "gproc,itc"], {ok, []}),
  21. ?assertEqual(Locks -- ["uuid","gproc","itc"], read_locks(Config)),
  22. rebar_test_utils:run_and_check(Config, [], ["unlock", string:join(Locks,",")], {ok, []}),
  23. ?assertEqual({error, enoent}, read_locks(Config)),
  24. ok.
  25. unlock_all(Config) ->
  26. [_|_] = read_locks(Config),
  27. rebar_test_utils:run_and_check(Config, [], ["unlock"], {ok, []}),
  28. ?assertEqual({error, enoent}, read_locks(Config)),
  29. ok.
  30. read_locks(Config) ->
  31. case file:consult(?config(lockfile, Config)) of
  32. {ok, [Locks]} -> [binary_to_list(element(1,Lock)) || Lock <- Locks];
  33. Other -> Other
  34. end.