File: helpers.bash.t

package info (click to toggle)
golang-github-containers-buildah 1.39.3%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,724 kB
  • sloc: sh: 2,398; makefile: 236; perl: 187; asm: 16; awk: 12; ansic: 1
file content (87 lines) | stat: -rwxr-xr-x 1,294 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
#
# tests for helpers.bash
#

. $(dirname ${BASH_SOURCE})/helpers.bash

INDEX=1
RC=0

# t (true) : tests that should pass
function t() {
    result=$(assert "$@" 2>&1)
    status=$?

    if [[ $status -eq 0 ]]; then
        echo "ok $INDEX $*"
    else
        echo "not ok $INDEX $*"
        echo "$result"
        RC=1
    fi

    INDEX=$((INDEX + 1))
}

# f (false) : tests that should fail
function f() {
    result=$(assert "$@" 2>&1)
    status=$?

    if [[ $status -ne 0 ]]; then
        echo "ok $INDEX ! $*"
    else
        echo "not ok $INDEX ! $*  [passed, should have failed]"
        RC=1
    fi

    INDEX=$((INDEX + 1))
}



t "" = ""
t "a" != ""
t "" != "a"

t "a" = "a"
t "aa" == "aa"
t "a[b]{c}" = "a[b]{c}"

t "abcde"  =~ "a"
t "abcde"  =~  "b"
t "abcde"  =~   "c"
t "abcde"  =~    "d"
t "abcde"  =~     "e"
t "abcde"  =~ "ab"
t "abcde"  =~ "abc"
t "abcde"  =~ "abcd"
t "abcde"  =~  "bcde"
t "abcde"  =~   "cde"
t "abcde"  =~    "de"

t    "foo"    =~ "foo"
t    "foobar" =~ "foo"
t "barfoo"    =~ "foo"

t 'a "AB \"CD": ef' =  'a "AB \"CD": ef'
t 'a "AB \"CD": ef' =~ 'a "AB \\"CD": ef'

t 'abcdef' !~ 'efg'
t 'abcdef' !~ 'x'

###########

f "a" = "b"
f "a" == "b"

f "abcde" =~ "x"

f "abcde" !~ "a"
f "abcde" !~ "ab"
f "abcde" !~ "abc"

f "" != ""

exit $RC