101 lines
2.9 KiB
Bash
Executable File
101 lines
2.9 KiB
Bash
Executable File
#! /usr/bin/env bats
|
|
|
|
# 03-log-context.bats
|
|
# The log messages may contain dynamic information about the forgebuild setup
|
|
# or the task being processed. In these tests, we check that these variables
|
|
# are substituted.
|
|
# In order to ensure that, we use a special translation file containing only
|
|
# variables to be replaced. This file is passed as LANG environment variable.
|
|
|
|
load helpers
|
|
|
|
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
|
|
|
|
# Disable translations
|
|
#export LANG="$TMPDIR/translations.json"
|
|
export LANG="/tmp/LANG.json"
|
|
cat << \EOF > $LANG
|
|
{
|
|
"error": "error",
|
|
"info": "info",
|
|
"warn": "warn",
|
|
"debug": "debug",
|
|
|
|
"no_task": "no_task",
|
|
"missing_basedir": "$i18n_basedir",
|
|
"unknown_arg": "$i18n_arg",
|
|
"found_task": "$i18n_task",
|
|
"process": "$i18n_task",
|
|
"run": "$i18n_task",
|
|
"start_proc": "$i18n_task",
|
|
|
|
"config": "dummy"
|
|
}
|
|
EOF
|
|
|
|
# Enable debug for full log
|
|
export LOG="debug"
|
|
}
|
|
|
|
function teardown {
|
|
cd $ORIGDIR
|
|
if [ -d $TMPDIR ]; then rm -rf $TMPDIR; fi
|
|
}
|
|
|
|
@test "LANG=translations.json is loaded as translation file" {
|
|
run $FORGEBUILD -b /tmp/THISPATHDOESNOTEXIST
|
|
# If we find error/tmp/THISPATHDOESNOTEXIST, the file was loaded and
|
|
# the variable correctly substituted so we don't want to error
|
|
if [ "$output" != "error/tmp/THISPATHDOESNOTEXIST" ]; then
|
|
# If we find error$i18n_basedir, the file was successfully loaded
|
|
# but no variable were substituted (no error)
|
|
eq "$output" "error\$i18n_basedir"
|
|
fi
|
|
}
|
|
|
|
@test "\$i18n_basedir is substituted" {
|
|
run $FORGEBUILD -b /tmp/THISPATHDOESNOTEXIST
|
|
eq "$output" "error/tmp/THISPATHDOESNOTEXIST"
|
|
}
|
|
|
|
@test "\$i18n_task is substituted" {
|
|
run $FORGEBUILD -b $FORGEBUILDDIR
|
|
|
|
eq "${lines[0]}" "$(info no_task)"
|
|
eq "${lines[1]}" "$(debug pwd)"
|
|
eq "${lines[2]}" "$(debug time)"
|
|
|
|
# Maybe there's some additional output (like config)
|
|
# to suppress from this test.
|
|
prev_output="$output"
|
|
echo "$output"
|
|
# Found task
|
|
# We don't want to match the first debug pwd so we start line 3
|
|
CONTEXT="$output" run find_line "$(debug pwd)" 3
|
|
[ $status = 0 ]
|
|
# The line number matching process
|
|
i="$output"
|
|
run echo "$prev_output"
|
|
|
|
eq "${lines[i++]}" "$(debug pwd)"
|
|
eq "${lines[i++]}" "$(info pwd)"
|
|
eq "${lines[i++]}" "$(info pwd)"
|
|
eq "${lines[i++]}" "$(debug time)"
|
|
eq "${lines[i++]}" "$(info time)"
|
|
eq "${lines[i++]}" "$(info time)"
|
|
}
|