Skip to content

Commit

Permalink
Move tests to snapshot-tests and enhance them (#141)
Browse files Browse the repository at this point in the history
Snapshot tests kind of suck in general and are more fragile, but
they are all we really have right now for testing before the unit
test changes and they can still serve some purpose for doing
end-to-end testing.

This moves the directory to be better named, updates the github
workflow to use the new directory/driver script and enhances that
script to compare the output to 'expected' output each step of
the way.
  • Loading branch information
jt-traub authored Oct 10, 2023
1 parent e17a21f commit 4ae2adc
Show file tree
Hide file tree
Showing 133 changed files with 904,467 additions and 52 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ jobs:
- uses: actions/download-artifact@v2
with:
name: ubuntu
- run: ./run-tests.sh
working-directory: tests
- run: ./run-snapshots.sh
working-directory: snapshot-tests
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ neworigins/html/neworigins.html
neworigins_v2/obj
neworigins_v2/neworigins_v2
neworigins_v2/html/neworigins.html
snapshot-tests/standard
snapshot-tests/output
times.*
report.*
template.*
players.*
game.*
names.*
orders.*
orders.*
62 changes: 62 additions & 0 deletions snapshot-tests/run-snapshots.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/bin/bash

if [[ ! -f ../standard/standard ]]; then
echo "Please build the standard executable before running the snapshot tests. Test failed."
exit 1
fi

cp ../standard/standard standard
chmod +x ./standard

lastTurn=$(<"turns/turn")

for turn in $(seq 0 $lastTurn)
do
echo -n "Replaying turn $turn..."
cp -f turns/turn_$turn/game.in game.in
cp -f turns/turn_$turn/players.in players.in
cp -f turns/turn_$turn/orders.3 orders.3

./standard run &> engine-output.txt
if [[ $? != 0 ]]; then
echo "executable crashed. -- Test failed."
cat engine-output.txt
rm -f game.*
rm -f players.*
rm -f times.*
rm -f orders.*
rm -f template.*
rm -f report.*
rm -f engine-output.txt
rm -f ./standard
exit 1
fi

mkdir -p output/turn_$turn
mv game.* output/turn_$turn
mv players.* output/turn_$turn
if [[ -f times.* ]]; then
mv times.* output/turn_$turn
fi
mv orders.* output/turn_$turn
mv template.* output/turn_$turn
mv report.* output/turn_$turn
mv engine-output.txt output/turn_$turn

diff -ur turns/turn_$turn output/turn_$turn &> turn-difference.txt
if [[ $? != 0 ]]; then
echo "output differed. -- Test failed."
cat turn-difference.txt
rm -f turn-difference.txt
rm -f ./standard
rm -rf ./output
exit 1
fi

echo "identical. -- Test succeeded."
rm -f turn-difference.txt
done

rm -f ./standard
rm -rf ./output
exit 0
44 changes: 44 additions & 0 deletions snapshot-tests/turns/new-turn.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

curTurn=$(< ./turn)
nextTurn=$((curTurn + 1))

if [[ ! -f ../../standard/standard ]]; then
echo "Please build the standard executable before trying to create a new snapshot turn."
exit 1
fi

if [[ ! -d turn_$nextTurn ]]; then
mkdir turn_$nextTurn
cp turn_$curTurn/game.out turn_$nextTurn/game.in
cp turn_$curTurn/players.out turn_$nextTurn/players.in
cp turn_$curTurn/template.3 turn_$nextTurn/orders.3
fi

echo "Modify the input orders for turn_$nextTurn to test desired changes"
echo "When that is complete, rerun this script."

diff turn_$curTurn/template.3 turn_$nextTurn/orders.3 &> /dev/null
if [[ $? = 0 ]];
then
echo "No order changes have occured. Exiting."
exit 0
fi

echo "Running turn to produce new output"
cd turn_$nextTurn
../../../standard/standard run &> engine-output.txt

if [[ $? != 0 ]]; then
echo "Game engine crashed while generating turn. Turn not generated."
cat engine-output.txt
rm -f *.out
rm -f template.*
rm -f report.*
rm -f times.*
rm -f engine-output.txt
fi

echo "$nextTurn" > ../turn

rm -f times.*
File renamed without changes.
46 changes: 46 additions & 0 deletions snapshot-tests/turns/turn_0/engine-output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
Atlantis Engine Version: 5.2.5 (beta)
Wyreth, Version: 2.0.0 (beta)

Saved Game Engine Version: 5.2.4 (beta)
Saved Rule-Set Version: 2.0.0 (beta)
Reading the regions...
Setting up the neighbors...
Setting Up Turn...
Reading the Gamemaster File...
Reading the Orders File...
QUITting Inactive Factions...
Running the Turn...
Running FIND Orders...
Running ENTER/LEAVE Orders...
Running PROMOTE/EVICT Orders...
Running Combat...
Running STEAL/ASSASSINATE Orders...
Running GIVE Orders...
Running ENTER NEW Orders...
Running EXCHANGE Orders...
Running DESTROY Orders...
Running PILLAGE Orders...
Running TAX Orders...
Running GUARD 1 Orders...
Running Magic Orders...
Running SELL Orders...
Running BUY Orders...
Running FORGET Orders...
Mid-Turn Processing...
Running QUIT Orders...
Removing Empty Units...
Running WITHDRAW Orders...
Running Consolidated Movement Orders...
Running Teach Orders...
Running Month-long Orders...
Running Economics...
Running Teleport Orders...
Assessing Maintenance costs...
Post-Turn Processing...
Writing the Report File...
...
Writing order templates...
...
Writing Playerinfo File...
Removing Dead Factions...
done
File renamed without changes.
Loading

0 comments on commit 4ae2adc

Please sign in to comment.