|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
| 3 | +# test for existence and executability of the test-exercise script |
| 4 | +# this depends on that |
| 5 | +if [ ! -f "./bin/test-exercise" ]; then |
| 6 | + echo "bin/test-exercise does not exist" |
| 7 | + exit 1 |
| 8 | +fi |
| 9 | +if [ ! -x "./bin/test-exercise" ]; then |
| 10 | + echo "bin/test-exercise does not have its executable bit set" |
| 11 | + exit 1 |
| 12 | +fi |
| 13 | + |
3 | 14 | # In DENYWARNINGS mode, do not set -e so that we run all tests.
|
4 | 15 | # This allows us to see all warnings.
|
5 | 16 | if [ -z "$DENYWARNINGS" ]; then
|
6 | 17 | set -e
|
7 | 18 | fi
|
8 | 19 |
|
| 20 | +# can't benchmark with a stable compiler; to bench, use |
| 21 | +# $ BENCHMARK=1 rustup run nightly _test/check-exercises.sh |
9 | 22 | if [ -n "$BENCHMARK" ]; then
|
10 | 23 | files=exercises/*/benches
|
11 | 24 | else
|
12 | 25 | files=exercises/*/tests
|
13 | 26 | fi
|
14 | 27 |
|
15 |
| -tmp=${TMPDIR:-/tmp/} |
16 |
| -mkdir "${tmp}exercises" |
17 |
| - |
18 |
| -exitcode=0 |
19 |
| - |
| 28 | +return_code=0 |
20 | 29 | # An exercise worth testing is defined here as any top level directory with
|
21 | 30 | # a 'tests' directory
|
22 | 31 | for exercise in $files; do
|
23 |
| - # This assumes that exercises are only one directory deep |
24 |
| - # and that the primary module is named the same as the directory |
25 |
| - directory=$(dirname "${exercise}"); |
26 |
| - |
27 |
| - workdir=$(mktemp -d "${tmp}${directory}.XXXXXXXXXX") |
28 |
| - |
29 |
| - cp -R -T $directory $workdir |
30 |
| - |
31 |
| - # Run in subshell to change workdir without affecting current workdir. |
32 |
| - ( |
33 |
| - cd $workdir |
34 |
| - |
35 |
| - cp example.rs src/lib.rs |
36 |
| - |
37 |
| - # Overwrite empty Cargo.toml if an example specific file exists |
38 |
| - if [ -f Cargo-example.toml ]; then |
39 |
| - cp Cargo-example.toml Cargo.toml |
40 |
| - fi |
41 |
| - |
42 |
| - # Forcibly strip all "ignore" statements from the testing files |
43 |
| - for test in tests/*.rs; do |
44 |
| - sed -i '/\[ignore\]/d' $test |
45 |
| - done |
46 |
| - |
47 |
| - # Run benchmarks instead of tests when enabled. |
48 |
| - if [ -n "$BENCHMARK" ]; then |
49 |
| - cargo bench |
50 |
| - elif [ -n "$DENYWARNINGS" ]; then |
51 |
| - sed -i -e '1i #![deny(warnings)]' src/lib.rs |
52 |
| - |
53 |
| - # No-run mode so we see no test output. |
54 |
| - # Quiet mode so we see no compile output |
55 |
| - # (such as "Compiling"/"Downloading"). |
56 |
| - # Compiler errors will still be shown though. |
57 |
| - # Both flags are necessary to keep things quiet. |
58 |
| - cargo test --quiet --no-run |
59 |
| - else |
60 |
| - # Run the test and get the status |
61 |
| - cargo test |
62 |
| - fi |
63 |
| - ) |
64 |
| - |
65 |
| - status=$? |
66 |
| - |
67 |
| - if [ $status -ne 0 ] |
68 |
| - then |
69 |
| - exitcode=1 |
70 |
| - fi |
| 32 | + # This assumes that exercises are only one directory deep |
| 33 | + # and that the primary module is named the same as the directory |
| 34 | + directory=$(dirname "${exercise}"); |
| 35 | + |
| 36 | + if [ -n "$DENYWARNINGS" ]; then |
| 37 | + # No-run mode so we see no test output. |
| 38 | + # Quiet mode so we see no compile output |
| 39 | + # (such as "Compiling"/"Downloading"). |
| 40 | + # Compiler errors will still be shown though. |
| 41 | + # Both flags are necessary to keep things quiet. |
| 42 | + ./bin/test-exercise $directory --quiet --no-run |
| 43 | + return_code=$(($return_code | $?)) |
| 44 | + else |
| 45 | + # Run the test and get the status |
| 46 | + # We use release mode here because, while it somewhat increases |
| 47 | + # the compile time for all exercises, it substantially improves |
| 48 | + # the runtime for certain exercises such as alphametics. |
| 49 | + # Overall this should be an improvement. |
| 50 | + ./bin/test-exercise $directory |
| 51 | + return_code=$(($return_code | $?)) |
| 52 | + fi |
71 | 53 | done
|
72 | 54 |
|
73 |
| -exit $exitcode |
| 55 | +exit $return_code |
0 commit comments