From d108af5664490947145da428eb9a90ea6d6529fc Mon Sep 17 00:00:00 2001 From: Sebastian Wilzbach Date: Thu, 5 Apr 2018 01:35:21 +0200 Subject: [PATCH] Port the individual test script runner to D --- .circleci/run.sh | 3 ++- test/README.md | 8 +++---- test/run_individual_tests | 41 ---------------------------------- test/run_individual_tests.d | 44 +++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 46 deletions(-) delete mode 100755 test/run_individual_tests create mode 100755 test/run_individual_tests.d diff --git a/.circleci/run.sh b/.circleci/run.sh index 4fafb8562e2d..eeeab28ac948 100755 --- a/.circleci/run.sh +++ b/.circleci/run.sh @@ -167,7 +167,8 @@ check_clean_git() # sanitycheck for the run_individual_tests script check_run_individual() { - ./test/run_individual_tests test/runnable/template2962.d ./test/compilable/test14275.d + local build_path=generated/linux/release/$MODEL + "${build_path}/dmd" -i -run ./test/run_individual_tests.d test/runnable/template2962.d ./test/compilable/test14275.d } codecov() diff --git a/test/README.md b/test/README.md index c8c962d4a46f..b767d82b7608 100644 --- a/test/README.md +++ b/test/README.md @@ -35,15 +35,15 @@ make -j10 run_runnable_tests ### Run only an individual test ```sh -./run_individual_tests fail_compilation/diag10089.d +./run_individual_tests.d fail_compilation/diag10089.d ``` Multiple arguments are supported too. -You can use `./run_individual_tests` to quickly run a custom subset of tests. +You can use `./run_individual_tests.d` to quickly run a custom subset of tests. For example, all diagnostic tests in `fail_compilation`: ```sh -./run_individual_tests fail_compilation/diag*.d +./run_individual_tests.d fail_compilation/diag*.d ``` ### Automatically update the `TEST_OUTPUT` segments @@ -58,7 +58,7 @@ AUTO_UPDATE=1 make run_fail_compilation_tests -j10 Updating the `TEST_OUTPUT` can also be done for a custom subset of tests: ```sh -AUTO_UPDATE=1 ./run_individual_tests fail_compilation/diag*.d +AUTO_UPDATE=1 ./run_individual_tests.d fail_compilation/diag*.d ``` Note: diff --git a/test/run_individual_tests b/test/run_individual_tests deleted file mode 100755 index 109852627e0e..000000000000 --- a/test/run_individual_tests +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env bash -# Allows running tests individually -# Usage: -# ./run_individual_tests ... -# Example: -# ./run_individual_tests runnable/template2962.d fail_compilation/fail282.d - -# See the Makefile for all available test targets - -set -euo pipefail - -# if PROCS is not set, auto-detect or fallback to 4 -PROCS="${PROCS:-$(nproc 2> /dev/null || sysctl -n hw.physicalcpu 2> /dev/null || echo 4)}" - -if [ -z ${1:-} ] ; then - cat >&2 << EOF -./run_individual_tests ... - -Examples: - - ./run_individual_tests runnable/template2962.d - ./run_individual_tests runnable/template2962.d fail_compilation/fail282.d -EOF - exit -fi - -# all test files to be run -files=() - -# normalize path to each test file -for arg in "$@" ; do - file="$arg" - normalizedDir=$(cd "$(dirname "$file")" && pwd) - files+=("test_results/$(basename "$normalizedDir" )/$(basename "$file").out") -done - -# allows the script to be called from anywhere -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $DIR -echo ${PROCS} -${MAKE:-make} "${files[@]}" -j${PROCS} diff --git a/test/run_individual_tests.d b/test/run_individual_tests.d new file mode 100755 index 000000000000..14bb664b1488 --- /dev/null +++ b/test/run_individual_tests.d @@ -0,0 +1,44 @@ +#!/usr/bin/env rdmd +/** +Allows running tests individually + +Usage: + ./run_individual_tests.d ... + +Example: + ./run_individual_tests.d runnable/template2962.d fail_compilation/fail282.d + +See the README.md for all available test targets +*/ + +void main(string[] args) +{ + import std.algorithm, std.conv, std.format, std.getopt, std.path, std.process, std.range, std.stdio, std.string; + import std.parallelism : totalCPUs; + + const scriptDir = __FILE_FULL_PATH__.dirName; + int jobs = totalCPUs; + auto res = getopt(args, + "j|jobs", "Specifies the number of jobs (commands) to run simultaneously (default: %d)".format(totalCPUs), &jobs, + ); + if (res.helpWanted || args.length < 2) + { + defaultGetoptPrinter(`./run_individual_tests.d ... + +Examples: + + ./run_individual_tests.d runnable/template2962.d + ./run_individual_tests.d runnable/template2962.d fail_compilation/fail282.d + +Options: +`, res.options); + "\nSee the README.md for a more in-depth explanation of the test-runner.".writeln; + return; + } + + auto makeArguments = ["make", "--jobs=".text(jobs)] + .chain(args.dropOne.map!(f => + format!"test_results/%s/%s.out"(f.absolutePath.dirName.baseName, f.baseName))) + .array; + spawnProcess(makeArguments, null, Config.none, scriptDir).wait; +}