Skip to content

Commit aa6f88d

Browse files
committed
Add tests and mechanism for running them through Travis CI
This patch adds tests for the PuzzleTools library and ensures they are run through Travis CI to verify that they succeed. It adds livecode as a submodule, and instructs travis to build the LiveCode community engine and run the tests. The tests are run using the livecode submodule's test runner via a Makefile which invokes the livecode test Makefile with a few tweaked parameters.
1 parent 8113709 commit aa6f88d

File tree

6 files changed

+219
-0
lines changed

6 files changed

+219
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tests/_lcs_test_suite.log

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "livecode"]
2+
path = livecode
3+
url = https://github.com/livecode/livecode

.travis.yml

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
sudo: required
2+
dist: trusty
3+
4+
# Build on both Linux and OSX
5+
os:
6+
- linux
7+
- osx
8+
9+
# Use a Travis image containing an Xcode we support
10+
# This prevents surprise upgrades!
11+
osx_image: xcode7.3
12+
13+
language: c++
14+
15+
compiler:
16+
- clang
17+
- gcc
18+
19+
# Environment variables
20+
env:
21+
global:
22+
- CXX_STD: "c++11"
23+
24+
jdk:
25+
- openjdk8
26+
27+
# Build using clang on mac and gcc on linux
28+
matrix:
29+
exclude:
30+
- os: osx
31+
compiler: gcc
32+
- os: linux
33+
compiler: clang
34+
35+
# Install any required tools
36+
before_install:
37+
- |
38+
if [[ "$TRAVIS_OS_NAME" == "osx" ]] ; then
39+
rvm --default use 2.2.1
40+
gem install xcpretty
41+
fi
42+
43+
- |
44+
if [[ "$TRAVIS_OS_NAME" == "linux" ]] ; then
45+
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
46+
sudo apt-get -qq update
47+
sudo apt-get -qq install g++-4.9
48+
fi
49+
50+
# Set up the source tree by fetching correct prebuilt objects
51+
install:
52+
- if [[ "$TRAVIS_OS_NAME" == "linux" ]] ; then (cd livecode/prebuilt && ./fetch-libraries.sh linux) ; fi
53+
- if [[ "$TRAVIS_OS_NAME" == "osx" ]] ; then (cd livecode/prebuilt && ./fetch-libraries.sh mac) ; fi
54+
55+
# Build the default target for LiveCode
56+
script: |
57+
case "${TRAVIS_OS_NAME}" in
58+
linux)
59+
BUILD_PLATFORM=linux
60+
CHECK_COMMAND=xvfb-run
61+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"${JAVA_HOME}/jre/lib/amd64/server"
62+
export CXX="g++-4.9"
63+
export CC="gcc-4.9"
64+
;;
65+
osx)
66+
BUILD_PLATFORM=mac
67+
CHECK_COMMAND=
68+
export XCODE_TARGET_SDK=macosx10.11
69+
export XCODEBUILD="set -o pipefail && xcodebuild"
70+
export XCODEBUILD_FILTER="| xcpretty"
71+
export JAVA_HOME=$(/usr/libexec/java_home)
72+
;;
73+
esac
74+
export MODE=debug
75+
76+
make -C livecode all-${BUILD_PLATFORM}
77+
if [ $? -ne 0 ] ; then
78+
echo " compile failed"
79+
exit 1
80+
fi
81+
${CHECK_COMMAND} make -C tests lcs-check
82+
if [ $? -ne 0 ] ; then
83+
echo " tests failed - dumping log file"
84+
cat tests/_lcs_test_suite.log
85+
exit 1
86+
fi
87+
88+
addons:
89+
# Packages needed for building LiveCode
90+
apt:
91+
packages:
92+
- gawk
93+
- libx11-dev
94+
- libxext-dev
95+
- libxrender-dev
96+
- libxft-dev
97+
- libxinerama-dev
98+
- libxv-dev
99+
- libxcursor-dev
100+
- libfreetype6-dev
101+
- libgtk2.0-dev
102+
- libpopt-dev
103+
- libesd0-dev
104+
- liblcms2-dev
105+
- xvfb
106+

livecode

Submodule livecode added at 4b29ad3

