Home | History | Annotate | Download | only in tests
      1 #!/bin/bash -ex
      2 
      3 function mtime() {
      4     stat -c %Y $1
      5 }
      6 
      7 # Go to top of blueprint tree
      8 cd $(dirname ${BASH_SOURCE[0]})/..
      9 TOP=${PWD}
     10 
     11 export TEMPDIR=$(mktemp -d -t blueprint.test.XXX)
     12 
     13 function cleanup() {
     14     cd "${TOP}"
     15     echo "cleaning up ${TEMPDIR}"
     16     rm -rf "${TEMPDIR}"
     17 }
     18 trap cleanup EXIT
     19 
     20 export OUTDIR="${TEMPDIR}/out"
     21 mkdir "${OUTDIR}"
     22 
     23 export SRCDIR="${TEMPDIR}/src"
     24 cp -r tests/test_tree "${SRCDIR}"
     25 cp -r "${TOP}" "${SRCDIR}/blueprint"
     26 
     27 cd "${OUTDIR}"
     28 export BLUEPRINTDIR=${SRCDIR}/blueprint
     29 #setup
     30 ${SRCDIR}/blueprint/bootstrap.bash $@
     31 
     32 #confirm no build.ninja file is rebuilt when no change happens
     33 ./blueprint.bash
     34 
     35 OLDTIME_BOOTSTRAP=$(mtime .bootstrap/build.ninja)
     36 OLDTIME=$(mtime build.ninja)
     37 
     38 sleep 2
     39 ./blueprint.bash
     40 
     41 if [ ${OLDTIME} != $(mtime build.ninja) ]; then
     42     echo "unnecessary build.ninja regeneration for null build" >&2
     43     exit 1
     44 fi
     45 
     46 if [ ${OLDTIME_BOOTSTRAP} != $(mtime .bootstrap/build.ninja) ]; then
     47     echo "unnecessary .bootstrap/build.ninja regeneration for null build" >&2
     48     exit 1
     49 fi
     50 
     51 #confirm no build.ninja file is rebuilt when a new directory is created
     52 mkdir ${SRCDIR}/newglob
     53 
     54 sleep 2
     55 ./blueprint.bash
     56 
     57 if [ ${OLDTIME} != $(mtime build.ninja) ]; then
     58     echo "unnecessary build.ninja regeneration for new empty directory" >&2
     59     exit 1
     60 fi
     61 if [ ${OLDTIME_BOOTSTRAP} != $(mtime .bootstrap/build.ninja) ]; then
     62     echo "unnecessary .bootstrap/build.ninja regeneration for new empty directory" >&2
     63     exit 1
     64 fi
     65 
     66 #confirm that build.ninja is rebuilt when a new Blueprints file is added
     67 touch ${SRCDIR}/newglob/Blueprints
     68 
     69 sleep 2
     70 ./blueprint.bash
     71 
     72 if [ ${OLDTIME} = $(mtime build.ninja) ]; then
     73     echo "Failed to rebuild build.ninja for glob addition" >&2
     74     exit 1
     75 fi
     76 if [ ${OLDTIME_BOOTSTRAP} = $(mtime .bootstrap/build.ninja) ]; then
     77     echo "Failed to rebuild .bootstrap/build.ninja for glob addition" >&2
     78     exit 1
     79 fi
     80 
     81 #confirm that build.ninja is rebuilt when a glob match is removed
     82 OLDTIME=$(mtime build.ninja)
     83 OLDTIME_BOOTSTRAP=$(mtime .bootstrap/build.ninja)
     84 rm ${SRCDIR}/newglob/Blueprints
     85 
     86 sleep 2
     87 ./blueprint.bash
     88 
     89 if [ ${OLDTIME} = $(mtime build.ninja) ]; then
     90     echo "Failed to rebuild build.ninja for glob removal" >&2
     91     exit 1
     92 fi
     93 if [ ${OLDTIME_BOOTSTRAP} = $(mtime .bootstrap/build.ninja) ]; then
     94     echo "Failed to rebuild .bootstrap/build.ninja for glob removal" >&2
     95     exit 1
     96 fi
     97 
     98 #confirm that build.ninja is not rebuilt when a glob match is removed
     99 OLDTIME=$(mtime build.ninja)
    100 OLDTIME_BOOTSTRAP=$(mtime .bootstrap/build.ninja)
    101 rmdir ${SRCDIR}/newglob
    102 
    103 sleep 2
    104 ./blueprint.bash
    105 
    106 if [ ${OLDTIME} != $(mtime build.ninja) ]; then
    107     echo "unnecessary build.ninja regeneration for removal of empty directory" >&2
    108     exit 1
    109 fi
    110 
    111 if [ ${OLDTIME_BOOTSTRAP} != $(mtime .bootstrap/build.ninja) ]; then
    112     echo "unnecessary .bootstrap/build.ninja regeneration for removal of empty directory" >&2
    113     exit 1
    114 fi
    115 
    116 echo tests passed
    117