Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : /**
4 : : * @brief Verify that a legacy CLI spelling maps to its canonical diagnostic
5 : : *
6 : : * @param[in] arguments Complete CLI arguments for the compatibility check
7 : : * @param[in] canonical_diagnostic Canonical TESTING diagnostic expected in stdout
8 : : * @return Return status code
9 : : */
10 : 8 : static Return assert_legacy_cli_argument(
11 : : const char *arguments,
12 : : const char *canonical_diagnostic)
13 : : {
14 : : /* Status returned by this function through deliver()
15 : : Default value assumes successful completion */
16 : 8 : Return status = SUCCESS;
17 : :
18 : 8 : m_create(char,result,MEMORY_STRING);
19 : :
20 [ + - - + ]: 8 : if(arguments == NULL || canonical_diagnostic == NULL)
21 : : {
22 : 0 : status = FAILURE;
23 : : }
24 : :
25 : 8 : run(set_environment_variable("TESTING","true"));
26 : 8 : run(runit(arguments,result,NULL,COMPLETED,ALLOW_BOTH));
27 : :
28 [ + - - + ]: 8 : if((SUCCESS & status) && strstr(m_text(result),canonical_diagnostic) == NULL)
29 : : {
30 : 0 : status = FAILURE;
31 : : }
32 : :
33 : 8 : call(m_del(result));
34 : :
35 : 8 : deliver(status);
36 : : }
37 : :
38 : : /**
39 : : * @brief Verify the legacy --db-clean-ignored spelling
40 : : *
41 : : * @return Return status code
42 : : */
43 : 2 : static Return test0039_1(void)
44 : : {
45 : 2 : INITTEST;
46 : :
47 : 2 : ASSERT(SUCCESS == assert_legacy_cli_argument(
48 : : "--dry-run --db-clean-ignored --database=0039_1.db tests/fixtures/diffs/diff1",
49 : : "TESTING:argument:db-drop-ignored=yes"));
50 : :
51 : 2 : RETURN_STATUS;
52 : : }
53 : :
54 : : /**
55 : : * @brief Verify the legacy --drop-inaccessible spelling
56 : : *
57 : : * @return Return status code
58 : : */
59 : 2 : static Return test0039_2(void)
60 : : {
61 : 2 : INITTEST;
62 : :
63 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
64 : 2 : ASSERT(SUCCESS == runit(
65 : : "--database=0039_2.db tests/fixtures/diffs/diff1",
66 : : NULL,
67 : : NULL,
68 : : COMPLETED,
69 : : ALLOW_BOTH));
70 : :
71 : 2 : ASSERT(SUCCESS == assert_legacy_cli_argument(
72 : : "--check-level=QUICK --dry-run --update --drop-inaccessible --database=0039_2.db tests/fixtures/diffs/diff1",
73 : : "TESTING:argument:db-drop-inaccessible=yes"));
74 : :
75 : 2 : ASSERT(SUCCESS == delete_path("0039_2.db"));
76 : :
77 : 2 : RETURN_STATUS;
78 : : }
79 : :
80 : : /**
81 : : * @brief Verify the legacy --start-device-only spelling
82 : : *
83 : : * @return Return status code
84 : : */
85 : 2 : static Return test0039_3(void)
86 : : {
87 : 2 : INITTEST;
88 : :
89 : 2 : ASSERT(SUCCESS == assert_legacy_cli_argument(
90 : : "--dry-run --start-device-only --database=0039_3.db tests/fixtures/diffs/diff1",
91 : : "TESTING:argument:one-file-system=yes"));
92 : :
93 : 2 : RETURN_STATUS;
94 : : }
95 : :
96 : : /**
97 : : * @brief Verify the legacy -o short spelling
98 : : *
99 : : * @return Return status code
100 : : */
101 : 2 : static Return test0039_4(void)
102 : : {
103 : 2 : INITTEST;
104 : :
105 : 2 : ASSERT(SUCCESS == assert_legacy_cli_argument(
106 : : "--dry-run -o --database=0039_4.db tests/fixtures/diffs/diff1",
107 : : "TESTING:argument:one-file-system=yes"));
108 : :
109 : 2 : RETURN_STATUS;
110 : : }
111 : :
112 : : /**
113 : : * @brief Verify that help shows canonical spellings and hides legacy spellings
114 : : *
115 : : * @return Return status code
116 : : */
117 : 2 : static Return test0039_5(void)
118 : : {
119 : 2 : INITTEST;
120 : :
121 : 2 : m_create(char,help_output,MEMORY_STRING);
122 : 2 : m_create(char,usage_output,MEMORY_STRING);
123 : :
124 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
125 : 2 : ASSERT(SUCCESS == runit("--help",help_output,NULL,COMPLETED,ALLOW_BOTH));
126 : 2 : ASSERT(SUCCESS == runit("--usage",usage_output,NULL,COMPLETED,ALLOW_BOTH));
127 : :
128 : 2 : const char *canonical_arguments[] = {
129 : : "--db-drop-ignored",
130 : : "--db-drop-inaccessible",
131 : : "--one-file-system"
132 : : };
133 : :
134 [ + + ]: 8 : for(size_t i = 0; i < sizeof(canonical_arguments) / sizeof(canonical_arguments[0]); i++)
135 : : {
136 : 6 : ASSERT(NULL != strstr(m_text(help_output),canonical_arguments[i]));
137 : 6 : ASSERT(NULL != strstr(m_text(usage_output),canonical_arguments[i]));
138 : : }
139 : :
140 : 2 : const char *legacy_arguments[] = {
141 : : "--db-clean-ignored",
142 : : "--drop-inaccessible",
143 : : "--start-device-only"
144 : : };
145 : :
146 [ + + ]: 8 : for(size_t i = 0; i < sizeof(legacy_arguments) / sizeof(legacy_arguments[0]); i++)
147 : : {
148 : 6 : ASSERT(NULL == strstr(m_text(help_output),legacy_arguments[i]));
149 : 6 : ASSERT(NULL == strstr(m_text(usage_output),legacy_arguments[i]));
150 : : }
151 : :
152 : 2 : ASSERT(NULL == strstr(m_text(help_output)," -o,"));
153 : :
154 : 2 : const char *short_options = strstr(m_text(usage_output),"Usage: precizer [-");
155 : 2 : ASSERT(short_options != NULL);
156 : :
157 [ + - ]: 2 : if(short_options != NULL)
158 : : {
159 : 2 : const char *short_options_end = strchr(short_options,']');
160 : 2 : ASSERT(short_options_end != NULL);
161 : :
162 [ + - ]: 2 : if(short_options_end != NULL)
163 : : {
164 : 2 : const char *legacy_short_option = strchr(short_options,'o');
165 : 2 : ASSERT(legacy_short_option == NULL || legacy_short_option > short_options_end);
166 : : }
167 : : }
168 : :
169 : 2 : m_del(usage_output);
170 : 2 : m_del(help_output);
171 : :
172 : 2 : RETURN_STATUS;
173 : : }
174 : :
175 : : /**
176 : : * @brief Verify the canonical filesystem restriction through CLI and configuration
177 : : *
178 : : * A small dry run checks the selected traversal flag and complete output without
179 : : * creating a database or requiring an additional mounted filesystem
180 : : *
181 : : * @return Return status for CLI and configuration output comparisons
182 : : */
183 : 2 : static Return test0039_6(void)
184 : : {
185 : 2 : INITTEST;
186 : :
187 : 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
188 : 2 : const struct argument_test_case cases[] = {
189 : : {"--one-file-system --dry-run --database=0039_6.db tests/fixtures/diffs/diff1/2",
190 : : COMPLETED,"templates/0039_006.txt",STDERR_MUST_BE_EMPTY},
191 : : {0}
192 : : };
193 : 2 : ASSERT(SUCCESS == run_and_match_templates(cases,NULL,NULL));
194 : :
195 : 2 : ASSERT(SUCCESS == copy_path("tests/templates/0039_006.conf","0039_006.conf"));
196 : 2 : const struct argument_test_case file_cases[] = {
197 : : {"--config=0039_006.conf",COMPLETED,"templates/0039_006.txt",STDERR_MUST_BE_EMPTY},
198 : : {0}
199 : : };
200 : 2 : ASSERT(SUCCESS == run_and_match_templates(file_cases,NULL,NULL));
201 : 2 : call(delete_path_if_present("0039_006.conf"));
202 : :
203 : 2 : RETURN_STATUS;
204 : : }
205 : :
206 : : /**
207 : : * @brief Run legacy CLI compatibility and canonical filesystem option tests
208 : : *
209 : : * @return Return status code
210 : : */
211 : 2 : Return test0039(void)
212 : : {
213 : 2 : INITTEST;
214 : :
215 : 2 : TEST(test0039_1,"Legacy --db-clean-ignored maps to --db-drop-ignored");
216 : 2 : TEST(test0039_2,"Legacy --drop-inaccessible maps to --db-drop-inaccessible");
217 : 2 : TEST(test0039_3,"Legacy --start-device-only maps to --one-file-system");
218 : 2 : TEST(test0039_4,"Legacy -o maps to -x");
219 : 2 : TEST(test0039_5,"Help and usage hide legacy CLI spellings");
220 : 2 : TEST(test0039_6,"One-file-system selects the same traversal settings through CLI and configuration");
221 : :
222 : 2 : RETURN_STATUS;
223 : : }
|