1 #!/bin/bash 2 3 # Go to srcdir 4 cd $(dirname ${BASH_SOURCE[0]})/.. 5 6 rm -rf out.test 7 mkdir out.test 8 cd out.test 9 ../bootstrap.bash 10 11 # Run ninja, filter the output, and compare against expectations 12 # $1: Name of test 13 function 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 34 function 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 54 testcase 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 60 sleep 2 61 touch ../Blueprints 62 testcase all 63 64 # This test affects only the primary bootstrap stage 65 sleep 2 66 touch ../bpmodify/bpmodify.go 67 testcase primary 68 69 # This test affects nothing, nothing should be done 70 sleep 2 71 testcase none 72 73 # This test will cause the source build.ninja.in to be copied into the first 74 # stage. 75 sleep 2 76 touch ../build.ninja.in 77 testcase manifest 78 79 # From now on, we're going to be modifying the build.ninja.in, so let's make our 80 # own copy 81 sleep 2 82 ../tests/bootstrap.bash -r 83 84 sleep 2 85 testcase 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. 90 sleep 2 91 echo "# test" >>src.build.ninja.in 92 testcase regen 93 94 # Add tests to our build by using '-t' 95 sleep 2 96 ../tests/bootstrap.bash -r -t 97 98 sleep 2 99 testcase start_add_tests 100 101 # Make sure that updating a test file causes us to go back to the bootstrap 102 # stage 103 sleep 2 104 touch ../parser/parser_test.go 105 testcase 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. 110 cd .. 111 rm -rf out.test 112 mkdir -p out.test 113 cd out.test 114 ../bootstrap.bash 115 116 testcase_wrapper start 117 118 # This test affects all bootstrap stages 119 sleep 2 120 touch ../Blueprints 121 testcase_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 125 sleep 2 126 ../tests/bootstrap.bash -r 127 128 sleep 2 129 testcase_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. 134 sleep 2 135 echo "# test" >>src.build.ninja.in 136 testcase_wrapper regen 137 138 if [ -f failed ]; then 139 cat failed 140 exit 1 141 fi 142