resetting manifest requested domain to floor
[platform/upstream/ccache.git] / test / test_hashutil.c
1 /*
2  * Copyright (C) 2010 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 TEST_SUITE(hashutil)
29
30 TEST(hash_command_output_simple)
31 {
32         struct mdfour h1, h2;
33         hash_start(&h1);
34         hash_start(&h2);
35         CHECK(hash_command_output(&h1, "echo", "not used"));
36         CHECK(hash_command_output(&h2, "echo", "not used"));
37         CHECK(hash_equal(&h1, &h2));
38 }
39
40 TEST(hash_command_output_space_removal)
41 {
42         struct mdfour h1, h2;
43         hash_start(&h1);
44         hash_start(&h2);
45         CHECK(hash_command_output(&h1, "echo", "not used"));
46         CHECK(hash_command_output(&h2, " echo ", "not used"));
47         CHECK(hash_equal(&h1, &h2));
48 }
49
50 TEST(hash_command_output_hash_inequality)
51 {
52         struct mdfour h1, h2;
53         hash_start(&h1);
54         hash_start(&h2);
55         CHECK(hash_command_output(&h1, "echo foo", "not used"));
56         CHECK(hash_command_output(&h2, "echo bar", "not used"));
57         CHECK(!hash_equal(&h1, &h2));
58 }
59
60 TEST(hash_command_output_compiler_substitution)
61 {
62         struct mdfour h1, h2;
63         hash_start(&h1);
64         hash_start(&h2);
65         CHECK(hash_command_output(&h1, "echo foo", "not used"));
66         CHECK(hash_command_output(&h2, "%compiler% foo", "echo"));
67         CHECK(hash_equal(&h1, &h2));
68 }
69
70 TEST(hash_command_output_stdout_versus_stderr)
71 {
72         struct mdfour h1, h2;
73         hash_start(&h1);
74         hash_start(&h2);
75         create_file("stderr.sh", "#!/bin/sh\necho foo >&2\n");
76         chmod("stderr.sh", 0555);
77         CHECK(hash_command_output(&h1, "echo foo", "not used"));
78         CHECK(hash_command_output(&h2, "./stderr.sh", "not used"));
79         CHECK(hash_equal(&h1, &h2));
80 }
81
82 TEST(hash_multicommand_output)
83 {
84         struct mdfour h1, h2;
85         hash_start(&h1);
86         hash_start(&h2);
87         create_file("foo.sh", "#!/bin/sh\necho foo\necho bar\n");
88         chmod("foo.sh", 0555);
89         CHECK(hash_multicommand_output(&h2, "echo foo; echo bar", "not used"));
90         CHECK(hash_multicommand_output(&h1, "./foo.sh", "not used"));
91         CHECK(hash_equal(&h1, &h2));
92 }
93
94 TEST(hash_multicommand_output_error_handling)
95 {
96         struct mdfour h1, h2;
97         hash_start(&h1);
98         hash_start(&h2);
99         CHECK(!hash_multicommand_output(&h2, "false; true", "not used"));
100 }
101
102 TEST_SUITE_END