Преглед на файлове

Travis build will only test against one exercise that's been modified

Logan Stucki преди 9 години
родител
ревизия
12e53383fb
No account linked to committer's email
променени са 2 файла, в които са добавени 57 реда и са изтрити 11 реда
  1. 16
    10
      .travis.yml
  2. 41
    1
      bin/journey-test.sh

+ 16
- 10
.travis.yml Целия файл

@@ -4,17 +4,23 @@ jdk:
4 4
   - oraclejdk8
5 5
 env:
6 6
   - SCRIPT=bin/unit-tests.sh
7
- 
8
-  # https://stackoverflow.com/questions/3790454/in-yaml-how-do-i-break-a-string-over-multiple-lines
7
+
9 8
   - 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"
18 24
 
19 25
 # http://docs.travis-ci.com/user/migrating-from-legacy
20 26
 sudo: false

+ 41
- 1
bin/journey-test.sh Целия файл

@@ -4,6 +4,7 @@ TRACK=java
4 4
 TRACK_REPO="$TRACK"
5 5
 TRACK_SRC_EXT="java"
6 6
 CPU_CORES=`getconf NPROCESSORS_ONLN 2>/dev/null || getconf _NPROCESSORS_ONLN 2>/dev/null || echo 1`
7
+EXERCISE_TO_SOLVE=$1
7 8
 
8 9
 on_exit() {
9 10
   echo ">>> on_exit()"
@@ -256,6 +257,41 @@ solve_all_exercises() {
256 257
   popd
257 258
 }
258 259
 
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
+
259 295
 main() {
260 296
   # all functions assume current working directory is repository root.
261 297
   cd "${SCRIPTPATH}/.."
@@ -296,7 +332,11 @@ main() {
296 332
   # Create a CLI install and config just for this build; this script does not use your CLI install.
297 333
   configure_exercism_cli "${exercism_home}" "${exercism_configfile}" "${xapi_port}"
298 334
 
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
300 340
 }
301 341
 
302 342
 ##########################################################################