File: common

package info (click to toggle)
arch-install-scripts 28-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 184 kB
  • sloc: sh: 537; makefile: 41
file content (45 lines) | stat: -rw-r--r-- 694 bytes parent folder | download | duplicates (3)
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
#!/bin/bash

fail=0
testcount=0

EXPECT_success() {
  (( ++testcount ))
  if ! "$@"; then
    (( ++fail ))
    printf 'expectation failed: did not succeed: %s\n' "$*" >&2
  fi
}

EXPECT_failure() {
  (( ++testcount ))
  if "$@"; then
    (( ++fail ))
    printf 'expectation failed: did not fail: %s\n' "$*" >&2
  fi
}

TEST_exit() {
  local result

  trap -- EXIT

  (( fail == 0 )) && result=PASS || result=FAIL

  printf '%s: %s\n' "$result" "$1"

  exit $(( fail != 0 ))
}

ASSERT_streq() {
  if [[ $1 != "$2" ]]; then
    printf 'assertion failed [line %d]: [[ %s = "%s" ]]\n' "$BASH_LINENO" "$1" "$2" >&2
  fi
}

TEST_start() {
  trap "TEST_exit '$1'" EXIT
}

TEST_start "${0##*/test_}"