forked from DivinumOfficium/divinum-officium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated regression test for output.
- Loading branch information
1 parent
7b63c05
commit 299d5da
Showing
7 changed files
with
226 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Regression tests | ||
|
||
This directory contains tests for identifying regressions in the generated | ||
offices between two commits. Contrast this to the unit tests in `t/`, which | ||
test the correctness of the implementation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
|
||
use DateTime; | ||
use List::MoreUtils qw(zip); | ||
|
||
while (<>) | ||
{ | ||
# Strip comments and ignore blank lines. | ||
s/#.*//; | ||
next unless $_; | ||
|
||
# Expand date ranges. | ||
s/^(\d+-\d+-\d+)$/$1:$1/; | ||
s/(\d+)-(\d+)-(\d+):(\d+)-(\d+)-(\d+)/expand_dates($1, $2, $3, $4, $5, $6)/e; | ||
|
||
print; | ||
} | ||
|
||
sub expand_dates | ||
{ | ||
my @keys = ('month', 'day', 'year'); | ||
my @start_mdy = @_[0..2]; | ||
my @end_mdy = @_[3..5]; | ||
my $rover = DateTime->new(zip(@keys, @start_mdy)); | ||
my $end = DateTime->new(zip(@keys, @end_mdy)); | ||
|
||
my @dates; | ||
|
||
while ($rover <= $end) | ||
{ | ||
push @dates, $rover->mdy('-'); | ||
$rover->add(days => 1); | ||
} | ||
|
||
return join("\n", @dates); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
#!/bin/sh | ||
|
||
basedir="$(dirname $0)" | ||
source "${basedir}/util.sh" | ||
|
||
usage() { | ||
err 'Usage:' | ||
err " $scriptname <base_ref> <test_ref> <testspec>" | ||
exit 1 | ||
} | ||
|
||
############################################################################### | ||
|
||
export_tree() { | ||
local ref="$1" | ||
|
||
git archive --prefix="${treedir}/${ref}/" "${ref}": | tar x -C "${tempdir}" | ||
} | ||
|
||
# Path to office script from root of tree. | ||
office_script_path() { | ||
local hour="$1" | ||
echo -n 'web/cgi-bin/' | ||
if [ "${hour}" = 'SanctaMissa' ]; then | ||
echo 'missa/missa.pl' | ||
else | ||
echo 'horas/officium.pl' | ||
fi | ||
} | ||
|
||
long_version() { | ||
local short_version="$1" | ||
case "${short_version}" in | ||
Monastic) echo 'pre-Trident Monastic';; | ||
1570) echo 'Trident 1570';; | ||
1910) echo 'Trident 1910';; | ||
Divino) echo 'Divino Afflatu';; | ||
1955) echo 'Reduced 1955';; | ||
1960) echo 'Rubrics 1960';; | ||
*) die "Invalid short version: ${short_version}" | ||
esac | ||
} | ||
|
||
hour_command() { | ||
local hour="$1" | ||
echo "pray${hour}" | ||
} | ||
|
||
run_single_test() { | ||
local test_tree="$1" | ||
local output_tree="$2" | ||
local short_version="$3" | ||
local date="$4" | ||
local hour="$5" | ||
|
||
local output_dir="${output_tree}/${short_version}/${date}" | ||
mkdir -p "${output_dir}" | ||
|
||
# Run the script and store its output, stripping off the cookie. | ||
"${test_tree}/$(office_script_path "${hour}")" \ | ||
"version=$(long_version "${short_version}")" \ | ||
"command=$(hour_command "${hour}")" \ | ||
"date=${date}" | \ | ||
grep -Pv '^Set-Cookie:' > \ | ||
"${output_dir}/${hour}.out" | ||
} | ||
|
||
expand_dates() { | ||
local testspec="$1" | ||
"${scriptdir}/expand-dates.pl" "${testspec}" | ||
} | ||
|
||
gen_output_tree() { | ||
local ref="$1" | ||
echo "${tempdir}/${outputdir}/${ref}" | ||
} | ||
|
||
run_test() { | ||
local ref="$1" | ||
local testspec="$2" | ||
local test_tree="${tempdir}/${treedir}/${ref}" | ||
local output_tree="$(gen_output_tree "${ref}")" | ||
|
||
for date in $(expand_dates "${testspec}"); do | ||
for hour in Matutinum Vespera SanctaMissa; do | ||
for short_version in Divino 1960; do | ||
run_single_test \ | ||
"${test_tree}" \ | ||
"${output_tree}" \ | ||
"${short_version}" \ | ||
"${date}" \ | ||
"${hour}" | ||
done | ||
done | ||
done | ||
} | ||
|
||
############################################################################### | ||
|
||
main() { | ||
# Globals. | ||
treedir=trees | ||
outputdir=output | ||
scriptname=$(basename "$0") | ||
scriptdir=$(dirname "$0") | ||
|
||
[ $# -eq 3 ] || usage | ||
|
||
local reporoot=$(git rev-parse --show-toplevel) | ||
local base_ref=$(git rev-parse --verify "$1") | ||
local test_ref=$(git rev-parse --verify "$2") | ||
local testspec="$3" | ||
|
||
# Export the two test trees. | ||
echo 'Exporting...' | ||
try export_tree "${base_ref}" | ||
try export_tree "${test_ref}" | ||
|
||
# Run test against each tree. | ||
echo 'Testing...' | ||
run_test "${base_ref}" "${testspec}" | ||
run_test "${test_ref}" "${testspec}" | ||
|
||
# Generate diff. | ||
echo 'Diffing...' | ||
local diff_output="${tempdir}/output.diff" | ||
diff -ur \ | ||
"$(gen_output_tree "${base_ref}")" \ | ||
"$(gen_output_tree "${test_ref}")" > \ | ||
"${diff_output}" || true | ||
diffstat -p5 "${diff_output}" | ||
cat "${diff_output}" | ||
} | ||
|
||
tempdir=$(mktemp -d) || die 'Failed to create temporary directory.' | ||
(set -e; main "$@") | ||
try rm -rf "${tempdir}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/sh | ||
|
||
set -e | ||
|
||
basedir="$(dirname $0)" | ||
source "${basedir}/util.sh" | ||
|
||
parent_rev="$(echo ${TRAVIS_COMMIT_RANGE} | | ||
perl -ne '/(.*)\.\.\./ && print $1')" | ||
test_rev="${TRAVIS_COMMIT}" | ||
|
||
# Check validity of commits. | ||
git rev-parse --verify "${parent_rev}" | ||
git rev-parse --verify "${test_rev}" | ||
|
||
"${basedir}/generate-diff.sh" \ | ||
"${parent_rev}" \ | ||
"${test_rev}" \ | ||
"${basedir}/../tests/travis.testspec" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
err() { | ||
echo "$@" >&2 | ||
} | ||
|
||
die() { | ||
err "$@" | ||
exit 1 | ||
} | ||
|
||
try() { | ||
"$@" || die "ERROR: failed $@" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Circumcision to St Hilary | ||
1-1-2016:1-14-2016 | ||
# Quinquagesima to Saturday of the first week of Lent | ||
2-7-2016:2-20-2016 | ||
# Sitientes to Low Monday | ||
3-12-2016:4-4-2016 | ||
# Ascension to Monday of first week after the octave of Pentecost | ||
5-5-2016:5-23-2016 | ||
# XVII. and XVIII. weeks after the octave of Pentecost; latter is ember week | ||
9-11-2016:9-24-2016 | ||
# III. week of Advent | ||
12-11-2016:12-17-2016 |