1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : arb_test.cxx // |
---|
4 | // Purpose : unit tester for tools // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in February 2011 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // =============================================================== // |
---|
11 | |
---|
12 | #include <arbdbt.h> |
---|
13 | #include <arb_defs.h> |
---|
14 | #include <arb_sleep.h> |
---|
15 | #include <arb_diff.h> |
---|
16 | #include <unistd.h> |
---|
17 | |
---|
18 | int ARB_main(int , char *[]) { |
---|
19 | fputs("don't call us\n", stderr); |
---|
20 | return EXIT_SUCCESS; |
---|
21 | } |
---|
22 | |
---|
23 | // -------------------------------------------------------------------------------- |
---|
24 | |
---|
25 | #ifdef UNIT_TESTS |
---|
26 | #include <arb_file.h> |
---|
27 | #include <test_unit.h> |
---|
28 | #include <ut_valgrinded.h> |
---|
29 | |
---|
30 | // -------------------------------------------------------------------------------- |
---|
31 | |
---|
32 | |
---|
33 | inline void make_valgrinded_call_from_pipe(char *&command) { |
---|
34 | using namespace utvg; |
---|
35 | static valgrind_info valgrind; |
---|
36 | if (valgrind.wanted) { |
---|
37 | char *pipeSym = strchr(command, '|'); |
---|
38 | if (pipeSym) { |
---|
39 | char *left = ARB_strpartdup(command, pipeSym-1); |
---|
40 | char *right = strdup(pipeSym+1); |
---|
41 | |
---|
42 | make_valgrinded_call(left); |
---|
43 | make_valgrinded_call_from_pipe(right); |
---|
44 | |
---|
45 | freeset(command, GBS_global_string_copy("%s | %s", left, right)); |
---|
46 | |
---|
47 | free(right); |
---|
48 | free(left); |
---|
49 | } |
---|
50 | else { |
---|
51 | make_valgrinded_call(command); |
---|
52 | } |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | inline GB_ERROR valgrinded_system(const char *cmdline) { |
---|
57 | char *cmddup = strdup(cmdline); |
---|
58 | make_valgrinded_call_from_pipe(cmddup); |
---|
59 | |
---|
60 | GB_ERROR error = GBK_system(cmddup); |
---|
61 | free(cmddup); |
---|
62 | return error; |
---|
63 | } |
---|
64 | |
---|
65 | #define RUN_TOOL(cmdline) valgrinded_system(cmdline) |
---|
66 | #define RUN_TOOL_NEVER_VALGRIND(cmdline) GBK_system(cmdline) |
---|
67 | |
---|
68 | #define TEST_RUN_TOOL(cmdline) TEST_EXPECT_NO_ERROR(RUN_TOOL(cmdline)) |
---|
69 | #define TEST_RUN_TOOL_NEVER_VALGRIND(cmdline) TEST_EXPECT_NO_ERROR(RUN_TOOL_NEVER_VALGRIND(cmdline)) |
---|
70 | |
---|
71 | static const char *checkedPipeCommand(const char *pipeCommand) { |
---|
72 | #if defined(ASSERTION_USED) |
---|
73 | const char *pipe = strchr(pipeCommand, '|'); |
---|
74 | gb_assert(pipe && strchr(pipe+1, '|') == 0); // only works for _exactly one_ pipe symbol |
---|
75 | #endif |
---|
76 | |
---|
77 | char *quotedCommand = GBK_singlequote(GBS_global_string("%s;exit $((${PIPESTATUS[0]} | ${PIPESTATUS[1]}))", pipeCommand)); |
---|
78 | const char *checked_cmd = GBS_global_string("bash -c %s", quotedCommand); |
---|
79 | free(quotedCommand); |
---|
80 | return checked_cmd; |
---|
81 | } |
---|
82 | |
---|
83 | void TEST_SLOW_ascii_2_bin_2_ascii() { |
---|
84 | const char *ascii_ORG = "TEST_loadsave_ascii.arb"; |
---|
85 | const char *ascii = "bin2ascii.arb"; |
---|
86 | const char *binary = "ascii2bin.arb"; |
---|
87 | const char *binary_2ND = "ascii2bin2.arb"; |
---|
88 | const char *binary_3RD = "ascii2bin3.arb"; |
---|
89 | |
---|
90 | // test that errors from _each_ part of a piped command propagate correctly: |
---|
91 | const char *failing_piped_cmds[] = { |
---|
92 | "arb_weirdo | wc -l", // first command fails |
---|
93 | "echo hello | arb_weirdo", // second command fails |
---|
94 | "arb_weirdo | arb_weirdo", // both commands fail |
---|
95 | }; |
---|
96 | for (unsigned c = 0; c<ARRAY_ELEMS(failing_piped_cmds); ++c) { |
---|
97 | TEST_EXPECT_ERROR_CONTAINS(RUN_TOOL(checkedPipeCommand(failing_piped_cmds[c])), "System call failed"); |
---|
98 | } |
---|
99 | |
---|
100 | TEST_RUN_TOOL("arb_2_ascii --help"); // checks proper documentation of available compression flags (in GB_get_supported_compression_flags) |
---|
101 | |
---|
102 | // test conversion file -> file |
---|
103 | TEST_RUN_TOOL(GBS_global_string("arb_2_bin %s %s", ascii_ORG, binary)); |
---|
104 | TEST_RUN_TOOL(GBS_global_string("arb_2_ascii %s %s", binary, ascii)); |
---|
105 | |
---|
106 | TEST_EXPECT_TEXTFILES_EQUAL(ascii, ascii_ORG); |
---|
107 | |
---|
108 | // test conversion (bin->ascii->bin) via stream (this tests 'arb_repair') |
---|
109 | TEST_RUN_TOOL(checkedPipeCommand(GBS_global_string("arb_2_ascii %s - | arb_2_bin - %s", binary, binary_2ND))); |
---|
110 | // TEST_EXPECT_FILES_EQUAL(binary, binary_2ND); // can't compare binary files (binary_2ND differs (keys?)) |
---|
111 | // instead convert back to ascii and compare result with original |
---|
112 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(ascii)); |
---|
113 | TEST_RUN_TOOL(GBS_global_string("arb_2_ascii %s %s", binary_2ND, ascii)); |
---|
114 | TEST_EXPECT_FILES_EQUAL(ascii, ascii_ORG); |
---|
115 | |
---|
116 | |
---|
117 | // test same using compression (gzip and bzip2) |
---|
118 | TEST_RUN_TOOL(checkedPipeCommand(GBS_global_string("arb_2_ascii -Cz %s - | arb_2_bin -CB - %s", binary, binary_3RD))); |
---|
119 | // TEST_EXPECT_FILES_EQUAL(binary, binary_2ND); // can't compare binary files (binary_3RD differs (keys?)) |
---|
120 | // instead convert back to ascii and compare result with original |
---|
121 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(ascii)); |
---|
122 | TEST_RUN_TOOL(GBS_global_string("arb_2_ascii %s %s", binary_3RD, ascii)); |
---|
123 | TEST_EXPECT_FILES_EQUAL(ascii, ascii_ORG); |
---|
124 | |
---|
125 | TEST_EXPECT_ERROR_CONTAINS(RUN_TOOL("arb_2_ascii -Cq -"), "System call failed"); // "Unknown compression flag 'q'" |
---|
126 | |
---|
127 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(ascii)); |
---|
128 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(binary)); |
---|
129 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(binary_2ND)); |
---|
130 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(binary_3RD)); |
---|
131 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink("ascii2bin.ARF")); |
---|
132 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink("ascii2bin2.ARF")); |
---|
133 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink("ascii2bin3.ARF")); |
---|
134 | } |
---|
135 | |
---|
136 | void TEST_arb_primer() { |
---|
137 | const char *primer_db = "TEST_nuc.arb"; |
---|
138 | const char *primer_stdin = "tools/arb_primer.in"; |
---|
139 | const char *primer_out = "tools/arb_primer.out"; |
---|
140 | const char *primer_expected = "tools/arb_primer_expected.out"; |
---|
141 | |
---|
142 | TEST_RUN_TOOL(GBS_global_string("arb_primer %s < %s", primer_db, primer_stdin)); |
---|
143 | TEST_EXPECT_FILES_EQUAL(primer_out, primer_expected); |
---|
144 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(primer_out)); |
---|
145 | } |
---|
146 | |
---|
147 | static GB_ERROR removeVaryingDateFromTreeRemarks(const char *dbname) { |
---|
148 | GB_ERROR error = NULL; |
---|
149 | GB_shell shell; |
---|
150 | GBDATA *gb_main = GB_open(dbname, "rw"); |
---|
151 | if (!gb_main) error = GB_await_error(); |
---|
152 | else { |
---|
153 | { |
---|
154 | GB_transaction ta(gb_main); |
---|
155 | |
---|
156 | GBDATA *gb_tree_data = GBT_get_tree_data(gb_main); |
---|
157 | const char *truncate_after = "\nunittest-tree\n"; |
---|
158 | size_t truncate_offset = strlen(truncate_after); |
---|
159 | |
---|
160 | if (!gb_tree_data) error = GB_await_error(); |
---|
161 | else { |
---|
162 | for (GBDATA *gb_tree = GB_child(gb_tree_data); |
---|
163 | gb_tree && !error; |
---|
164 | gb_tree = GB_nextChild(gb_tree)) |
---|
165 | { |
---|
166 | GBDATA *gb_remark = GB_entry(gb_tree, "remark"); |
---|
167 | if (!gb_remark) { |
---|
168 | error = "could not find 'remark' entry"; |
---|
169 | } |
---|
170 | else { |
---|
171 | char *remark = GB_read_string(gb_remark); |
---|
172 | char *found = strstr(remark, truncate_after); |
---|
173 | |
---|
174 | if (found) { |
---|
175 | strcpy(found+truncate_offset, "<date removed for testing>"); |
---|
176 | error = GB_write_string(gb_remark, remark); |
---|
177 | } |
---|
178 | free(remark); |
---|
179 | } |
---|
180 | } |
---|
181 | } |
---|
182 | |
---|
183 | ta.close(error); |
---|
184 | } |
---|
185 | if (!error) error = GB_save_as(gb_main, dbname, "a"); |
---|
186 | GB_close(gb_main); |
---|
187 | } |
---|
188 | return error; |
---|
189 | } |
---|
190 | |
---|
191 | // #define TEST_AUTO_UPDATE_TREE // uncomment to auto-update expected tree |
---|
192 | |
---|
193 | void TEST_SLOW_arb_read_tree() { |
---|
194 | struct { |
---|
195 | const char *basename; |
---|
196 | const char *extraArgs; |
---|
197 | } |
---|
198 | run[] = { |
---|
199 | { "newick", "" }, |
---|
200 | { "newick_sq", "-commentFromFile general/text.input" }, |
---|
201 | { "newick_dq", "-scale 0.5" }, |
---|
202 | { "newick_group", "-scale 10 -consense 10" }, |
---|
203 | { "newick_len", "" }, |
---|
204 | { "newick_len_group", "" }, |
---|
205 | }; |
---|
206 | |
---|
207 | const char *dbin = "min_ascii.arb"; |
---|
208 | const char *dbout = "tools/read_tree_out.arb"; |
---|
209 | const char *dbexpected = "tools/read_tree_out_expected.arb"; |
---|
210 | |
---|
211 | for (size_t b = 0; b<ARRAY_ELEMS(run); ++b) { |
---|
212 | const char *basename = run[b].basename; |
---|
213 | const char *extraArgs = run[b].extraArgs; |
---|
214 | char *treefile = GBS_global_string_copy("tools/%s.tree", basename); |
---|
215 | char *treename = GBS_global_string_copy("tree_%s", basename); |
---|
216 | |
---|
217 | TEST_RUN_TOOL(GBS_global_string("arb_read_tree -db %s %s %s %s \"test %s\" %s", |
---|
218 | dbin, dbout, treename, treefile, basename, extraArgs)); |
---|
219 | |
---|
220 | dbin = dbout; // use out-db from previous loop ( = write all trees into one db) |
---|
221 | |
---|
222 | free(treename); |
---|
223 | free(treefile); |
---|
224 | } |
---|
225 | |
---|
226 | TEST_EXPECT_NO_ERROR(removeVaryingDateFromTreeRemarks(dbout)); |
---|
227 | #if defined(TEST_AUTO_UPDATE_TREE) |
---|
228 | TEST_COPY_FILE(dbout, dbexpected); |
---|
229 | #else // !defined(TEST_AUTO_UPDATE_TREE) |
---|
230 | TEST_EXPECT_TEXTFILES_EQUAL(dbexpected, dbout); |
---|
231 | #endif |
---|
232 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(dbout)); |
---|
233 | } |
---|
234 | |
---|
235 | #define TEST_ARB_REPLACE(infile,expected,args) do { \ |
---|
236 | char *tmpfile = GBS_global_string_copy("%s.tmp", expected); \ |
---|
237 | TEST_RUN_TOOL_NEVER_VALGRIND(GBS_global_string("cp %s %s", infile, tmpfile)); \ |
---|
238 | TEST_RUN_TOOL(GBS_global_string("arb_replace %s %s", args, tmpfile)); \ |
---|
239 | TEST_EXPECT_TEXTFILES_EQUAL(tmpfile, expected); \ |
---|
240 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(tmpfile)); \ |
---|
241 | free(tmpfile); \ |
---|
242 | } while(0) |
---|
243 | |
---|
244 | void TEST_arb_replace() { |
---|
245 | const char *infile = "tools/arb_replace.in"; |
---|
246 | const char *file1 = "tools/arb_replace_1.out"; |
---|
247 | const char *file2 = "tools/arb_replace_2.out"; |
---|
248 | |
---|
249 | TEST_ARB_REPLACE(infile, "tools/arb_replace_1.out", "'gene=GONE'"); |
---|
250 | TEST_ARB_REPLACE(file1, infile, "-l 'GONE=gene'"); |
---|
251 | TEST_ARB_REPLACE(file1, file2, "-L 'GONE=gene:\"*\"=( * )'"); |
---|
252 | } |
---|
253 | |
---|
254 | // -------------------------------------------------------------------------------- |
---|
255 | |
---|
256 | #include "command_output.h" |
---|
257 | |
---|
258 | void TEST_arb_message() { |
---|
259 | TEST_STDERR_EQUALS("arb_message \"this is the test message\"", |
---|
260 | "arb_message: this is the test message\n"); |
---|
261 | } |
---|
262 | |
---|
263 | void TEST_SLOW_arb_probe() { |
---|
264 | // test called here currently are duplicating the tests in |
---|
265 | // arb_probe.cxx@TEST_SLOW_match_probe |
---|
266 | // and arb_probe.cxx@TEST_SLOW_design_probe |
---|
267 | // |
---|
268 | // Here test of functionality is secondary. |
---|
269 | // The primary goal here is to test calling the tools (i.e. arb_probe) |
---|
270 | |
---|
271 | TEST_SETUP_GLOBAL_ENVIRONMENT("ptserver"); |
---|
272 | TEST_STDOUT_EQUALS("arb_probe" |
---|
273 | " serverid=-666" |
---|
274 | " matchsequence=UAUCGGAGAGUUUGA", |
---|
275 | |
---|
276 | /* ---- */ " name---- fullname mis N_mis wmis pos ecoli rev 'UAUCGGAGAGUUUGA'\1" |
---|
277 | "BcSSSS00\1" " BcSSSS00 0 0 0.0 3 2 0 .......UU-===============-UCAAGUCGA\1" |
---|
278 | ); |
---|
279 | |
---|
280 | TEST_STDOUT_EQUALS("arb_probe" |
---|
281 | " serverid=-666" |
---|
282 | " designnames=ClnCorin#CltBotul#CPPParap#ClfPerfr" |
---|
283 | " designmintargets=100", |
---|
284 | |
---|
285 | "Probe design parameters:\n" |
---|
286 | "Length of probe 18\n" |
---|
287 | "Temperature [ 0.0 -400.0]\n" |
---|
288 | "GC-content [30.0 - 80.0]\n" |
---|
289 | "E.Coli position [any]\n" |
---|
290 | "Max. nongroup hits 0\n" |
---|
291 | "Min. group hits 100% (max. rejected coverage: 75%)\n" |
---|
292 | "Target le apos ecol qual grps G+C temp Probe sequence | Decrease T by n*.3C -> probe matches n non group species\n" |
---|
293 | "CGAAAGGAAGAUUAAUAC 18 A=94 82 77 4 33.3 48.0 GUAUUAAUCUUCCUUUCG | - - - - - - - - - - - - - - - - - - - -\n" |
---|
294 | "GAAAGGAAGAUUAAUACC 18 A+ 1 83 77 4 33.3 48.0 GGUAUUAAUCUUCCUUUC | - - - - - - - - - - - - - - - - - - - -\n" |
---|
295 | "UCAAGUCGAGCGAUGAAG 18 B=18 17 61 4 50.0 54.0 CUUCAUCGCUCGACUUGA | - - - - - - - - - - - - - - - 2 2 2 2 2\n" |
---|
296 | "AUCAAGUCGAGCGAUGAA 18 B- 1 16 45 4 44.4 52.0 UUCAUCGCUCGACUUGAU | - - - - - - - - - - - 2 2 2 2 2 2 2 2 2\n" |
---|
297 | ); |
---|
298 | } |
---|
299 | |
---|
300 | void TEST_arb_probe_match() { |
---|
301 | TEST_SETUP_GLOBAL_ENVIRONMENT("ptserver"); |
---|
302 | |
---|
303 | // this probe-match is also tested with 'arb_probe'. see arb_probe.cxx@TEST_arb_probe_match |
---|
304 | TEST_STDOUT_EQUALS("arb_probe_match" |
---|
305 | " --port :../sockets/pt.socket" |
---|
306 | " --n-matches 0" |
---|
307 | " --n-match-bound 4" |
---|
308 | " --mismatches 3" |
---|
309 | " --sequence GAGCGGUCAG", |
---|
310 | |
---|
311 | "acc \t" "start\t" "stop\t" "pos\t" "mis\t" "wmis\t" "nmis\t" "dt\t" "rev\t" "seq\n" |
---|
312 | "ARB_2CA9F764\t" "0\t" "0\t" "24\t" "1\t" "1.1\t" "0\t" "0\t" "0\t" "GAUCAAGUC-======A===-AUGGGAGCU\t" "\n" |
---|
313 | "ARB_6B04C30A\t" "10\t" "20\t" "24\t" "2\t" "2.2\t" "0\t" "0\t" "0\t" "GAUCAAGUC-======A=C=-ACGGGAGCU\t" "\n" |
---|
314 | "ARB_4C6C9E8C\t" "20\t" "170\t" "67\t" "3\t" "2.4\t" "0\t" "0\t" "0\t" "GGAUUUGUU-=g====CG==-CGGCGGACG\t" "\n" |
---|
315 | "ARB_948948A3\t" "0\t" "0\t" "81\t" "3\t" "2.8\t" "0\t" "0\t" "0\t" "ACGAGUGGC-=gA===C===-UUGGAAACG\t" "\n" |
---|
316 | "ARB_5BEE4C92\t" "0\t" "0\t" "85\t" "3\t" "3.2\t" "0\t" "0\t" "0\t" "CGGCGGGAC-=g==CU====-AACCUGCGG\t" "\n" |
---|
317 | "ARB_2180C521\t" "0\t" "0\t" "24\t" "3\t" "3.6\t" "0\t" "0\t" "0\t" "GAUCAAGUC-======Aa=C-GAUGGAAGC\t" "\n" |
---|
318 | "ARB_815E94DB\t" "0\t" "0\t" "94\t" "3\t" "3.6\t" "0\t" "0\t" "0\t" "GGACUGCCC-==Aa==A===-CUAAUACCG\t" "\n" |
---|
319 | "ARB_948948A3\t" "0\t" "0\t" "24\t" "3\t" "4\t" "0\t" "0\t" "0\t" "GAUCAAGUC-==A====a=C-AGGUCUUCG\t" "\n" |
---|
320 | "ARB_9E1D1B16\t" "0\t" "0\t" "28\t" "3\t" "4\t" "0\t" "0\t" "0\t" "GAUCAAGUC-==A====a=C-GGGAAGGGA\t" "\n" |
---|
321 | "ARB_CEB24FD3\t" "0\t" "0\t" "24\t" "3\t" "4.1\t" "0\t" "0\t" "0\t" "GAUCAAGUC-=====A=G=A-GUUCCUUCG\t" "\n" |
---|
322 | "ARB_4FCDD74F\t" "0\t" "0\t" "24\t" "3\t" "4.1\t" "0\t" "0\t" "0\t" ".AUCAAGUC-=====A=G=A-GCUUCUUCG\t" "\n" |
---|
323 | "ARB_CF69AC5C\t" "0\t" "0\t" "24\t" "3\t" "4.1\t" "0\t" "0\t" "0\t" "GAUCAAGUC-=====A=G=A-GUUCCUUCG\t" "\n" |
---|
324 | "ARB_5BEE4C92\t" "0\t" "0\t" "24\t" "3\t" "4.1\t" "0\t" "0\t" "0\t" "GAUCAAGUC-=====A=G=A-GUUUCCUUC\t" "\n" |
---|
325 | "ARB_815E94DB\t" "0\t" "0\t" "156\t" "3\t" "4.1\t" "0\t" "0\t" "0\t" "GUAGCCGUU-===GAA====-CGGCUGGAU\t" "\n" |
---|
326 | "ARB_1763CF6\t" "0\t" "0\t" "24\t" "3\t" "2.4\t" "3\t" "0\t" "0\t" "GAUCAAGUC-=======...-<more>\t" "\n" |
---|
327 | "ARB_ED8B86F\t" "0\t" "0\t" "28\t" "3\t" "2.4\t" "3\t" "0\t" "0\t" "GAUCAAGUC-=======...-<more>\t" "\n" |
---|
328 | ); |
---|
329 | } |
---|
330 | |
---|
331 | #define IN_DB "tools/dnarates.arb" |
---|
332 | #define OUT_DB "tools/dnarates_result.arb" |
---|
333 | #define WANTED_DB "tools/dnarates_expected.arb" |
---|
334 | |
---|
335 | // #define TEST_AUTO_UPDATE_SAI // uncomment to auto-update expected SAI |
---|
336 | |
---|
337 | void TEST_SLOW_arb_dna_rates() { |
---|
338 | TEST_STDOUT_CONTAINS("arb_dnarates tools/dnarates.inp " IN_DB " " OUT_DB, "\nWriting 'POS_VAR_BY_ML_1'\n"); |
---|
339 | |
---|
340 | #if defined(TEST_AUTO_UPDATE_SAI) |
---|
341 | TEST_COPY_FILE(OUT_DB, WANTED_DB); |
---|
342 | #else // !defined(TEST_AUTO_UPDATE_SAI) |
---|
343 | TEST_EXPECT_TEXTFILES_EQUAL(WANTED_DB, OUT_DB); |
---|
344 | #endif |
---|
345 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(OUT_DB)); |
---|
346 | } |
---|
347 | |
---|
348 | #define RATES_DB "tools/exportrates.arb" |
---|
349 | |
---|
350 | void TEST_arb_export_rates() { |
---|
351 | // Note: just testing against regression here. |
---|
352 | // Since the output is quite longish, we just test the checksums of the results. |
---|
353 | // |
---|
354 | // If one of the checksums changes unexpectedly and you want to see more details about the change, |
---|
355 | // - go back to a revision with a correct checksum, |
---|
356 | // - add passing TEST_OUTPUT_EQUALS for broken command and |
---|
357 | // - move that test to broken revision. |
---|
358 | |
---|
359 | TEST_OUTPUT_HAS_CHECKSUM("arb_export_rates -d " RATES_DB " POS_VAR_BY_PARSIMONY", 0xc75a5fad); |
---|
360 | TEST_OUTPUT_HAS_CHECKSUM("arb_export_rates -d " RATES_DB " -r POS_VAR_BY_PARSIMONY", 0xd69fb01e); |
---|
361 | TEST_OUTPUT_HAS_CHECKSUM("arb_export_rates -d " RATES_DB " -r \"\"", 0xad0461ce); |
---|
362 | } |
---|
363 | |
---|
364 | #define TREE_DB "tools/tree.arb" |
---|
365 | |
---|
366 | void TEST_arb_export_tree() { |
---|
367 | TEST_STDOUT_EQUALS("arb_export_tree tree_mini " TREE_DB, |
---|
368 | "((( 'VibFurni' :0.02952, 'VibVulni' :0.01880):0.04015, 'VibChole' :0.03760):1.00000,( 'AcnPleur' :0.12011, 'PrtVulga' :0.06756):1.00000, 'HlmHalod' :1.00000);\n"); |
---|
369 | TEST_STDOUT_EQUALS("arb_export_tree --bifurcated tree_mini " TREE_DB, |
---|
370 | "(((( 'VibFurni' :0.02952, 'VibVulni' :0.01880):0.04015, 'VibChole' :0.03760):0.04610,( 'AcnPleur' :0.12011, 'PrtVulga' :0.06756):0.01732):0.07176, 'HlmHalod' :0.12399)'inner';\n"); |
---|
371 | TEST_STDOUT_EQUALS("arb_export_tree --doublequotes tree_mini " TREE_DB, |
---|
372 | "((( \"VibFurni\" :0.02952, \"VibVulni\" :0.01880):0.04015, \"VibChole\" :0.03760):1.00000,( \"AcnPleur\" :0.12011, \"PrtVulga\" :0.06756):1.00000, \"HlmHalod\" :1.00000);\n"); |
---|
373 | |
---|
374 | TEST_STDOUT_EQUALS("arb_export_tree --nobranchlens tree_mini " TREE_DB, |
---|
375 | "((( 'VibFurni' 'VibVulni' ) 'VibChole' ),( 'AcnPleur' 'PrtVulga' ), 'HlmHalod' );\n"); |
---|
376 | TEST_EXPECT__BROKEN(0); // the test above returns a wrong result (commas are missing) |
---|
377 | |
---|
378 | TEST_OUTPUT_EQUALS("arb_export_tree \"\" " TREE_DB, |
---|
379 | ";\n", // shall export an empty newick tree |
---|
380 | ""); // without error! |
---|
381 | TEST_OUTPUT_EQUALS("arb_export_tree tree_nosuch " TREE_DB, |
---|
382 | ";\n", // shall export an empty newick tree |
---|
383 | "arb_export_tree from '" TREE_DB "': ARB ERROR: Failed to read tree 'tree_nosuch' (Reason: tree not found)\n"); // with error! |
---|
384 | } |
---|
385 | TEST_PUBLISH(TEST_arb_export_tree); |
---|
386 | |
---|
387 | static char *notification_result = NULL; |
---|
388 | static void test_notification_cb(const char *message, void *cd) { |
---|
389 | const char *cds = (const char *)cd; |
---|
390 | notification_result = GBS_global_string_copy("message='%s' cd='%s'", message, cds); |
---|
391 | } |
---|
392 | |
---|
393 | #define INIT_NOTIFICATION \ |
---|
394 | GB_shell shell; \ |
---|
395 | GBDATA *gb_main = GBT_open("nosuch.arb", "crw"); \ |
---|
396 | const char *cd = "some argument"; \ |
---|
397 | char *cmd = GB_generate_notification(gb_main, test_notification_cb, "the note", (void*)cd) |
---|
398 | |
---|
399 | #define EXIT_NOTIFICATION \ |
---|
400 | GB_close(gb_main); \ |
---|
401 | free(cmd) |
---|
402 | |
---|
403 | #define TEST_DBSERVER_OPEN(gbmain) TEST_EXPECT_NO_ERROR(GBCMS_open(":", 0, gbmain)) |
---|
404 | #define TEST_DBSERVER_SERVE_UNTIL(gbmain, cond) do { \ |
---|
405 | bool success = GBCMS_accept_calls(gb_main, false); \ |
---|
406 | while (success) success = GBCMS_accept_calls(gb_main, true); \ |
---|
407 | GB_sleep(10, MS); \ |
---|
408 | } while(!(cond)) |
---|
409 | |
---|
410 | #define TEST_DBSERVER_CLOSE(gbmain) GBCMS_shutdown(gb_main) |
---|
411 | |
---|
412 | void TEST_close_with_pending_notification() { |
---|
413 | INIT_NOTIFICATION; |
---|
414 | EXIT_NOTIFICATION; |
---|
415 | } |
---|
416 | void TEST_close_after_pending_notification_removed() { |
---|
417 | INIT_NOTIFICATION; |
---|
418 | TEST_EXPECT_NO_ERROR(GB_remove_last_notification(gb_main)); |
---|
419 | EXIT_NOTIFICATION; |
---|
420 | } |
---|
421 | void TEST_arb_notify() { |
---|
422 | INIT_NOTIFICATION; |
---|
423 | |
---|
424 | TEST_DBSERVER_OPEN(gb_main); |
---|
425 | |
---|
426 | TEST_EXPECT_NULL(notification_result); |
---|
427 | TEST_EXPECT_NO_ERROR(GBK_system(GBS_global_string("%s &", cmd))); // async call to arb_notify |
---|
428 | |
---|
429 | TEST_DBSERVER_SERVE_UNTIL(gb_main, notification_result); |
---|
430 | TEST_DBSERVER_CLOSE(gb_main); |
---|
431 | |
---|
432 | TEST_EXPECT_EQUAL(notification_result, "message='the note' cd='some argument'"); |
---|
433 | freenull(notification_result); |
---|
434 | |
---|
435 | EXIT_NOTIFICATION; |
---|
436 | } |
---|
437 | |
---|
438 | // -------------------------------------------------------------------------------- |
---|
439 | |
---|
440 | // #define TEST_AUTO_UPDATE_EXP_SEQ // uncomment to auto-update expected sequence exports |
---|
441 | |
---|
442 | #define EXPECTED(file) file ".expected" |
---|
443 | #if defined(TEST_AUTO_UPDATE_EXP_SEQ) |
---|
444 | #define UPDATE_OR_COMPARE(outfile) TEST_COPY_FILE(outfile, EXPECTED(outfile)) |
---|
445 | #else // !defined(TEST_AUTO_UPDATE_EXP_SEQ) |
---|
446 | #define UPDATE_OR_COMPARE(outfile) TEST_EXPECT_TEXTFILES_EQUAL(outfile, EXPECTED(outfile)) |
---|
447 | #endif |
---|
448 | #define TEST_OUTFILE_EXPECTED(outfile) do{ \ |
---|
449 | UPDATE_OR_COMPARE(outfile); \ |
---|
450 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(outfile)); \ |
---|
451 | }while(0) |
---|
452 | |
---|
453 | #define SEQ_DB "TEST_loadsave.arb" |
---|
454 | #define TEMPLATE_DB "tools/min_template.arb" |
---|
455 | #define EFT "../../lib/export/fasta_wide.eft" // ../lib/export/fasta_wide.eft |
---|
456 | #define EXSEQ_EFT "tools/exseq_via_eft.fasta" |
---|
457 | #define EXSEQ_FASTA "tools/exseq.fasta" |
---|
458 | #define EXSEQ_ARB "tools/exseq.arb" |
---|
459 | #define EXSEQ_ARB_ASCII "tools/exseq_ascii.arb" |
---|
460 | #define EXSEQ_RESTRICT "tools/acc.list" |
---|
461 | |
---|
462 | void TEST_arb_export_sequences() { |
---|
463 | TEST_RUN_TOOL("arb_export_sequences --source " SEQ_DB " --format FASTA --dest " EXSEQ_FASTA); |
---|
464 | TEST_OUTFILE_EXPECTED(EXSEQ_FASTA); |
---|
465 | |
---|
466 | TEST_RUN_TOOL("arb_export_sequences --source " SEQ_DB " --format " EFT " --dest " EXSEQ_EFT " --accs " EXSEQ_RESTRICT); |
---|
467 | TEST_OUTFILE_EXPECTED(EXSEQ_EFT); |
---|
468 | |
---|
469 | TEST_RUN_TOOL("arb_export_sequences --source " SEQ_DB " --format ARB --dest " EXSEQ_ARB " --arb-template " TEMPLATE_DB |
---|
470 | " && " |
---|
471 | "arb_2_ascii " EXSEQ_ARB " " EXSEQ_ARB_ASCII |
---|
472 | ); |
---|
473 | TEST_OUTFILE_EXPECTED(EXSEQ_ARB_ASCII); |
---|
474 | TEST_EXPECT_ZERO_OR_SHOW_ERRNO(GB_unlink(EXSEQ_ARB)); |
---|
475 | } |
---|
476 | |
---|
477 | |
---|
478 | #endif // UNIT_TESTS |
---|
479 | |
---|