Skip to content

Commit

Permalink
Add console.assert (denoland#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
g-plane authored and ry committed Jun 5, 2018
1 parent 71d7891 commit 874db2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
7 changes: 7 additions & 0 deletions globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ _global["console"] = {
// tslint:disable-next-line:no-any
error(...args: any[]): void {
print("ERROR: " + stringifyArgs(args));
},

// tslint:disable-next-line:no-any
assert(condition: boolean, ...args: any[]): void {
if (!condition) {
throw new Error("Assertion failed: " + stringifyArgs(args));
}
}
};

Expand Down
12 changes: 12 additions & 0 deletions tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ test(async function tests_fetch() {
assertEqual(json.name, "deno");
});

test(function tests_console_assert() {
console.assert(true);

let hasThrown = false;
try {
console.assert(false);
} catch {
hasThrown = true;
}
assertEqual(hasThrown, true);
});

test(async function tests_readFileSync() {
const data = readFileSync("package.json");
if (!data.byteLength) {
Expand Down

0 comments on commit 874db2a

Please sign in to comment.