(fail_message: string, user_message: string | undefined, args: any[])
| 45 | } |
| 46 | |
| 47 | function fail(fail_message: string, user_message: string | undefined, args: any[]): never { |
| 48 | // Assertions will look like: |
| 49 | // Assertion failed |
| 50 | // Assertion failed: Foobar |
| 51 | // Assertion failed: Foobar, [{"foo": "bar"}] |
| 52 | let assert_line = fail_message; |
| 53 | if (user_message) { |
| 54 | assert_line += `: ${user_message}`; |
| 55 | } |
| 56 | if (args.length > 0) { |
| 57 | try { |
| 58 | assert_line += ', ' + JSON.stringify(args); |
| 59 | } catch {} |
| 60 | } |
| 61 | |
| 62 | const diagnostic = get_diagnostic(); |
| 63 | if (diagnostic) { |
| 64 | throw new Error(assert_line + `, at ${diagnostic.file}:${diagnostic.line}`); |
| 65 | } |
| 66 | throw new Error(assert_line); |
| 67 | } |
| 68 | |
| 69 | export function assert(c: unknown, message?: string, ...extra_info: any[]): asserts c { |
| 70 | if (!c) { |
no test coverage detected