#! /usr/bin/env bats # 21-task-env.bats # In here, we ensure that the environment variables passed to the task, # as well as its working directory, are as expected. A task should have: # $FORGEBUILDDIR: the basedir for the current tests # $FORGEBUILD: the current implementation of forgebuild running # Also, a task's should by default have the basedir as working directory. # This is not true for tasks with a source, and corresponding tests # are located in specific DVCS tests. # Additionally, tasks may receive a $FORGEBUILDCONF variable, which is # described and tested for in 20-host-config.bats. # Finally, we ensure running a task does not have the unintended # consequence of changing the current working directory. function setup { ORIGDIR="$(pwd)" TMPDIR="$(mktemp -d)" # If no $FORGEBUILD is supplied in ENV, use the default # (otherwise you can't `bats ./tests/` manually) [ -z "$FORGEBUILD" ] && FORGEBUILD="forgebuild" # Setup forgebuild tasks FORGEBUILDDIR="$TMPDIR"/forgebuild mkdir $FORGEBUILDDIR echo "date +%s%N > $TMPDIR/forgebuild-time" > $FORGEBUILDDIR/time chmod +x $FORGEBUILDDIR/time echo "echo \$(pwd) > $TMPDIR/forgebuild-pwd" > $FORGEBUILDDIR/pwd chmod +x $FORGEBUILDDIR/pwd } function teardown { cd $ORIGDIR if [ -d $TMPDIR ]; then rm -rf $TMPDIR; fi } @test "sourceless task working dir is FORGEBUILDDIR" { $FORGEBUILD -b $FORGEBUILDDIR pwd PWD="$(cat $TMPDIR/forgebuild-pwd)" cp $TMPDIR/forgebuild-pwd{,-2} [[ "$PWD" = "$FORGEBUILDDIR" ]] } @test "after running, back to the previous working dir" { cd /tmp $FORGEBUILD -b $FORGEBUILDDIR pwd [[ "$(pwd)" = "/tmp" ]] }