1#!/bin/bash
2
3# Go to srcdir
4cd $(dirname ${BASH_SOURCE[0]})/..
5
6rm -rf out.test
7mkdir out.test
8cd out.test
9../bootstrap.bash
10
11# Run ninja, filter the output, and compare against expectations
12# $1: Name of test
13function testcase()
14{
15  echo -n "Running $1..."
16  if ! ninja -v -d explain >log_$1 2>&1; then
17    echo " Failed."
18    echo "Test $1 Failed:" >>failed
19    tail log_$1 >>failed
20    return
21  fi
22  grep -E "^(Choosing|Newer|Stage)" log_$1 >test_$1
23  if ! cmp -s test_$1 ../tests/expected_$1; then
24    echo " Failed."
25    echo "Test $1 Failed:" >>failed
26    diff -u ../tests/expected_$1 test_$1 >>failed
27  else
28    echo " Passed."
29  fi
30}
31
32# Run wrapper, filter the output, and compare against expectations
33# $1: Name of test
34function testcase_wrapper()
35{
36  echo -n "Running wrapper_$1..."
37  if ! ./blueprint.bash -v -d explain >log_wrapper_$1 2>&1; then
38    echo " Failed."
39    echo "Test wrapper_$1 Failed:" >>failed
40    tail log_wrapper_$1 >>failed
41    return
42  fi
43  grep -E "^(Choosing|Newer|Stage)" log_wrapper_$1 >test_wrapper_$1
44  if ! cmp -s test_wrapper_$1 ../tests/expected_wrapper_$1; then
45    echo " Failed."
46    echo "Test wrapper_$1 Failed:" >>failed
47    diff -u ../tests/expected_wrapper_$1 test_wrapper_$1 >>failed
48  else
49    echo " Passed."
50  fi
51}
52
53
54testcase start
55
56# The 2 second sleeps are needed until ninja understands sub-second timestamps
57# https://github.com/martine/ninja/issues/371
58
59# This test affects all bootstrap stages
60sleep 2
61touch ../Blueprints
62testcase all
63
64# This test affects only the primary bootstrap stage
65sleep 2
66touch ../bpmodify/bpmodify.go
67testcase primary
68
69# This test affects nothing, nothing should be done
70sleep 2
71testcase none
72
73# This test will cause the source build.ninja.in to be copied into the first
74# stage.
75sleep 2
76touch ../build.ninja.in
77testcase manifest
78
79# From now on, we're going to be modifying the build.ninja.in, so let's make our
80# own copy
81sleep 2
82../tests/bootstrap.bash -r
83
84sleep 2
85testcase start2
86
87# This is similar to the last test, but incorporates a change into the source
88# build.ninja.in, so that we'll restart into the new version created by the
89# build.
90sleep 2
91echo "# test" >>src.build.ninja.in
92testcase regen
93
94# Add tests to our build by using '-t'
95sleep 2
96../tests/bootstrap.bash -r -t
97
98sleep 2
99testcase start_add_tests
100
101# Make sure that updating a test file causes us to go back to the bootstrap
102# stage
103sleep 2
104touch ../parser/parser_test.go
105testcase rebuild_test
106
107# Restart testing using the wrapper instead of going straight to ninja. This
108# will force each test to start in the correct bootstrap stage, so there are
109# less cases to test.
110cd ..
111rm -rf out.test
112mkdir -p out.test
113cd out.test
114../bootstrap.bash
115
116testcase_wrapper start
117
118# This test affects all bootstrap stages
119sleep 2
120touch ../Blueprints
121testcase_wrapper all
122
123# From now on, we're going to be modifying the build.ninja.in, so let's make our
124# own copy
125sleep 2
126../tests/bootstrap.bash -r
127
128sleep 2
129testcase_wrapper start2
130
131# This is similar to the last test, but incorporates a change into the source
132# build.ninja.in, so that we'll restart into the new version created by the
133# build.
134sleep 2
135echo "# test" >>src.build.ninja.in
136testcase_wrapper regen
137
138if [ -f failed ]; then
139  cat failed
140  exit 1
141fi
142