Home | History | Annotate | Download | only in testcase
      1 #!/bin/sh
      2 #
      3 # Copyright 2015 Google Inc. All rights reserved
      4 #
      5 # Licensed under the Apache License, Version 2.0 (the "License");
      6 # you may not use this file except in compliance with the License.
      7 # You may obtain a copy of the License at
      8 #
      9 #      http:#www.apache.org/licenses/LICENSE-2.0
     10 #
     11 # Unless required by applicable law or agreed to in writing, software
     12 # distributed under the License is distributed on an "AS IS" BASIS,
     13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
     16 
     17 set -e
     18 
     19 log=/tmp/log
     20 mk="$@"
     21 
     22 sleep_if_necessary() {
     23   if [ x$(uname) != x"Linux" -o x"${TRAVIS}" != x"" ]; then
     24     sleep "$@"
     25   fi
     26 }
     27 
     28 export VAR=hoge
     29 
     30 cat <<EOF > Makefile
     31 all:
     32 	echo foo
     33 EOF
     34 
     35 ${mk} 2> ${log}
     36 if [ -e ninja.sh ]; then
     37   ./ninja.sh
     38 fi
     39 
     40 sleep_if_necessary 1
     41 cat <<EOF > Makefile
     42 \$(KATI_deprecated_var VAR4)
     43 \$(KATI_obsolete_var VAR5)
     44 VAR3 := unused
     45 all:
     46 	echo bar
     47 	echo VAR=\$(VAR)
     48 	echo VAR2=\$(VAR2)
     49 	echo VAR3=\$(VAR3)
     50 	echo wildcard=\$(wildcard *.mk)
     51 other:
     52 	echo foo
     53 EOF
     54 
     55 ${mk} 2> ${log}
     56 if [ -e ninja.sh ]; then
     57   if ! grep regenerating ${log} > /dev/null; then
     58     echo 'Should be regenerated (Makefile)'
     59   fi
     60   ./ninja.sh
     61 fi
     62 
     63 export VAR=fuga
     64 ${mk} 2> ${log}
     65 if [ -e ninja.sh ]; then
     66   if ! grep regenerating ${log} > /dev/null; then
     67     echo 'Should be regenerated (env changed)'
     68   fi
     69   ./ninja.sh
     70 fi
     71 
     72 export VAR2=OK
     73 ${mk} 2> ${log}
     74 if [ -e ninja.sh ]; then
     75   if ! grep regenerating ${log} > /dev/null; then
     76     echo 'Should be regenerated (env added)'
     77   fi
     78   ./ninja.sh
     79 fi
     80 
     81 export VAR3=testing
     82 ${mk} 2> ${log}
     83 if [ -e ninja.sh ]; then
     84   if grep regenerating ${log} >/dev/null; then
     85     echo 'Should not regenerate (unused env added)'
     86   fi
     87   ./ninja.sh
     88 fi
     89 
     90 export VAR3=test2
     91 ${mk} 2> ${log}
     92 if [ -e ninja.sh ]; then
     93   if grep regenerating ${log} >/dev/null; then
     94     echo 'Should not regenerate (unused env changed)'
     95   fi
     96   ./ninja.sh
     97 fi
     98 
     99 export VAR4=foo
    100 ${mk} 2> ${log}
    101 if [ -e ninja.sh ]; then
    102   if grep regenerating ${log} >/dev/null; then
    103     echo 'Should not regenerate (deprecated env added)'
    104   fi
    105   ./ninja.sh
    106 fi
    107 
    108 export VAR5=foo
    109 ${mk} 2> ${log}
    110 if [ -e ninja.sh ]; then
    111   if grep regenerating ${log} >/dev/null; then
    112     echo 'Should not regenerate (obsolete env added)'
    113   fi
    114   ./ninja.sh
    115 fi
    116 
    117 export PATH=/random_path:$PATH
    118 ${mk} 2> ${log}
    119 if [ -e ninja.sh ]; then
    120   if ! grep regenerating ${log} > /dev/null; then
    121     echo 'Should be regenerated (PATH changed)'
    122   fi
    123   ./ninja.sh
    124 fi
    125 
    126 sleep_if_necessary 1
    127 touch PASS.mk
    128 ${mk} 2> ${log}
    129 if [ -e ninja.sh ]; then
    130   if ! grep regenerating ${log} > /dev/null; then
    131     echo 'Should be regenerated (wildcard)'
    132   fi
    133   ./ninja.sh
    134 fi
    135 
    136 sleep_if_necessary 1
    137 touch XXX
    138 ${mk} 2> ${log}
    139 if [ -e ninja.sh ]; then
    140   if grep regenerating ${log}; then
    141     echo 'Should not be regenerated'
    142   fi
    143   ./ninja.sh
    144 fi
    145 
    146 ${mk} other 2> ${log}
    147 if [ -e ninja.sh ]; then
    148   if ! grep regenerating ${log} >/dev/null; then
    149     echo 'Should be regenerated (argument)'
    150   fi
    151   ./ninja.sh other
    152 fi
    153