Skip to content

Commit 12e5338

Browse files
committed
Travis build will only test against one exercise that's been modified
1 parent 6e9bc5d commit 12e5338

2 files changed

Lines changed: 57 additions & 11 deletions

File tree

.travis.yml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,23 @@ jdk:
44
- oraclejdk8
55
env:
66
- SCRIPT=bin/unit-tests.sh
7-
8-
# https://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines
7+
98
- SCRIPT="bin/build-jq.sh;
10-
for file in \`curl -s https://api.github.com/repos/exercism/java/pulls/$TRAVIS_PULL_REQUEST/files | bin/jq -r '.[].filename'\`;
11-
do if [[ \$file == exercises* ]] || [[ \$file == config.json ]];
12-
then rvm install 2.2.5;
13-
rvm use 2.2.5;
14-
bin/journey-tests.sh;
15-
break;
16-
fi;
17-
done"
9+
modded_files=\`curl -s https://api.github.com/repos/exercism/java/pulls/${TRAVIS_PULL_REQUEST}/files | bin/jq -r '.[].filename'\`;
10+
for file in \$modded_files;
11+
do if [[ \$file == exercises* ]] || [[ \$file == config.json ]];
12+
then rvm install 2.2.5;
13+
rvm use 2.2.5;
14+
for file2 in \$modded_files;
15+
do if [[ \$file2 == exercises* ]];
16+
then modded_exercise=\${file2#exercises/};
17+
modded_exercise=\${modded_exercise%%/*};
18+
fi;
19+
done;
20+
bin/journey-test.sh \$modded_exercise;
21+
break;
22+
fi;
23+
done"
1824

1925
# http://docs.travis-ci.com/user/migrating-from-legacy
2026
sudo: false

bin/journey-test.sh

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ TRACK=java
44
TRACK_REPO="$TRACK"
55
TRACK_SRC_EXT="java"
66
CPU_CORES=`getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1`
7+
EXERCISE_TO_SOLVE=$1
78

89
on_exit() {
910
echo ">>> on_exit()"
@@ -256,6 +257,41 @@ solve_all_exercises() {
256257
popd
257258
}
258259

260+
solve_single_exercise() {
261+
local exercism_exercises_dir="$1"
262+
local exercism_configfile="$2"
263+
local exercise_to_solve="$3"
264+
echo ">>> solve_all_exercises(exercism_exercises_dir=\"${exercism_exercises_dir}\", exercism_configfile=\"${exercism_configfile}\", exercise_to_solve=\"$exercise_to_solve\")"
265+
266+
local track_root=$( pwd )
267+
local exercism_cli="./exercism --config ${exercism_configfile}"
268+
269+
pushd ${exercism_exercises_dir}
270+
271+
echo -e "\n\n"
272+
echo "=================================================="
273+
echo "Solving ${exercise_to_solve}"
274+
echo "=================================================="
275+
276+
${exercism_cli} fetch ${TRACK} $exercise_to_solve
277+
cp -R -H ${track_root}/exercises/${exercise_to_solve}/src/example/${TRACK}/* ${exercism_exercises_dir}/${TRACK}/${exercise_to_solve}/src/main/${TRACK}/
278+
279+
pushd ${exercism_exercises_dir}/${TRACK}/${exercise_to_solve}
280+
# Check that tests compile before we strip @Ignore annotations
281+
"$EXECPATH"/gradlew compileTestJava
282+
# Ensure we run all the tests (as delivered, all but the first is @Ignore'd)
283+
for testfile in `find . -name "*Test.${TRACK_SRC_EXT}"`; do
284+
# Strip @Ignore annotations to ensure we run the tests (as delivered, all but the first is @Ignore'd).
285+
# Note that unit-test.sh also strips @Ignore annotations via the Gradle task copyTestsFilteringIgnores.
286+
# The stripping implementations here and in copyTestsFilteringIgnores should be kept consistent.
287+
sed 's/@Ignore\(\(.*\)\)\{0,1\}//' ${testfile} > "${tempfile}" && mv "${tempfile}" "${testfile}"
288+
done
289+
"$EXECPATH"/gradlew test
290+
popd
291+
292+
popd
293+
}
294+
259295
main() {
260296
# all functions assume current working directory is repository root.
261297
cd "${SCRIPTPATH}/.."
@@ -296,7 +332,11 @@ main() {
296332
# Create a CLI install and config just for this build; this script does not use your CLI install.
297333
configure_exercism_cli "${exercism_home}" "${exercism_configfile}" "${xapi_port}"
298334

299-
solve_all_exercises "${exercism_home}" "${exercism_configfile}"
335+
if [[ ${EXERCISE_TO_SOLVE} == "" ]]; then
336+
solve_all_exercises "${exercism_home}" "${exercism_configfile}"
337+
else
338+
solve_single_exercise "${exercism_home}" "${exercism_configfile}" "${EXERCISE_TO_SOLVE}"
339+
fi
300340
}
301341

302342
##########################################################################

0 commit comments

Comments
 (0)