Refactoring for better testing capabilities

This commit is contained in:
southerntofu 2022-02-21 00:44:11 +01:00
parent eb67748679
commit c6142711dd
7 changed files with 63 additions and 16 deletions

3
bin/.gitignore vendored
View File

@ -1,2 +1,5 @@
*
!.gitignore
!server
!test.sh
!dev_server.sh

24
bin/dev_server.sh Executable file
View File

@ -0,0 +1,24 @@
#! /bin/bash
# dev_server.sh PORT
# Start a PHP web server on port "PORT" to start serving the index.php endpoint
# If you'd like to run tests for the endpoint, you can use test.sh instead (will automatically start the server)
ORIGDIR="$(pwd)"
if [ -z "$FORGEHOOKPORT" ]; then
[ -z "$1" ] && exit 1
FORGEHOOKPORT="$1"
fi
# TODO: is this still actually used?
[ -z "$FORGEHOOK" ] && FORGEHOOK="forgehook"
# Move to parent folder from bin/
cd "$(dirname "$0")"/..
php -S localhost:$FORGEHOOKPORT
if [[ $? != 0 ]]; then
exit 2
fi
cd "$ORIGDIR"

3
bin/server Executable file
View File

@ -0,0 +1,3 @@
#! /usr/bin/env bash
echo "$(dirname "$0")"/dev_server.sh

31
bin/test.sh Executable file
View File

@ -0,0 +1,31 @@
#! /usr/bin/env bash
SCRIPTDIR="$(dirname "$0")"
BASEDIR="$(realpath "$SCRIPTDIR"/..)"
ORIGDIR="$(pwd)"
if [ ! -f "$BASEDIR"/spec/test_cli.sh ]; then
echo "Submodule not cloned yet. Doing it now"
cd "$BASEDIR"
git submodule init
if ! git submodule update; then
echo "Failed to download submodules. Are you connected to the internet?"
exit 1
fi
fi
# If bin/server succeeds, it contains a path to the executable
# Otherwise it may contain build error messages
server="$("$BASEDIR"/bin/server)"
if [ $? -eq 0 ]; then
# Let test_web.sh figure out the path to whck
"$BASEDIR"/spec/test_web.sh "$server"
status=$?
else
status=1
echo "Build failed. OUTPUT:"
echo "$output"
fi
cd "$ORIGDIR"
exit $status

14
server
View File

@ -1,14 +0,0 @@
#! /bin/bash
# This script should be used by the test suite, don't useit manually
if [ -z "$FORGEHOOKPORT" ]; then
[ -z "$1" ] && exit 1
FORGEHOOKPORT="$1"
fi
[ -z "$FORGEHOOK" ] && FORGEHOOK="forgehook"
cd "$(dirname "$0")"
php -S localhost:$FORGEHOOKPORT
if [[ $? != 0 ]]; then
exit 2
fi

2
spec

@ -1 +1 @@
Subproject commit 71804c4b3a5f19bb53fdab0bbcecb39ed0919aca
Subproject commit 9fca3d5736ba709f618ffb3d8630efb741976c14

2
whck

@ -1 +1 @@
Subproject commit 510a0b13b99f85379fe10dabadce408aa95a795d
Subproject commit 25f16530087d1be6added84fbac7bb28c3511431