1 | #!/usr/bin/env bash
|
2 | #
|
3 | # Run tests in this directory.
|
4 | #
|
5 | # Usage:
|
6 | # cpp/TEST.sh <function name>
|
7 |
|
8 | set -o nounset
|
9 | set -o pipefail
|
10 | set -o errexit
|
11 |
|
12 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
|
13 | source build/common.sh
|
14 | source test/common.sh # run-test
|
15 |
|
16 | run-test-in-dir() {
|
17 | ### Test hand-written code
|
18 |
|
19 | local rel_path=$1
|
20 | local compiler=${2:-cxx}
|
21 | local variant=${3:-dbg}
|
22 |
|
23 | local bin=_bin/$compiler-$variant/$rel_path
|
24 | ninja $bin
|
25 |
|
26 | local working_dir=_tmp/$rel_path
|
27 | rm -r -f -v $working_dir
|
28 | mkdir -p $working_dir
|
29 |
|
30 | # to test glob()
|
31 | touch $working_dir/{foo,bar,baz}.testdata
|
32 |
|
33 | # TODO: we need a way to pass -t here
|
34 | run-test-bin $bin $working_dir
|
35 | }
|
36 |
|
37 | pre-build() {
|
38 | # TODO: fold this into Ninja so it doesn't invalidate build
|
39 | build/py.sh fastmatch
|
40 | }
|
41 |
|
42 |
|
43 | unit() {
|
44 | ### Run unit tests in this dir; used by test/cpp-unit.sh
|
45 |
|
46 | local variants=(ubsan asan+gcalways)
|
47 | if can-compile-32-bit; then
|
48 | variants+=(asan32+gcalways)
|
49 | else
|
50 | # TODO: CI images need gcc-multilib
|
51 | log "Can't compile 32-bit binaries (gcc-multilib g++-multilib needed on Debian)"
|
52 | fi
|
53 |
|
54 | for variant in "${variants[@]}"; do
|
55 | run-one-test cpp/obj_layout_test '' $variant
|
56 |
|
57 | run-test-in-dir cpp/core_test '' $variant # has testdata
|
58 |
|
59 | run-one-test cpp/data_lang_test '' $variant
|
60 |
|
61 | run-one-test cpp/frontend_flag_spec_test '' $variant
|
62 |
|
63 | run-one-test cpp/frontend_match_test '' $variant
|
64 |
|
65 | run-test-in-dir cpp/libc_test '' $variant # has testdata
|
66 |
|
67 | run-one-test cpp/osh_test '' $variant
|
68 |
|
69 | run-one-test cpp/pylib_test '' $variant
|
70 |
|
71 | run-one-test cpp/stdlib_test '' $variant
|
72 | done
|
73 | }
|
74 |
|
75 | data-race-test() {
|
76 | ### TODO: Expand this to signal state, and make sure it passes!
|
77 |
|
78 | run-one-test cpp/data_race_test '' tsan
|
79 | }
|
80 |
|
81 | coverage() {
|
82 | ### Run coverage for this dir
|
83 |
|
84 | pre-build
|
85 |
|
86 | local compiler=clang
|
87 | local variant=coverage
|
88 |
|
89 | run-one-test cpp/obj_layout_test $compiler $variant
|
90 |
|
91 | run-test-in-dir cpp/core_test $compiler $variant # has testdata
|
92 |
|
93 | run-one-test cpp/data_lang_test $compiler $variant
|
94 |
|
95 | run-one-test cpp/frontend_flag_spec_test $compiler $variant
|
96 |
|
97 | run-one-test cpp/frontend_match_test $compiler $variant
|
98 |
|
99 | run-test-in-dir cpp/libc_test $compiler $variant # has testdata
|
100 |
|
101 | run-one-test cpp/osh_test $compiler $variant
|
102 |
|
103 | run-one-test cpp/pylib_test $compiler $variant
|
104 |
|
105 | run-one-test cpp/stdlib_test $compiler $variant
|
106 |
|
107 | local out_dir=_test/clang-coverage/cpp
|
108 | test/coverage.sh html-report $out_dir clang-coverage/cpp
|
109 | }
|
110 |
|
111 | "$@"
|