summaryrefslogtreecommitdiff
path: root/share/bash/template/assert.sh
blob: 17aa71e624fd31e97ef0d180834c10a2ea83a030 (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 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
}