From 787f9102468e4eeabf5a3ca33ebbd4037cb08e22 Mon Sep 17 00:00:00 2001 From: Konstantin Baierer Date: Tue, 31 May 2016 02:33:02 +0200 Subject: [PATCH] First try of converting tests to tsht --- .gitignore | 1 + .travis.yml | 3 +++ test/backend.tsht | 47 +++++++++++++++++++++++++++++++++++++++++++++++ test/tsht | 22 ++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 .travis.yml create mode 100755 test/backend.tsht create mode 100755 test/tsht diff --git a/.gitignore b/.gitignore index efad417..1dadbb7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ /bower_components /node_modules npm-debug.log +test/.tsht diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..73c6456 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: bash + +script: ./test/tsht diff --git a/test/backend.tsht b/test/backend.tsht new file mode 100755 index 0000000..6c50597 --- /dev/null +++ b/test/backend.tsht @@ -0,0 +1,47 @@ +#!/usr/bin/env tsht +PORT=9091 +SAMPLE_URL="http://example.org/fileadmin/digi/445442158/thumbs/445442158_0126.jpg" +SAMPLE_THUMB="example/fileadmin/digi/445442158/thumbs/445442158_0126.jpg" +SAMPLE_CORR="example/ocr-corrections/digi/445442158/gt/0126/correction.html" +SAMPLE_COMM="example/ocr-corrections/digi/445442158/gt/0126/anmerkungen.txt" + +# rm request log files, samples, start the server, wait a second, see if it's still running +start_server() { + rm -f dist/log/* $SAMPLE_COMM $SAMPLE_CORR + plackup --port=$PORT ../app.psgi & SERVER_PID=$! + sleep 1 + ps -p "$SERVER_PID" 2>/dev/null +} + +stop_server() { + kill "$SERVER_PID" && true + cat dist/log/ocr-gt-tools.log +} + +# # Test history +# test_history() { +# curl -i "http://localhost:$PORT/ocr-gt-tools.cgi?action=history" +# [[ "$(wc -l dist/log/request.log|cut -d' ' -f1)" = "1" ]]; +# } + +# Test create +test_create() { + [[ ! -e $SAMPLE_CORR ]]; + curl -i "http://localhost:$PORT/ocr-gt-tools.cgi?action=create&imageUrl=$SAMPLE_URL" + [[ -e $SAMPLE_CORR ]]; +} + + +# -x Trace steps +# -e exit on first non-null return value +set -e + +# Stop the server for failing tests +trap stop_server EXIT + +start_server + +# test_create +# test_history + +stop_server diff --git a/test/tsht b/test/tsht new file mode 100755 index 0000000..30683d0 --- /dev/null +++ b/test/tsht @@ -0,0 +1,22 @@ +#!/bin/bash + +# Unless TSHTLIB is already set +if [[ -z "$TSHTLIB" ]];then + + # Set TSHTLIB to the `.tshs` directory relative to this script + TSHTLIB="$(cd "$(dirname "$0")" && pwd)/.tsht" + + # Unless TSHTLIB exists, try to clone it + if [[ ! -e "$TSHTLIB" ]];then + echo "# $TSHTLIB does not exist, cloning" + git clone --depth 1 'http://github.com/kba/tsht' "$TSHTLIB" + if [[ ! -d "$TSHTLIB" ]];then + echo "Failed to clone tsht framework!" + exit 201 + fi + fi +fi + +# Export TSHTLIB and execute the test-runner +export TSHTLIB +exec "$TSHTLIB/tsht-runner.sh" "$@"