summaryrefslogtreecommitdiff
path: root/share/bash/template/assert.sh
blob: ccfd09a05db53ebc4be3547d1119339aee3c186c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/bash

# Check two values for equality and give an error if they are not equal
assert_eq() {
    if ! diff -u <(echo "$1") <(echo "$2")
    then
        echo "expected values to be identical, but they're not"
        return 1
    fi
}

# Check first value contains second value.
assert_contains() {
    if ! echo "$1" | grep -F "$2" > /dev/null
    then
        echo "expected first value to contain second value"
        return 1
    fi
}