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