-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.sh
executable file
·82 lines (69 loc) · 2.2 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
# A script to test the cmake dependency make generation framework using this simple test case
set -e
mkdir -p build
cd build
cmake ..
source_path=../
missing_expected_content=
contains_unexpected_content=
# Parameter 1: The file to check for content
# Parameter 2: The content to look for in the file
# Append missing_expected_content with the content missing from the file
expect_file_contains()
{
local file=$1
local content=$2
grep $content $file > /dev/null
if [ $? -ne 0 ]; then
echo "expected file to contain ${content} but did not find in the file"
missing_expected_content="$missing_expected_content:$content"
fi
}
# Parameter 1: The file to check for content
# Parameter 2: The content to look for in the file
# Append contains_unexpected_content with the content missing from the file
expect_file_does_not_contain()
{
local file=$1
local content=$2
grep $content $file > /dev/null
if [ $? -eq 0 ]; then
echo "ERROR!!! expected file should not contain ${content} but found in the file"
contains_unexpected_content="$contains_unexpected_content:$content"
fi
}
cd `dirname $0`
make_output_file=`mktemp`
# Get the make up to date with latest source
set -e
make clean > /dev/null
make > /dev/null
set +e
touch ${source_path}file1.h
make > $make_output_file 2>&1
echo make output after touching file1.h was:
cat $make_output_file
expect_file_contains $make_output_file 'file1.c'
expect_file_contains $make_output_file 'main.c'
expect_file_does_not_contain $make_output_file 'file2.c'
touch ${source_path}file2.h
make > $make_output_file 2>&1
echo make output after touching file2.h was:
cat $make_output_file
expect_file_contains $make_output_file 'file2.c'
expect_file_contains $make_output_file 'main.c'
expect_file_does_not_contain $make_output_file 'file1.c'
touch ${source_path}main.c
make > $make_output_file 2>&1
echo make output after touching main.c was:
cat $make_output_file
expect_file_contains $make_output_file 'main.c'
expect_file_does_not_contain $make_output_file 'file2.c'
expect_file_does_not_contain $make_output_file 'file1.c'
rm $make_output_file
if [ -n "$missing_expected_content" ] || [ -n "$contains_unexpected_content" ]; then
echo "At least one test failed"
exit 1
fi
exit 0