mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 21:54:42 +00:00
vscode: add equality assertion
This commit is contained in:
parent
9cf2577054
commit
3ad0574d7e
2 changed files with 12 additions and 2 deletions
|
@ -1,10 +1,10 @@
|
||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { promises as fs } from "fs";
|
import { promises as fs } from "fs";
|
||||||
import { strict as assert } from "assert";
|
|
||||||
|
|
||||||
import { ArtifactReleaseInfo } from "./interfaces";
|
import { ArtifactReleaseInfo } from "./interfaces";
|
||||||
import { downloadFile } from "./download_file";
|
import { downloadFile } from "./download_file";
|
||||||
|
import { assert } from "../util";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Downloads artifact from given `downloadUrl`.
|
* Downloads artifact from given `downloadUrl`.
|
||||||
|
@ -19,7 +19,7 @@ export async function downloadArtifact(
|
||||||
installationDir: string,
|
installationDir: string,
|
||||||
displayName: string,
|
displayName: string,
|
||||||
) {
|
) {
|
||||||
await fs.mkdir(installationDir).catch(err => assert.strictEqual(
|
await fs.mkdir(installationDir).catch(err => assert.eq(
|
||||||
err?.code,
|
err?.code,
|
||||||
"EEXIST",
|
"EEXIST",
|
||||||
`Couldn't create directory "${installationDir}" to download ` +
|
`Couldn't create directory "${installationDir}" to download ` +
|
||||||
|
|
|
@ -11,6 +11,16 @@ export function assert(condition: unknown, explanation: string): asserts conditi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert.eq = <T>(bibba: unknown, bobba: T, explanation: string): asserts bibba is T => {
|
||||||
|
try {
|
||||||
|
nativeAssert.strictEqual(bibba, bobba, explanation);
|
||||||
|
} catch (err) {
|
||||||
|
log.error(`Equality assertion failed:`, explanation);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export const log = {
|
export const log = {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
debug(message?: any, ...optionalParams: any[]): void {
|
debug(message?: any, ...optionalParams: any[]): void {
|
||||||
|
|
Loading…
Reference in a new issue