Start tests to ensure consistent output across implementations

This commit is contained in:
southerntofu 2020-11-27 18:52:13 +01:00
parent 4dd2e49d07
commit 79c0f8e53d
1 changed files with 116 additions and 0 deletions

116
tests/output.bats Executable file
View File

@ -0,0 +1,116 @@
#! /usr/bin/env bats
# This is a test file for use with the bats testing framework
# https://github.com/bats-core/bats-core
# On Debian: apt install bats
# output.bats tests that output is uniform across forgebuild implementations,
# by using the special value "NONE" as LANG environment variable when calling
# forgebuild.
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
# Setup settings
mkdir $FORGEBUILDDIR/config
echo "default" > $FORGEBUILDDIR/config/entry
mkdir $FORGEBUILDDIR/$HOSTNAME
echo "host" > $FORGEBUILDDIR/$HOSTNAME/entry
# Disable translations
export LANG="NONE"
}
function teardown {
cd $ORIGDIR
clean
}
function clean {
if [ -d $TMPDIR ]; then rm -rf $TMPDIR; fi
}
# Emulate translation, without actual escape codes (colors),
# variable substitution, or actual translations
warn() {
echo "warning${1}"
}
info() {
if [[ "$LOG" = "info" ]] || [[ "$LOG" = "debug" ]] || [[ "$LOG" = "" ]]; then
echo "[git-build] ${1}"
fi
}
debug() {
[[ "$LOG" = "debug" ]] && echo "debug${1}"
}
error() {
echo "error${1}"
}
# Simple repository
@test "missing basedir" {
run $FORGEBUILD -b /tmp/THISPATHDOESNOTEXIST
[ "$output" = "$(error missing_basedir)" ]
}
@test "unknown task" {
run $FORGEBUILD -b $FORGEBUILDDIR THISTASKDOESNOTEXIST
[ "$output" = "$(error unknown_arg)" ]
}
@test "unknown argument" {
run $FORGEBUILD -WTF -b $FORGEBUILDDIR
[ "$output" = "$(error unknown_arg)" ]
}
@test "clone failed" {
echo "/tmp/THISPATHDOESNOTEXIST" > $FORGEBUILDDIR/time.source
run $FORGEBUILD -b $FORGEBUILDDIR time
[ "${lines[0]}" = "$(info config)" ]
[ "${lines[1]}" = "$(info process)" ]
[ "${lines[2]}" = "$(info clone)" ]
[ "${lines[3]}" = "$(error clone_failed)" ]
}
@test "simple sourceless run" {
run $FORGEBUILD -b $FORGEBUILDDIR time
[ "${lines[0]}" = "$(info config)" ]
[ "${lines[1]}" = "$(info process)" ]
[ "${lines[2]}" = "$(info run)" ]
}
@test "no tasks requested" {
run $FORGEBUILD -b $FORGEBUILDDIR
[ "${lines[0]}" = "$(info no_task)" ]
[ "${lines[1]}" = "$(info config)" ]
[ "${lines[2]}" = "$(info process)" ]
[ "${lines[3]}" = "$(info run)" ]
[ "${lines[4]}" = "$(info process)" ]
[ "${lines[5]}" = "$(info run)" ]
}
@test "no tasks exist" {
rm -r $FORGEBUILDDIR/*
run $FORGEBUILD -b $FORGEBUILDDIR
echo $output
[ "${lines[0]}" = "$(info no_task)" ]
[ "${lines[1]}" = "$(info config)" ]
# TODO: maybe introduce a "nothing to do" message here?
}