William A. Kennington III | 6fae14e | 2021-04-20 00:08:40 -0700 | [diff] [blame] | 1 | #!/bin/bash |
William A. Kennington III | e1e58f4 | 2023-06-05 14:18:40 -0700 | [diff] [blame] | 2 | # shellcheck disable=SC2317 |
William A. Kennington III | 6fae14e | 2021-04-20 00:08:40 -0700 | [diff] [blame] | 3 | # Copyright 2021 Google LLC |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
William A. Kennington III | e1e58f4 | 2023-06-05 14:18:40 -0700 | [diff] [blame] | 17 | # shellcheck source=meta-google/recipes-google/test/test-sh/lib.sh |
William A. Kennington III | 6fae14e | 2021-04-20 00:08:40 -0700 | [diff] [blame] | 18 | source "$(dirname "$0")/lib.sh" || exit |
| 19 | |
| 20 | ( |
| 21 | echo '## Test Pass' >&2 |
| 22 | test_pass() { |
| 23 | return 0 |
| 24 | } |
| 25 | main || exit |
| 26 | ) || exit |
| 27 | |
| 28 | ( |
| 29 | echo '## Test Fail' >&2 |
| 30 | i=0 |
| 31 | test_pass1() { |
| 32 | (( i++ )) |
| 33 | return 0 |
| 34 | } |
| 35 | test_fail() { |
| 36 | return 1 |
| 37 | (( i++ )) |
| 38 | return 0 |
| 39 | } |
| 40 | test_pass2() { |
| 41 | (( i++ )) |
| 42 | return 0 |
| 43 | } |
| 44 | ! main || exit |
| 45 | (( i == 2 )) || exit |
| 46 | ) || exit |
| 47 | |
| 48 | ( |
| 49 | echo '## Test Deferred Fail' >&2 |
| 50 | i=0 |
| 51 | test_expect_fail() { |
| 52 | test_err=1 || return |
| 53 | (( i++ )) |
| 54 | return 0 |
| 55 | } |
| 56 | test_pass() { |
| 57 | (( i++ )) |
| 58 | return 0 |
| 59 | } |
| 60 | ! main || exit |
| 61 | (( i == 2 )) || exit |
| 62 | ) || exit |
| 63 | |
| 64 | ( |
| 65 | echo '## Test Fail' >&2 |
| 66 | i=0 |
| 67 | test_fail() { |
| 68 | fail 'Failed' || return |
| 69 | (( i++ )) |
| 70 | return 0 |
| 71 | } |
| 72 | ! main || exit |
| 73 | (( i == 1 )) || exit |
| 74 | ) || exit |
| 75 | |
| 76 | ( |
| 77 | echo '## Test Expect Err' >&2 |
| 78 | i=0 |
| 79 | test_expect_err() { |
| 80 | expect_err 1 false || return |
| 81 | (( i++ )) |
| 82 | return 0 |
| 83 | } |
| 84 | main || exit |
| 85 | (( i == 1 )) || exit |
| 86 | ) || exit |
| 87 | |
| 88 | ( |
| 89 | echo '## Test Expect Err Error' >&2 |
| 90 | i=0 |
| 91 | test_expect_err() { |
| 92 | expect_err 0 false || return |
| 93 | (( i++ )) |
| 94 | return 0 |
| 95 | } |
| 96 | ! main || exit |
| 97 | (( i == 1 )) || exit |
| 98 | ) || exit |
| 99 | |
| 100 | ( |
| 101 | echo '## Test Num EQ' >&2 |
| 102 | i=0 |
| 103 | test_num_eq() { |
| 104 | expect_numeq 15 0xf || return |
| 105 | expect_numeq 1 1 || return |
| 106 | (( i++ )) |
| 107 | return 0 |
| 108 | } |
| 109 | main || exit |
| 110 | (( i == 1 )) || exit |
| 111 | ) || exit |
| 112 | |
| 113 | ( |
| 114 | echo '## Test Num EQ Error' >&2 |
| 115 | i=0 |
| 116 | test_num_eq() { |
| 117 | expect_numeq 15 10 || return |
| 118 | (( i++ )) |
| 119 | return 0 |
| 120 | } |
| 121 | ! main || exit |
| 122 | (( i == 1 )) || exit |
| 123 | ) || exit |
| 124 | |
| 125 | ( |
| 126 | echo '## Test Str EQ' >&2 |
| 127 | i=0 |
| 128 | test_str_eq() { |
| 129 | expect_streq abz abz || return |
| 130 | (( i++ )) |
| 131 | return 0 |
| 132 | } |
| 133 | main || exit |
| 134 | (( i == 1 )) || exit |
| 135 | ) || exit |
| 136 | |
| 137 | ( |
| 138 | echo '## Test Str EQ Error' >&2 |
| 139 | i=0 |
| 140 | test_str_eq() { |
| 141 | expect_streq 15 0xf || return |
| 142 | (( i++ )) |
| 143 | return 0 |
| 144 | } |
| 145 | ! main || exit |
| 146 | (( i == 1 )) || exit |
| 147 | ) || exit |