-
Notifications
You must be signed in to change notification settings - Fork 128
Expand file tree
/
Copy pathcuttlefish_escript_test.erl
More file actions
147 lines (129 loc) · 5.74 KB
/
Copy pathcuttlefish_escript_test.erl
File metadata and controls
147 lines (129 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
%% -------------------------------------------------------------------
%%
%% Copyright (c) 2014-2017 Basho Technologies, Inc.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License. You may obtain
%% a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied. See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------
-module(cuttlefish_escript_test).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-define(assertPrinted(___Text),
?assertPrinted(___Text, [])).
-define(assertPrinted(___Text, ___Opts),
begin
((fun() ->
case cuttlefish_test_group_leader:get_output() of
{ok, ___Output} ->
case {lists:member(exact, ___Opts),
re:run(___Output, ___Text)} of
{true, _} when ___Output =:= ___Text ->
ok;
{true, _} when ___Output =/= ___Text ->
erlang:error({assertPrinted_failed,
[{module, ?MODULE},
{line, ?LINE},
{expected, ___Text},
{actual, unicode:characters_to_list(___Output)}]});
{_, {match, _}} ->
ok;
{_, nomatch} ->
erlang:error({assertPrinted_failed,
[{module, ?MODULE},
{line, ?LINE},
{expected, ___Text},
{actual, unicode:characters_to_list(___Output)}]})
end;
error ->
erlang:error({assertPrinted_failed,
[{module, ?MODULE},
{line, ?LINE},
{expected, ___Text},
{reason, timed_out_on_receive}]})
end
end)())
end).
-define(capturing(__Forms),
begin
___OldLeader = group_leader(),
group_leader(cuttlefish_test_group_leader:new_group_leader(self()), self()),
try
__Forms
after
cuttlefish_test_group_leader:tidy_up(___OldLeader)
end
end).
describe_test_() ->
[
{"`cuttlefish describe` prints documentation", fun describe_prints_docs/0},
{"`cuttlefish describe` prints datatype's valid values", fun describe_prints_datatype/0},
{"`cuttlefish describe` prints default", fun describe_prints_default/0},
{"`cuttlefish describe` prints configured value", fun describe_prints_configured/0},
{"`cuttlefish describe` prints erlang application key", fun describe_prints_app_key/0},
{"`cuttlefish describe` prints message when no default exists", fun describe_prints_no_default/0},
{"`cuttlefish describe` prints message when value not configured", fun describe_prints_not_configured/0}
].
describe(Key) ->
?assertThrow(stop_deactivate, cuttlefish_escript:main([
"-i", "test/riak.schema",
"-c", "test/riak.conf",
"describe", Key ])).
describe_prints_docs() ->
?capturing(begin
describe("ring_size"),
?assertPrinted("Documentation for ring_size"),
?assertPrinted("Default ring creation size\\. Make sure it is a power of 2")
end).
describe_prints_datatype() ->
?capturing(begin
describe("storage_backend"),
?assertPrinted("- one of: bitcask, leveldb, memory, multi")
end).
describe_prints_default() ->
?capturing(begin
describe("ring_size"),
?assertPrinted("Default Value : 64")
end).
describe_prints_configured() ->
?capturing(begin
describe("anti_entropy"),
?assertPrinted("Set Value : debug")
end).
describe_prints_app_key() ->
?capturing(begin
describe("leveldb.bloomfilter"),
?assertPrinted("Internal key : eleveldb\\.use_bloomfilter")
end).
describe_prints_no_default() ->
?capturing(begin
describe("listener.https.foo"),
?assertPrinted("No default set")
end).
describe_prints_not_configured() ->
?capturing(begin
describe("ssl.keyfile"),
?assertPrinted("Value not set in test/riak.conf")
end).
silent_test() ->
?capturing(begin
cuttlefish_escript:main(["-i", "test/riak.schema", "-c", "test/riak.conf", "--etc_dir", "etc", "--silent"]),
?assertPrinted("", [exact])
end).
vm_args_test() ->
?capturing(begin
cuttlefish_escript:main(["--schema_file", "priv/erlang_vm.schema", "--conf_file", "test/riak.conf", "--etc_dir", "etc", "--dest_file", "vm.generated.args", "--allow_extra", "--silent"]),
?assertPrinted("", [exact])
end).
-endif.