Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : 28 : static Return assert_information_mode_output(
4 : : const char *arguments,
5 : : const char *stdout_pattern_file)
6 : : {
7 : 28 : INITTEST;
8 : :
9 : 28 : create(char,stdout_result);
10 : 28 : create(char,stderr_result);
11 : 28 : create(char,stdout_pattern);
12 : 28 : create(char,stderr_pattern);
13 : :
14 [ + - + - ]: 28 : ASSERT(arguments != NULL);
15 [ + - + - ]: 28 : ASSERT(stdout_pattern_file != NULL);
16 : :
17 [ + - + - ]: 28 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
18 : :
19 [ + - + - ]: 28 : ASSERT(SUCCESS == runit(arguments,stdout_result,stderr_result,COMPLETED,STDERR_ALLOW));
20 : :
21 [ + - + - ]: 28 : ASSERT(SUCCESS == get_file_content(stdout_pattern_file,stdout_pattern));
22 [ + - + - ]: 28 : ASSERT(SUCCESS == match_pattern(stdout_result,stdout_pattern,stdout_pattern_file));
23 : :
24 [ + - + - ]: 28 : ASSERT(SUCCESS == copy_literal(stderr_pattern,"\\A\\Z"));
25 [ + - + - ]: 28 : ASSERT(SUCCESS == match_pattern(stderr_result,stderr_pattern));
26 : :
27 [ - + - + ]: 28 : call(del(stderr_pattern));
28 [ - + - + ]: 28 : call(del(stdout_pattern));
29 [ - + - + ]: 28 : call(del(stderr_result));
30 [ - + - + ]: 28 : call(del(stdout_result));
31 : :
32 : 28 : return(status);
33 : : }
34 : :
35 : : /**
36 : : *
37 : : * Check the name of the database created by default.
38 : : * Does it really comply with to the "hostname.db" template
39 : : *
40 : : */
41 : 2 : Return test0003_1(void)
42 : : {
43 : 2 : INITTEST;
44 : :
45 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
46 : :
47 : 2 : const char *arguments = "--progress tests/fixtures/diffs/diff1";
48 : :
49 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
50 : :
51 : 2 : arguments = "--progress --database=database2.db "
52 : : "tests/fixtures/diffs/diff2";
53 : :
54 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,NULL,NULL,COMPLETED,ALLOW_BOTH));
55 : :
56 : : // Get the output of the application
57 : 2 : arguments = "--compare $DBNAME database2.db";
58 : :
59 : 2 : const char *filename = "templates/0003_001.txt"; // File name
60 : 2 : const char *template = "%DB_NAME%";
61 : :
62 : 2 : const char *replacement = getenv("DBNAME"); // Database name
63 : :
64 [ + - + - ]: 2 : ASSERT(replacement != NULL);
65 : :
66 [ + - + - ]: 2 : ASSERT(SUCCESS == match_app_output(arguments,filename,template,replacement,COMPLETED));
67 : :
68 : : // Clean up test results
69 : 2 : const char *command = "rm \"${TMPDIR}/${DBNAME}\" \"${TMPDIR}/database2.db\"";
70 : :
71 [ + - + - ]: 2 : ASSERT(SUCCESS == external_call(command,NULL,NULL,COMPLETED,ALLOW_BOTH));
72 : :
73 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
74 : : }
75 : :
76 : : /**
77 : : *
78 : : * Running the application with no arguments at all
79 : : *
80 : : */
81 : 2 : Return test0003_2(void)
82 : : {
83 : 2 : INITTEST;
84 : :
85 : 2 : const char *arguments = "";
86 : :
87 : 2 : create(char,stdout_result);
88 : 2 : create(char,stderr_result);
89 : 2 : create(char,stdout_pattern);
90 : 2 : create(char,stderr_pattern);
91 : :
92 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
93 : :
94 [ + - + - ]: 2 : ASSERT(SUCCESS == runit(arguments,stdout_result,stderr_result,COMPLETED,STDERR_ALLOW));
95 : :
96 : 2 : const char *filename = "templates/0003_002.txt";
97 : :
98 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,stderr_pattern));
99 : :
100 : : // Match stderr against the pattern
101 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(stderr_result,stderr_pattern,filename));
102 : :
103 : 2 : filename = "templates/0003_003.txt";
104 : :
105 [ + - + - ]: 2 : ASSERT(SUCCESS == get_file_content(filename,stdout_pattern));
106 : :
107 : : // Match stdout against the pattern
108 [ + - + - ]: 2 : ASSERT(SUCCESS == match_pattern(stdout_result,stdout_pattern,filename));
109 : :
110 : : // Clean to use it iteratively
111 : 2 : del(stderr_pattern);
112 : 2 : del(stdout_pattern);
113 : 2 : del(stderr_result);
114 : 2 : del(stdout_result);
115 : :
116 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
117 : :
118 : : }
119 : :
120 : : /**
121 : : *
122 : : * Information modes should complete successfully without PATH
123 : : *
124 : : */
125 : 2 : Return test0003_3(void)
126 : : {
127 : 2 : INITTEST;
128 : :
129 [ + - + - ]: 2 : ASSERT(SUCCESS == set_environment_variable("TESTING","true"));
130 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--help","templates/0003_004.txt"));
131 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("-h","templates/0003_004.txt"));
132 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--usage","templates/0003_005.txt"));
133 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("-z","templates/0003_005.txt"));
134 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--version","templates/0003_006.txt"));
135 : :
136 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
137 : : }
138 : :
139 : : /**
140 : : *
141 : : * Information modes should ignore PATH and not run the main workflow
142 : : *
143 : : */
144 : 2 : Return test0003_4(void)
145 : : {
146 : 2 : INITTEST;
147 : :
148 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--help /definitely/nonexistent/path","templates/0003_004.txt"));
149 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("-h /definitely/nonexistent/path","templates/0003_004.txt"));
150 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--usage /definitely/nonexistent/path","templates/0003_005.txt"));
151 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("-z /definitely/nonexistent/path","templates/0003_005.txt"));
152 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--version /definitely/nonexistent/path","templates/0003_006.txt"));
153 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--compare --help","templates/0003_004.txt"));
154 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--compare --usage","templates/0003_005.txt"));
155 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--compare -z","templates/0003_005.txt"));
156 [ + - + - ]: 2 : ASSERT(SUCCESS == assert_information_mode_output("--compare --version","templates/0003_006.txt"));
157 : :
158 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
159 : : }
160 : :
161 : 2 : Return test0003(void)
162 : : {
163 : 2 : INITTEST;
164 : :
165 [ + - ]: 2 : TEST(test0003_1,"Comply default DB name to \"hostname.db\" template…");
166 [ + - ]: 2 : TEST(test0003_2,"Running the application with no arguments at all…");
167 [ + - ]: 2 : TEST(test0003_3,"Information modes without PATH return success…");
168 [ + - ]: 2 : TEST(test0003_4,"Information modes ignore PATH and stop early…");
169 : :
170 [ + - - + : 2 : RETURN_STATUS;
- - - + +
- ]
171 : : }
|