CheckEqual checks that the string value is equal to some reference.
(val, ref string)
| 136 | |
| 137 | // CheckEqual checks that the string value is equal to some reference. |
| 138 | func (t *T) CheckStringEqual(val, ref string) { |
| 139 | t.Helper() |
| 140 | if val != ref { |
| 141 | pat := regexp.QuoteMeta(ref) |
| 142 | pat = strings.ReplaceAll(pat, "\n", `\n`) |
| 143 | pat = strings.ReplaceAll(pat, "'", `'"'"'`) |
| 144 | pat = strings.ReplaceAll(pat, "\t", `\t`) |
| 145 | repl := strings.ReplaceAll(val, "\n", `\n`) |
| 146 | repl = strings.ReplaceAll(repl, "'", `'"'"'`) |
| 147 | repl = strings.ReplaceAll(repl, "\t", `\t`) |
| 148 | _, file, _, _ := runtime.Caller(1) |
| 149 | t.failWithf(false, "values not equal; got:\n %s\nexpected:\n %s\nTo update expected, run:\n perl -0777 -pi -ne 's@%s@%s@ms' %s", |
| 150 | strings.ReplaceAll(val, "\n", "\n "), |
| 151 | strings.ReplaceAll(ref, "\n", "\n "), |
| 152 | pat, repl, file, |
| 153 | ) |
| 154 | |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // CheckDeepEqual checks that the value is equal to some reference. |
| 159 | func (t *T) CheckDeepEqual(val, ref interface{}) { |