Skip to content

Commit 2b9ab89

Browse files
committed
Merge journey test scripts into one.
1 parent c7cfe1b commit 2b9ab89

File tree

5 files changed

+227
-132
lines changed

5 files changed

+227
-132
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ before_install:
1515
- rvm use 2.2.1
1616

1717
script:
18-
- bin/run-unit-tests-in-ci.sh
19-
- bin/run-journey-test-in-ci.sh
18+
- bin/unit-tests.sh
19+
- bin/journey-test.sh

bin/journey-test.sh

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
#!/bin/bash
2+
SCRIPTPATH=$( pushd `dirname $0` > /dev/null && pwd && popd > /dev/null )
3+
EXECPATH=$PWD
4+
XAPI_PID=""
5+
6+
function on_exit() {
7+
echo ">>> on_exit()"
8+
if [ "$XAPI_PID" != "" ] ; then
9+
kill $XAPI_PID
10+
echo "Stopped X-API (pid=${XAPI_PID})"
11+
fi
12+
cd $EXECPATH
13+
echo "<<< on_exit()"
14+
}
15+
16+
assert_gradle_installed() {
17+
echo ">>> assert_gradle_installed()"
18+
which gradle >/dev/null
19+
if [ $? != 0 ]; then
20+
echo "Gradle not found. This the Java build tool and is required."
21+
echo -e "Have you completed the setup instructions at https://github.com/exercism/xjava ?\n"
22+
echo "PATH=${PATH}"
23+
echo "aborting."
24+
exit 1
25+
fi
26+
echo "<<< assert_gradle_installed()"
27+
}
28+
29+
assert_jq_installed() {
30+
echo ">>> assert_jq_installed()"
31+
which jq >/dev/null
32+
if [ $? != 0 ]; then
33+
echo "jq not found. This utility is used to parse the config.json file and is required."
34+
echo -e "Have you completed the setup instructions at https://github.com/exercism/xjava ?\n"
35+
echo "PATH=${PATH}"
36+
echo "aborting."
37+
exit 1
38+
fi
39+
echo "<<< assert_jq_installed()"
40+
}
41+
42+
assert_required_ruby_installed() {
43+
echo ">>> assert_required_ruby_installed(\"$1\")"
44+
local RACKAPP_HOME="$1"
45+
46+
pushd "${RACKAPP_HOME}" >/dev/null
47+
local CURRENT_RUBY_VER=`ruby --version | egrep --only-matching "[0-9]+\.[0-9]+\.[0-9]+"`
48+
local EXPECTED_RUBY_VER=`cat Gemfile | awk -F\' '/ruby /{print $2}'`
49+
popd >/dev/null
50+
if [ "$CURRENT_RUBY_VER" != "$EXPECTED_RUBY_VER" ]; then
51+
echo "${RACKAPP_HOME} requires Ruby ${EXPECTED_RUBY_VER}; current Ruby version is ${CURRENT_RUBY_VER}."
52+
echo -e "Ruby used: `which ruby`.\n"
53+
echo -e "Have you completed the setup instructions at https://github.com/exercism/xjava ?\n"
54+
echo "PATH=${PATH}"
55+
echo "aborting."
56+
exit 1
57+
fi
58+
echo "<<< assert_required_ruby_installed()"
59+
}
60+
61+
clean_build() {
62+
echo ">>> clean_build(\"$1\", \"$2\")"
63+
local REPO_ROOT="$1"
64+
local BUILD_DIR="$2"
65+
66+
if [ -d "$BUILD_DIR" ] ; then
67+
echo "Cleaning journey script build (${BUILD_DIR})."
68+
rm -rf "$BUILD_DIR"
69+
fi
70+
pushd ${REPO_ROOT}/exercises > /dev/null
71+
gradle clean
72+
popd > /dev/null
73+
echo "<<< clean_build()"
74+
}
75+
76+
get_operating_system() {
77+
case $(uname) in
78+
(Darwin*)
79+
echo "mac";;
80+
(Linux*)
81+
echo "linux";;
82+
(Windows*)
83+
echo "windows";;
84+
(*)
85+
echo "linux";;
86+
esac
87+
}
88+
89+
get_cpu_architecture() {
90+
case $(uname -m) in
91+
(*64*)
92+
echo 64bit;;
93+
(*686*)
94+
echo 32bit;;
95+
(*386*)
96+
echo 32bit;;
97+
(*)
98+
echo 64bit;;
99+
esac
100+
}
101+
102+
fetch_exercism_cli() {
103+
echo ">>> fetch_exercism_cli(\"$1\", \"$2\", \"$3\")"
104+
local OS="$1"
105+
local ARCH="$2"
106+
local EXERCISM_HOME="$3"
107+
108+
local LATEST=https://github.com/exercism/cli/releases/latest
109+
# "curl..." :: HTTP 302 headers, including "Location" -- URL to redirect to.
110+
# "awk..." :: pluck last path segment from "Location" (i.e. the version number)
111+
local VERSION="$(curl --head --silent $LATEST | awk -v FS=/ '/Location:/{print $NF}' | tr -d '\r')"
112+
local CLI_URL=https://github.com/exercism/cli/releases/download/${VERSION}/exercism-${OS}-${ARCH}.tgz
113+
114+
mkdir -p ${EXERCISM_HOME}
115+
curl -s --location ${CLI_URL} | tar xz -C ${EXERCISM_HOME}
116+
echo "<<< fetch_exercism_cli()"
117+
}
118+
119+
fetch_x_api() {
120+
echo ">>> fetch_x_api(\"$1\")"
121+
local XAPI_HOME="$1"
122+
123+
git clone https://github.com/exercism/x-api ${XAPI_HOME}
124+
pushd ${XAPI_HOME} >/dev/null
125+
git submodule init -- metadata
126+
git submodule update
127+
rmdir tracks/java
128+
ln -s $REPO_ROOT tracks/java
129+
popd > /dev/null
130+
echo "<<< fetch_x_api()"
131+
}
132+
133+
start_x_api() {
134+
echo ">>> start_x_api(\"$1\")"
135+
local XAPI_HOME="$1"
136+
137+
pushd $XAPI_HOME >/dev/null
138+
139+
SET_RUBY_VER_CMD="rbenv local 2.2.1"
140+
gem install bundler
141+
bundle install
142+
143+
RACK_ENV=development rackup &
144+
XAPI_PID=$!
145+
sleep 5
146+
147+
echo "X-API is running (pid=${XAPI_PID})."
148+
149+
popd > /dev/null
150+
echo "<<< start_x_api()"
151+
}
152+
153+
configure_exercism_cli() {
154+
echo ">>> configure_exercism_cli(\"$1\", \"$2\", $3)"
155+
local EXERCISM_HOME="$1"
156+
local EXERCISM_CONFIGFILE="$2"
157+
local XAPI_PORT=$3
158+
local EXERCISM="./exercism --config ${EXERCISM_CONFIGFILE}"
159+
160+
mkdir -p "${EXERCISM_HOME}"
161+
pushd "${EXERCISM_HOME}" >/dev/null
162+
$EXERCISM configure --dir="${EXERCISM_HOME}"
163+
$EXERCISM configure --api http://localhost:${XAPI_PORT}
164+
$EXERCISM debug
165+
popd >/dev/null
166+
167+
echo "<<< configure_exercism_cli()"
168+
}
169+
170+
solve_all_exercises() {
171+
echo ">>> solve_all_exercises(\"$1\", \"$2\")"
172+
173+
local EXERCISM_HOME="$1"
174+
local EXERCISM_CONFIGFILE="$2"
175+
176+
local EXERCISM="./exercism --config ${EXERCISM_CONFIGFILE}"
177+
local EXERCISES=`cat config.json | jq '.problems []' --raw-output`
178+
local TOTAL_EXERCISES=`cat config.json | jq '.problems | length'`
179+
local CURRENT_EXERCISE_NUMBER=1
180+
181+
pushd ${EXERCISM_HOME} >/dev/null
182+
for EXERCISE in $EXERCISES; do
183+
echo ''
184+
echo '****' Testing $EXERCISE '('$CURRENT_EXERCISE_NUMBER / $TOTAL_EXERCISES') ****'
185+
echo ''
186+
$EXERCISM fetch java $EXERCISE
187+
cp -R -H $REPO_ROOT/exercises/$EXERCISE/src/example/java/* $EXERCISM_HOME/java/$EXERCISE/src/main/java/
188+
pushd $EXERCISM_HOME/java/$EXERCISE/ >/dev/null
189+
gradle test
190+
popd >/dev/null
191+
192+
CURRENT_EXERCISE_NUMBER=$((CURRENT_EXERCISE_NUMBER + 1))
193+
done
194+
popd >/dev/null
195+
}
196+
197+
main() {
198+
# allow all functions to assume current working directory is repository root.
199+
cd "${SCRIPTPATH}/.."
200+
201+
local REPO_ROOT="${PWD}"
202+
local BUILD_DIR="${REPO_ROOT}/build"
203+
local XAPI_HOME="${BUILD_DIR}/x-api"
204+
local EXERCISM_HOME="${BUILD_DIR}/exercism"
205+
local EXERCISM_CONFIGFILE=".journey-test.exercism.json"
206+
local XAPI_PORT=9292
207+
208+
assert_gradle_installed
209+
assert_jq_installed
210+
clean_build "${REPO_ROOT}" "${BUILD_DIR}"
211+
fetch_exercism_cli $(get_operating_system) $(get_cpu_architecture) "${EXERCISM_HOME}"
212+
fetch_x_api "${XAPI_HOME}"
213+
assert_required_ruby_installed "${XAPI_HOME}"
214+
start_x_api "${XAPI_HOME}"
215+
configure_exercism_cli "${EXERCISM_HOME}" "${EXERCISM_CONFIGFILE}" "${XAPI_PORT}"
216+
solve_all_exercises "${EXERCISM_HOME}" "${EXERCISM_CONFIGFILE}"
217+
}
218+
219+
##########################################################################
220+
# Execution begins here...
221+
222+
set -e
223+
trap on_exit EXIT
224+
main
225+

bin/run-journey-test-in-ci.sh

Lines changed: 0 additions & 55 deletions
This file was deleted.

bin/run-journey-test-locally.sh

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)