tests/Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# This Makefile takes advantage of the fact that the LiveCode engine's
2+
# "tests/Makefile" already does pretty much everything required for
3+
# running a test suite. Rather than duplicating it, it can
4+
# just be included with a few tweaks to its configuration.
5+
6+
# Override the default value of top_srcdir so that it points to the
7+
# top of the engine repository.
8+
top_srcdir = ../livecode
9+
10+
LCS_TESTS_DIR = test-scripts
11+
12+
# Things have now been setup enough that the engine's test Makefile
13+
# can perform the tests without any further configuration.
14+
include $(top_srcdir)/tests/Makefile
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
script "TestCiphers"
2+
3+
on TestSetup
4+
local tSourceFile
5+
put the filename of me into tSourceFile
6+
set the itemdelimiter to slash
7+
put "src/PuzzleTools.livecodescript" into item -3 to -1 of tSourceFile
8+
start using stack tSourceFile
9+
end TestSetup
10+
11+
private command TestAssertUserThrows pDesc, pHandler, pError
12+
local tError
13+
try
14+
dispatch pHandler to me
15+
catch tError
16+
end try
17+
18+
TestAssert pDesc, tError is pError
19+
20+
if tError is not pError then
21+
TestDiagnostic "Expected error:" && pError
22+
TestDiagnostic "Actual error:" && tError
23+
end if
24+
end TestAssertUserThrows
25+
26+
on LetterToNumberThrow
27+
get toNumber("'")
28+
end LetterToNumberThrow
29+
30+
on TestLetterToNumber
31+
local tIndex
32+
put 0 into tIndex
33+
repeat for each char tChar in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34+
add 1 to tIndex
35+
TestAssert "uppercase letter" && tChar && "to number correct", \
36+
toNumber(tChar) is tIndex
37+
end repeat
38+
39+
put 0 into tIndex
40+
repeat for each char tChar in "abcdefghijklmnopqrstuvwxyz"
41+
add 1 to tIndex
42+
TestAssert "lowercase letter" && tChar && "to number correct", \
43+
toNumber(tChar) is tIndex
44+
end repeat
45+
46+
TestAssertUserThrows "non alphabetic input to toNumber function throws", \
47+
"LetterToNumberThrow", "char not alphabetical"
48+
end TestLetterToNumber
49+
50+
on TestLetterFromNumber
51+
local tIndex
52+
put 0 into tIndex
53+
repeat for each char tChar in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
54+
add 1 to tIndex
55+
TestAssert "uppercase letter" && tChar && "from number correct", \
56+
fromNumber(tIndex) is tChar
57+
end repeat
58+
59+
put 0 into tIndex
60+
repeat for each char tChar in "abcdefghijklmnopqrstuvwxyz"
61+
add 1 to tIndex
62+
TestAssert "lowercase letter" && tChar && "from number correct", \
63+
fromNumber(tIndex) is tChar
64+
end repeat
65+
end TestLetterFromNumber
66+
67+
command _TestCaesarCipher pDesc, pSource, pShift, pExpected
68+
local tResult, tSuccess
69+
put caesarShift(pSource, pShift) into tResult
70+
put tResult is pExpected into tSuccess
71+
TestAssert pDesc, tSuccess
72+
73+
// If the test failed then log the actual output of caesarShift
74+
if not tSuccess then
75+
TestDiagnostic pDesc && "failed"
76+
TestDiagnostic "Expected result:" && pExpected
77+
TestDiagnostic "Actual result:" && tResult
78+
end if
79+
end _TestCaesarCipher
80+
81+
on TestCaesarCipher
82+
_TestCaesarCipher "abjurer <-> nowhere (13)", "abjurer", 13, "nowhere"
83+
_TestCaesarCipher "inkier <-> purply (7)", "inkier", 7, "purply"
84+
_TestCaesarCipher "fusion <-> layout (6)", "fusion", 6, "layout"
85+
_TestCaesarCipher "manful <-> thumbs (7)", "manful", 7, "thumbs"
86+
_TestCaesarCipher "primero <-> sulphur (3)", "primero", 3, "sulphur"
87+
_TestCaesarCipher "steeds <-> tuffet (1)", "steeds", 1, "tuffet"
88+
end TestCaesarCipher
89+
90+
on TestVigenereCipher
91+
TestAssert "LIVECODE encoded using vigenere cipher with key TEST is EMNXVSVX", \
92+
vigenereShift("LIVECODE","TEST") is "EMNXVSVX"
93+
end TestVigenereCipher
94+

0 commit comments

Comments
 (0)