2 * Copyright (C) 2010 Joel Rosdahl
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)
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
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
20 * This file contains tests for functions in hashutil.c.
25 #include "test/framework.h"
26 #include "test/util.h"
30 TEST(hash_command_output_simple)
35 CHECK(hash_command_output(&h1, "echo", "not used"));
36 CHECK(hash_command_output(&h2, "echo", "not used"));
37 CHECK(hash_equal(&h1, &h2));
40 TEST(hash_command_output_space_removal)
45 CHECK(hash_command_output(&h1, "echo", "not used"));
46 CHECK(hash_command_output(&h2, " echo ", "not used"));
47 CHECK(hash_equal(&h1, &h2));
50 TEST(hash_command_output_hash_inequality)
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));
60 TEST(hash_command_output_compiler_substitution)
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));
70 TEST(hash_command_output_stdout_versus_stderr)
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));
82 TEST(hash_multicommand_output)
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));
94 TEST(hash_multicommand_output_error_handling)
99 CHECK(!hash_multicommand_output(&h2, "false; true", "not used"));