Skip to content

Commit 3694697

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 3694697

File tree

6 files changed

+193
-0
lines changed

6 files changed

+193
-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: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
${CHECK_COMMAND} make -C tests lcs-check
78+
79+
addons:
80+
# Packages needed for building LiveCode
81+
apt:
82+
packages:
83+
- gawk
84+
- libx11-dev
85+
- libxext-dev
86+
- libxrender-dev
87+
- libxft-dev
88+
- libxinerama-dev
89+
- libxv-dev
90+
- libxcursor-dev
91+
- libfreetype6-dev
92+
- libgtk2.0-dev
93+
- libpopt-dev
94+
- libesd0-dev
95+
- liblcms2-dev
96+
- xvfb
97+

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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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+
TestDiagnostic tError
19+
20+
TestAssert pDesc, tError is pError
21+
end TestAssertUserThrows
22+
23+
on LetterToNumberThrow
24+
get toNumber("'")
25+
end LetterToNumberThrow
26+
27+
on TestLetterToNumber
28+
local tIndex
29+
put 0 into tIndex
30+
repeat for each char tChar in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
31+
add 1 to tIndex
32+
TestAssert "uppercase letter" && tChar && "to number correct", \
33+
toNumber(tChar) is tIndex
34+
end repeat
35+
36+
put 0 into tIndex
37+
repeat for each char tChar in "abcdefghijklmnopqrstuvwxyz"
38+
add 1 to tIndex
39+
TestAssert "lowercase letter" && tChar && "to number correct", \
40+
toNumber(tChar) is tIndex
41+
end repeat
42+
43+
TestAssertUserThrows "non alphabetic input to toNumber function throws", \
44+
"LetterToNumberThrow", "char not alphabetical"
45+
end TestLetterToNumber
46+
47+
on TestLetterFromNumber
48+
local tIndex
49+
put 0 into tIndex
50+
repeat for each char tChar in "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
51+
add 1 to tIndex
52+
TestAssert "uppercase letter" && tChar && "from number correct", \
53+
fromNumber(tIndex) is tChar
54+
end repeat
55+
56+
put 0 into tIndex
57+
repeat for each char tChar in "abcdefghijklmnopqrstuvwxyz"
58+
add 1 to tIndex
59+
TestAssert "lowercase letter" && tChar && "from number correct", \
60+
fromNumber(tIndex) is tChar
61+
end repeat
62+
end TestLetterFromNumber
63+
64+
on TestCaesarCipher
65+
TestAssert "abjurer <-> nowhere (13)", caesarShift("abjurer", 13) is "nowhere"
66+
TestAssert "inkier <-> purply (7)", caesarShift("inkier", 7) is "purply"
67+
TestAssert "fusion <-> layout (6)", caesarShift("fusion", 6) is "layout"
68+
TestAssert "manful <-> thumbs (7)", caesarShift("manful", 7) is "thumbs"
69+
TestAssert "primero <-> sulphur (3)", caesarShift("primero", 3) is "sulphur"
70+
TestAssert "steeds <-> tuffet (1)", caesarShift("steeds", 1) is "tuffet"
71+
end TestCaesarCipher
72+
73+
on TestVigenereCipher
74+
TestAssert "LIVECODE encoded using vigenere cipher with key TEST is EMNXVSVX", \
75+
vigenereShift("LIVECODE","TEST") is "EMNXVSVX"
76+
end TestVigenereCipher
77+

0 commit comments

Comments
 (0)