diff options
author | Veetaha <[email protected]> | 2020-02-28 22:26:22 +0000 |
---|---|---|
committer | Veetaha <[email protected]> | 2020-02-28 22:26:22 +0000 |
commit | 3ad0574d7e3f1af1e28f7f5cbc085faa30759e47 (patch) | |
tree | de0192925c1b4bcdad592401771fe4344b11a3e7 /editors | |
parent | 9cf25770542dfbf35c710f7c214f65ecaad39100 (diff) |
vscode: add equality assertion
Diffstat (limited to 'editors')
-rw-r--r-- | editors/code/src/installation/download_artifact.ts | 4 | ||||
-rw-r--r-- | editors/code/src/util.ts | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/editors/code/src/installation/download_artifact.ts b/editors/code/src/installation/download_artifact.ts index 8ed99bf0a..c60014c8c 100644 --- a/editors/code/src/installation/download_artifact.ts +++ b/editors/code/src/installation/download_artifact.ts | |||
@@ -1,10 +1,10 @@ | |||
1 | import * as vscode from "vscode"; | 1 | import * as vscode from "vscode"; |
2 | import * as path from "path"; | 2 | import * as path from "path"; |
3 | import { promises as fs } from "fs"; | 3 | import { promises as fs } from "fs"; |
4 | import { strict as assert } from "assert"; | ||
5 | 4 | ||
6 | import { ArtifactReleaseInfo } from "./interfaces"; | 5 | import { ArtifactReleaseInfo } from "./interfaces"; |
7 | import { downloadFile } from "./download_file"; | 6 | import { downloadFile } from "./download_file"; |
7 | import { assert } from "../util"; | ||
8 | 8 | ||
9 | /** | 9 | /** |
10 | * Downloads artifact from given `downloadUrl`. | 10 | * Downloads artifact from given `downloadUrl`. |
@@ -19,7 +19,7 @@ export async function downloadArtifact( | |||
19 | installationDir: string, | 19 | installationDir: string, |
20 | displayName: string, | 20 | displayName: string, |
21 | ) { | 21 | ) { |
22 | await fs.mkdir(installationDir).catch(err => assert.strictEqual( | 22 | await fs.mkdir(installationDir).catch(err => assert.eq( |
23 | err?.code, | 23 | err?.code, |
24 | "EEXIST", | 24 | "EEXIST", |
25 | `Couldn't create directory "${installationDir}" to download ` + | 25 | `Couldn't create directory "${installationDir}" to download ` + |
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts index 733bdc8c5..5a5f11a10 100644 --- a/editors/code/src/util.ts +++ b/editors/code/src/util.ts | |||
@@ -11,6 +11,16 @@ export function assert(condition: unknown, explanation: string): asserts conditi | |||
11 | } | 11 | } |
12 | } | 12 | } |
13 | 13 | ||
14 | assert.eq = <T>(bibba: unknown, bobba: T, explanation: string): asserts bibba is T => { | ||
15 | try { | ||
16 | nativeAssert.strictEqual(bibba, bobba, explanation); | ||
17 | } catch (err) { | ||
18 | log.error(`Equality assertion failed:`, explanation); | ||
19 | throw err; | ||
20 | } | ||
21 | } | ||
22 | |||
23 | |||
14 | export const log = { | 24 | export const log = { |
15 | enabled: true, | 25 | enabled: true, |
16 | debug(message?: any, ...optionalParams: any[]): void { | 26 | debug(message?: any, ...optionalParams: any[]): void { |