Branch data Line data Source code
1 : : /*
2 : : * Copyright (C) 2010, 2012 Joel Rosdahl
3 : : *
4 : : * This program is free software; you can redistribute it and/or modify it
5 : : * under the terms of the GNU General Public License as published by the Free
6 : : * Software Foundation; either version 3 of the License, or (at your option)
7 : : * any later version.
8 : : *
9 : : * This program is distributed in the hope that it will be useful, but WITHOUT
10 : : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 : : * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 : : * more details.
13 : : *
14 : : * You should have received a copy of the GNU General Public License along with
15 : : * this program; if not, write to the Free Software Foundation, Inc., 51
16 : : * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 : : */
18 : :
19 : : /*
20 : : * This file contains tests for functions in hashutil.c.
21 : : */
22 : :
23 : : #include "ccache.h"
24 : : #include "hashutil.h"
25 : : #include "test/framework.h"
26 : : #include "test/util.h"
27 : :
28 : 1 : TEST_SUITE(hashutil)
29 : :
30 [ + - ]: 1 : TEST(hash_command_output_simple)
31 : : {
32 : : struct mdfour h1, h2;
33 : 1 : hash_start(&h1);
34 : 1 : hash_start(&h2);
35 [ + - ]: 1 : CHECK(hash_command_output(&h1, "echo", "not used"));
36 [ + - ]: 1 : CHECK(hash_command_output(&h2, "echo", "not used"));
37 [ + - ]: 1 : CHECK(hash_equal(&h1, &h2));
38 : : }
39 : :
40 [ + - ]: 1 : TEST(hash_command_output_space_removal)
41 : : {
42 : : struct mdfour h1, h2;
43 : 1 : hash_start(&h1);
44 : 1 : hash_start(&h2);
45 [ + - ]: 1 : CHECK(hash_command_output(&h1, "echo", "not used"));
46 [ + - ]: 1 : CHECK(hash_command_output(&h2, " echo ", "not used"));
47 [ + - ]: 1 : CHECK(hash_equal(&h1, &h2));
48 : : }
49 : :
50 [ + - ]: 1 : TEST(hash_command_output_hash_inequality)
51 : : {
52 : : struct mdfour h1, h2;
53 : 1 : hash_start(&h1);
54 : 1 : hash_start(&h2);
55 [ + - ]: 1 : CHECK(hash_command_output(&h1, "echo foo", "not used"));
56 [ + - ]: 1 : CHECK(hash_command_output(&h2, "echo bar", "not used"));
57 [ + - ]: 1 : CHECK(!hash_equal(&h1, &h2));
58 : : }
59 : :
60 [ + - ]: 1 : TEST(hash_command_output_compiler_substitution)
61 : : {
62 : : struct mdfour h1, h2;
63 : 1 : hash_start(&h1);
64 : 1 : hash_start(&h2);
65 [ + - ]: 1 : CHECK(hash_command_output(&h1, "echo foo", "not used"));
66 [ + - ]: 1 : CHECK(hash_command_output(&h2, "%compiler% foo", "echo"));
67 [ + - ]: 1 : CHECK(hash_equal(&h1, &h2));
68 : : }
69 : :
70 [ + - ]: 1 : TEST(hash_command_output_stdout_versus_stderr)
71 : : {
72 : : struct mdfour h1, h2;
73 : 1 : hash_start(&h1);
74 : 1 : hash_start(&h2);
75 : 1 : create_file("stderr.sh", "#!/bin/sh\necho foo >&2\n");
76 : 1 : chmod("stderr.sh", 0555);
77 [ + - ]: 1 : CHECK(hash_command_output(&h1, "echo foo", "not used"));
78 [ + - ]: 1 : CHECK(hash_command_output(&h2, "./stderr.sh", "not used"));
79 [ + - ]: 1 : CHECK(hash_equal(&h1, &h2));
80 : : }
81 : :
82 [ + - ]: 1 : TEST(hash_multicommand_output)
83 : : {
84 : : struct mdfour h1, h2;
85 : 1 : hash_start(&h1);
86 : 1 : hash_start(&h2);
87 : 1 : create_file("foo.sh", "#!/bin/sh\necho foo\necho bar\n");
88 : 1 : chmod("foo.sh", 0555);
89 [ + - ]: 1 : CHECK(hash_multicommand_output(&h2, "echo foo; echo bar", "not used"));
90 [ + - ]: 1 : CHECK(hash_multicommand_output(&h1, "./foo.sh", "not used"));
91 [ + - ]: 1 : CHECK(hash_equal(&h1, &h2));
92 : : }
93 : :
94 [ + - ]: 1 : TEST(hash_multicommand_output_error_handling)
95 : : {
96 : : struct mdfour h1, h2;
97 : 1 : hash_start(&h1);
98 : 1 : hash_start(&h2);
99 [ + - ]: 1 : CHECK(!hash_multicommand_output(&h2, "false; true", "not used"));
100 : : }
101 : :
102 [ + - ]: 1 : TEST(check_for_temporal_macros)
103 : : {
104 : : const char time_start[] =
105 : : "__TIME__\n"
106 : 1 : "int a;\n";
107 : : const char time_middle[] =
108 : : "#define a __TIME__\n"
109 : 1 : "int a;\n";
110 : : const char time_end[] =
111 : 1 : "#define a __TIME__";
112 : :
113 : : const char date_start[] =
114 : : "__DATE__\n"
115 : 1 : "int ab;\n";
116 : : const char date_middle[] =
117 : : "#define ab __DATE__\n"
118 : 1 : "int ab;\n";
119 : : const char date_end[] =
120 : 1 : "#define ab __DATE__";
121 : :
122 : : const char no_temporal[] =
123 : : "#define ab _ _DATE__\n"
124 : : "#define ab __ DATE__\n"
125 : : "#define ab __D ATE__\n"
126 : : "#define ab __DA TE__\n"
127 : : "#define ab __DAT E__\n"
128 : : "#define ab __DATE __\n"
129 : : "#define ab __DATE_ _\n"
130 : : "#define ab _ _TIME__\n"
131 : : "#define ab __ TIME__\n"
132 : : "#define ab __T IME__\n"
133 : : "#define ab __TI ME__\n"
134 : : "#define ab __TIM E__\n"
135 : : "#define ab __TIME __\n"
136 : 1 : "#define ab __TIME_ _\n";
137 : :
138 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_start + 0, sizeof(time_start) - 0));
139 [ + - ]: 1 : CHECK(!check_for_temporal_macros(time_start + 1, sizeof(time_start) - 1));
140 : :
141 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_middle + 0, sizeof(time_middle) - 0));
142 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_middle + 1, sizeof(time_middle) - 1));
143 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_middle + 2, sizeof(time_middle) - 2));
144 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_middle + 3, sizeof(time_middle) - 3));
145 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_middle + 4, sizeof(time_middle) - 4));
146 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_middle + 5, sizeof(time_middle) - 5));
147 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_middle + 6, sizeof(time_middle) - 6));
148 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_middle + 7, sizeof(time_middle) - 7));
149 : :
150 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_end + 0, sizeof(time_end) - 0));
151 [ + - ]: 1 : CHECK(check_for_temporal_macros(time_end + sizeof(time_end) - 9, 9));
152 [ + - ]: 1 : CHECK(!check_for_temporal_macros(time_end + sizeof(time_end) - 8, 8));
153 : :
154 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_start + 0, sizeof(date_start) - 0));
155 [ + - ]: 1 : CHECK(!check_for_temporal_macros(date_start + 1, sizeof(date_start) - 1));
156 : :
157 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_middle + 0, sizeof(date_middle) - 0));
158 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_middle + 1, sizeof(date_middle) - 1));
159 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_middle + 2, sizeof(date_middle) - 2));
160 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_middle + 3, sizeof(date_middle) - 3));
161 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_middle + 4, sizeof(date_middle) - 4));
162 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_middle + 5, sizeof(date_middle) - 5));
163 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_middle + 6, sizeof(date_middle) - 6));
164 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_middle + 7, sizeof(date_middle) - 7));
165 : :
166 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_end + 0, sizeof(date_end) - 0));
167 [ + - ]: 1 : CHECK(check_for_temporal_macros(date_end + sizeof(date_end) - 9, 9));
168 [ + - ]: 1 : CHECK(!check_for_temporal_macros(date_end + sizeof(date_end) - 8, 8));
169 : :
170 [ + - ]: 1 : CHECK(!check_for_temporal_macros(no_temporal + 0, sizeof(no_temporal) - 0));
171 [ + - ]: 1 : CHECK(!check_for_temporal_macros(no_temporal + 1, sizeof(no_temporal) - 1));
172 [ + - ]: 1 : CHECK(!check_for_temporal_macros(no_temporal + 2, sizeof(no_temporal) - 2));
173 [ + - ]: 1 : CHECK(!check_for_temporal_macros(no_temporal + 3, sizeof(no_temporal) - 3));
174 [ + - ]: 1 : CHECK(!check_for_temporal_macros(no_temporal + 4, sizeof(no_temporal) - 4));
175 [ + - ]: 1 : CHECK(!check_for_temporal_macros(no_temporal + 5, sizeof(no_temporal) - 5));
176 [ + - ]: 1 : CHECK(!check_for_temporal_macros(no_temporal + 6, sizeof(no_temporal) - 6));
177 [ + - ]: 1 : CHECK(!check_for_temporal_macros(no_temporal + 7, sizeof(no_temporal) - 7));
178 : : }
179 : :
180 : 1 : TEST_SUITE_END
|