diff --git a/.travis.yml b/.travis.yml index a93eab99..fd82b715 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,5 +50,4 @@ script: - bin/fetch-configlet - bin/configlet lint . - bin/check-configlet-fmt.sh - - cmake -G Ninja - - ninja + - bin/check-exercises.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index e6ed66dd..594faac9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,56 +20,10 @@ endfunction() option(EXERCISM_RUN_ALL_TESTS "Run all Exercism tests" On) -foreach(exercise - hello-world - bob - word-count - hamming - anagram - food-chain - beer-song - nucleotide-count - rna-transcription - phone-number - grade-school - robot-name - leap - etl - space-age - grains - gigasecond - triangle - clock - raindrops - difference-of-squares - roman-numerals - nth-prime - sieve - binary - sum-of-multiples - series - prime-factors - pascals-triangle - trinary - crypto-square - scrabble-score - hexadecimal - say - meetup - queen-attack - allergies - atbash-cipher - bracket-push - all-your-base - pangram - binary-search-tree - robot-simulator - binary-search - isogram - reverse-string - acronym - luhn -) +file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/*) + +foreach(exercise_dir ${exercise_list}) + get_filename_component(exercise ${exercise_dir} NAME) travis_fixup(${exercise} ${alt_exercise_tree}) add_subdirectory(${alt_exercise_tree}/${exercise}) endforeach() diff --git a/bin/check-exercises.sh b/bin/check-exercises.sh new file mode 100755 index 00000000..a89cdacd --- /dev/null +++ b/bin/check-exercises.sh @@ -0,0 +1,31 @@ +#!/usr/bin/env bash +# +# Runs tests only if the current Pull Request has modified a test or the root +# CMakeLists.txt, or if we are running on the master branch. + +# Fail if any command fails +set -e + +repo=$(cd "$(dirname "$0")/.." && pwd) + +# Configure all the tests. +cmake -G Ninja "$repo" +echo "" + +if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then + echo "This is not a Pull Request, running all tests." + cmake --build "$repo" +elif git diff --name-only master | grep "^CMakeLists.txt"; then + echo "This PR changes the root CMakeLists.txt." + echo "Running a single test and then all tests." + cmake --build "$repo" -- test_hello-world + cmake --build "$repo" +else + tests="$(git diff --name-only master | grep "^exercises/" | cut -d '/' -f2 | sed 's/.*/test_&/' | uniq | tr '\n' ' ')" + if [ ${#tests} -ne 0 ]; then + echo "Running only tests that have changed." + cmake --build "$repo" -- $tests + else + echo "No tests changed." + fi +fi