File: run_unit_tests.sh

package info (click to toggle)
dd-opentracing-cpp 1.3.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,336 kB
  • sloc: cpp: 44,895; sh: 697; ansic: 27; makefile: 20
file content (69 lines) | stat: -rwxr-xr-x 1,479 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash

usage() {
  cat <<'END_USAGE'
Build and run the unit tests.

Options:

  --coverage
    Build the code and tests with instrumentation for tracking source code
    coverage.

  --verbose
    Emit verbose output.  Pass the VERBOSE=1 option to `make` when building,
    and pass the `--verbose` flag to `ctest` when running the tests.
  
  --build-only
    Don't run the tests, just build them.

  --help
  -h
    Print this message.
END_USAGE
}

# Exit if any non-conditional command returns a nonzero exit status.
set -e

cmake_flags=('-DBUILD_TESTING=ON' '-DCMAKE_BUILD_TYPE=Debug')
make_flags=("--jobs=${MAKE_JOB_COUNT:-$(nproc)}")
ctest_flags=('--output-on-failure')
build_only=0

# Parse command line options.
while [ $# -gt 0 ]; do
  case "$1" in
    -h|--help)
      usage
      exit ;;
    --coverage)
      cmake_flags+=('-DBUILD_COVERAGE=ON') ;;
    --verbose)
      make_flags+=('VERBOSE=1')
      ctest_flags+=('--verbose') ;;
    --build-only)
      build_only=1 ;;
    *)
      >&2 usage 
      >&2 printf "\nUnknown option: %s\n" "$1"
      exit 1
  esac
  shift
done

# Get to the root of the repository.
cd "$(dirname "$0")"
cd "$(git rev-parse --show-toplevel)"

# Default build directory is ".build", but you might prefer another (e.g.
# VSCode uses "build").
BUILD_DIR="${BUILD_DIR:-.build}"

mkdir -p "$BUILD_DIR"
cd "$BUILD_DIR"
cmake "${cmake_flags[@]}" ..
make "${make_flags[@]}"
if [ "$build_only" -ne 1 ]; then
  ctest "${ctest_flags[@]}"
fi