summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-01-01 22:46:17 -0500
committerRyan Dahl <ry@tinyclouds.org>2019-01-02 13:45:42 -0500
commit6a783ea179de1321ae7fd0586967476e72984c63 (patch)
treecafa2e3716ee3dcfa88354e4a7190cab7e436613
parent6545e5bde9454e9ae7ab61b0f4ee95db8a15e43c (diff)
Add testing module
Original: https://github.com/denoland/deno_std/commit/61fdae51a7cc50874b9674c40b1aef3fbf012494
-rw-r--r--README.md5
-rw-r--r--colors/main_test.ts2
-rw-r--r--examples/test.ts2
-rwxr-xr-xflags/tests/all_bool.ts2
-rwxr-xr-xflags/tests/bool.ts2
-rwxr-xr-xflags/tests/dash.ts2
-rwxr-xr-xflags/tests/default_bool.ts2
-rwxr-xr-xflags/tests/dotted.ts2
-rwxr-xr-xflags/tests/kv_short.ts2
-rwxr-xr-xflags/tests/long.ts2
-rwxr-xr-xflags/tests/num.ts2
-rw-r--r--flags/tests/parse.ts2
-rwxr-xr-xflags/tests/short.ts2
-rwxr-xr-xflags/tests/stop_early.ts2
-rwxr-xr-xflags/tests/unknown.ts2
-rwxr-xr-xflags/tests/whitespace.ts2
-rw-r--r--logging/README.md26
-rw-r--r--logging/test.ts3
-rw-r--r--mkdirp/test.ts2
-rw-r--r--net/bufio_test.ts2
-rw-r--r--net/extension_map.json2
-rw-r--r--net/file_server_test.ts2
-rw-r--r--net/http_test.ts2
-rw-r--r--net/textproto_test.ts2
-rw-r--r--path/basename_test.ts2
-rw-r--r--path/dirname_test.ts2
-rw-r--r--path/extname_test.ts2
-rw-r--r--path/isabsolute_test.ts2
-rw-r--r--path/join_test.ts2
-rw-r--r--path/parse_format_test.ts2
-rw-r--r--path/relative_test.ts2
-rw-r--r--path/resolve_test.ts2
-rw-r--r--path/zero_length_strings_test.ts2
-rwxr-xr-xtest.ts28
-rw-r--r--testing/mod.ts162
-rw-r--r--testing/test.ts57
36 files changed, 275 insertions, 66 deletions
diff --git a/README.md b/README.md
index 995ce9c53..f6c40627a 100644
--- a/README.md
+++ b/README.md
@@ -8,11 +8,12 @@ for Deno.
| Collection | Description |
| --------------------- | --------------------------------------------------------------- |
| [colors](./colors/) | Modules that generate ANSI color codes for the console. |
-| [net](./net/) | A framework for creating HTTP/HTTPS servers inspired by GoLang. |
-| [path](./path/) | File path manipulation. |
| [flags](./flags/) | Command line arguments parser. |
| [logging](./logging/) | Command line logging |
| [mkdirp](./mkdirp/) | Make directory branches. |
+| [net](./net/) | A framework for creating HTTP/HTTPS servers inspired by GoLang. |
+| [path](./path/) | File path manipulation. |
+| [testing](./testing/) | Testing |
---
diff --git a/colors/main_test.ts b/colors/main_test.ts
index 3ca064bb7..2073c7c78 100644
--- a/colors/main_test.ts
+++ b/colors/main_test.ts
@@ -1,4 +1,4 @@
-import { assertEqual, test } from "https://deno.land/x/testing/testing.ts";
+import { assertEqual, test } from "../testing/mod.ts";
import { color } from "main.ts";
import "example.ts";
diff --git a/examples/test.ts b/examples/test.ts
index 4d2dea157..f42db1bba 100644
--- a/examples/test.ts
+++ b/examples/test.ts
@@ -1,5 +1,5 @@
import { run } from "deno";
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
/** Example of how to do basic tests */
test(function t1() {
diff --git a/flags/tests/all_bool.ts b/flags/tests/all_bool.ts
index 879de5cc0..2e0bba4ce 100755
--- a/flags/tests/all_bool.ts
+++ b/flags/tests/all_bool.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
// flag boolean true (default all --args to boolean)
diff --git a/flags/tests/bool.ts b/flags/tests/bool.ts
index ee4f5e1c3..5d135028e 100755
--- a/flags/tests/bool.ts
+++ b/flags/tests/bool.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function flagBooleanDefaultFalse() {
diff --git a/flags/tests/dash.ts b/flags/tests/dash.ts
index 2008cce43..f8cec6ef7 100755
--- a/flags/tests/dash.ts
+++ b/flags/tests/dash.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function hyphen() {
diff --git a/flags/tests/default_bool.ts b/flags/tests/default_bool.ts
index b43c52e8d..8cf6a720b 100755
--- a/flags/tests/default_bool.ts
+++ b/flags/tests/default_bool.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function booleanDefaultTrue() {
diff --git a/flags/tests/dotted.ts b/flags/tests/dotted.ts
index 03f72dc83..94867abb2 100755
--- a/flags/tests/dotted.ts
+++ b/flags/tests/dotted.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function dottedAlias() {
diff --git a/flags/tests/kv_short.ts b/flags/tests/kv_short.ts
index 93aa76387..1050d7734 100755
--- a/flags/tests/kv_short.ts
+++ b/flags/tests/kv_short.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function short() {
diff --git a/flags/tests/long.ts b/flags/tests/long.ts
index 57e48ecbe..41c3e7743 100755
--- a/flags/tests/long.ts
+++ b/flags/tests/long.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function longOpts() {
diff --git a/flags/tests/num.ts b/flags/tests/num.ts
index 66cbcb7ad..0588b51f6 100755
--- a/flags/tests/num.ts
+++ b/flags/tests/num.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function nums() {
diff --git a/flags/tests/parse.ts b/flags/tests/parse.ts
index 29a500868..30551f875 100644
--- a/flags/tests/parse.ts
+++ b/flags/tests/parse.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function _arseArgs() {
diff --git a/flags/tests/short.ts b/flags/tests/short.ts
index 00c9dcc80..dee981351 100755
--- a/flags/tests/short.ts
+++ b/flags/tests/short.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function numbericShortArgs() {
diff --git a/flags/tests/stop_early.ts b/flags/tests/stop_early.ts
index 62725e6cf..ca64bf97e 100755
--- a/flags/tests/stop_early.ts
+++ b/flags/tests/stop_early.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
// stops parsing on the first non-option when stopEarly is set
diff --git a/flags/tests/unknown.ts b/flags/tests/unknown.ts
index ff5f2041c..2c87b18fe 100755
--- a/flags/tests/unknown.ts
+++ b/flags/tests/unknown.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function booleanAndAliasIsNotUnknown() {
diff --git a/flags/tests/whitespace.ts b/flags/tests/whitespace.ts
index f50518b4f..8373cd19e 100755
--- a/flags/tests/whitespace.ts
+++ b/flags/tests/whitespace.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../../testing/mod.ts";
import { parse } from "../index.ts";
test(function whitespaceShouldBeWhitespace() {
diff --git a/logging/README.md b/logging/README.md
index 4d7e95474..1d88cb070 100644
--- a/logging/README.md
+++ b/logging/README.md
@@ -12,27 +12,27 @@ log.critical("500 Internal server error");
// configure as needed
await log.setup({
- handlers: {
- console: new log.handlers.ConsoleHandler("DEBUG"),
- file: new log.handlers.FileHandler("WARNING", "./log.txt"),
- },
+ handlers: {
+ console: new log.handlers.ConsoleHandler("DEBUG"),
+ file: new log.handlers.FileHandler("WARNING", "./log.txt")
+ },
- loggers: {
- default: {
- level: "DEBUG",
- handlers: ["console", "file"],
- }
+ loggers: {
+ default: {
+ level: "DEBUG",
+ handlers: ["console", "file"]
}
+ }
});
// get configured logger
const logger = log.getLogger("default");
-logger.debug("fizz") // <- logs to `console`, because `file` handler requires 'WARNING' level
-logger.warning("buzz") // <- logs to both `console` and `file` handlers
+logger.debug("fizz"); // <- logs to `console`, because `file` handler requires 'WARNING' level
+logger.warning("buzz"); // <- logs to both `console` and `file` handlers
// if you try to use a logger that hasn't been configured
// you're good to go, it gets created automatically with level set to 0
// so no message is logged
const unknownLogger = log.getLogger("mystery");
-unknownLogger.info("foobar") // no-op
-``` \ No newline at end of file
+unknownLogger.info("foobar"); // no-op
+```
diff --git a/logging/test.ts b/logging/test.ts
index 4808b5944..b96a046dd 100644
--- a/logging/test.ts
+++ b/logging/test.ts
@@ -1,6 +1,5 @@
import { remove, open, readAll } from "deno";
-import { assertEqual, test } from "https://deno.land/x/testing/testing.ts";
-
+import { assertEqual, test } from "../testing/mod.ts";
import * as log from "index.ts";
import { FileHandler } from "./handlers.ts";
diff --git a/mkdirp/test.ts b/mkdirp/test.ts
index 9f5d7fb92..a3a4fac03 100644
--- a/mkdirp/test.ts
+++ b/mkdirp/test.ts
@@ -1,5 +1,5 @@
import { cwd, lstat, makeTempDirSync, removeAll, FileInfo } from "deno";
-import { test, assert } from "https://deno.land/x/testing/testing.ts";
+import { test, assert } from "../testing/mod.ts";
import { mkdirp } from "./mkdirp.ts";
let root: string = `${cwd()}/${Date.now()}`; //makeTempDirSync();
diff --git a/net/bufio_test.ts b/net/bufio_test.ts
index 96490a6c9..411f173f4 100644
--- a/net/bufio_test.ts
+++ b/net/bufio_test.ts
@@ -8,7 +8,7 @@ import {
test,
assert,
assertEqual
-} from "https://deno.land/x/testing/testing.ts";
+} from "../testing/mod.ts";
import { BufReader, BufState, BufWriter } from "./bufio.ts";
import * as iotest from "./iotest.ts";
import { charCode, copyBytes, stringsReader } from "./util.ts";
diff --git a/net/extension_map.json b/net/extension_map.json
index 241e8677d..b02517d6b 100644
--- a/net/extension_map.json
+++ b/net/extension_map.json
@@ -82,4 +82,4 @@
".yml": "text/yaml",
".yaml": "text/yaml",
".zip": "application/zip"
-} \ No newline at end of file
+}
diff --git a/net/file_server_test.ts b/net/file_server_test.ts
index 40bec1c4b..36fe8bdc3 100644
--- a/net/file_server_test.ts
+++ b/net/file_server_test.ts
@@ -4,7 +4,7 @@ import {
test,
assert,
assertEqual
-} from "https://deno.land/x/testing/testing.ts";
+} from "../testing/mod.ts";
// Promise to completeResolve when all tests completes
let completeResolve;
diff --git a/net/http_test.ts b/net/http_test.ts
index 93a8049e6..46ea60185 100644
--- a/net/http_test.ts
+++ b/net/http_test.ts
@@ -10,7 +10,7 @@ import {
test,
assert,
assertEqual
-} from "https://deno.land/x/testing/testing.ts";
+} from "../testing/mod.ts";
import {
listenAndServe,
ServerRequest,
diff --git a/net/textproto_test.ts b/net/textproto_test.ts
index 3af21247a..9fe5e8dd3 100644
--- a/net/textproto_test.ts
+++ b/net/textproto_test.ts
@@ -10,7 +10,7 @@ import {
test,
assert,
assertEqual
-} from "https://deno.land/x/testing/testing.ts";
+} from "../testing/mod.ts";
function reader(s: string): TextProtoReader {
return new TextProtoReader(new BufReader(stringsReader(s)));
diff --git a/path/basename_test.ts b/path/basename_test.ts
index a5104106a..b605aa210 100644
--- a/path/basename_test.ts
+++ b/path/basename_test.ts
@@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
test(function basename() {
diff --git a/path/dirname_test.ts b/path/dirname_test.ts
index 8e92c4498..e535ec891 100644
--- a/path/dirname_test.ts
+++ b/path/dirname_test.ts
@@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
test(function dirname() {
diff --git a/path/extname_test.ts b/path/extname_test.ts
index c9a4a68f4..0d6d283a8 100644
--- a/path/extname_test.ts
+++ b/path/extname_test.ts
@@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
const slashRE = /\//g;
diff --git a/path/isabsolute_test.ts b/path/isabsolute_test.ts
index 38eddd5e8..548819ac0 100644
--- a/path/isabsolute_test.ts
+++ b/path/isabsolute_test.ts
@@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
test(function isAbsolute() {
diff --git a/path/join_test.ts b/path/join_test.ts
index 2c98592f5..25e302eba 100644
--- a/path/join_test.ts
+++ b/path/join_test.ts
@@ -1,4 +1,4 @@
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
const backslashRE = /\\/g;
diff --git a/path/parse_format_test.ts b/path/parse_format_test.ts
index 75c3ff00a..1b5e5908a 100644
--- a/path/parse_format_test.ts
+++ b/path/parse_format_test.ts
@@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
const winPaths = [
diff --git a/path/relative_test.ts b/path/relative_test.ts
index 2e4b455f7..dcf8fed98 100644
--- a/path/relative_test.ts
+++ b/path/relative_test.ts
@@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
const relativeTests = {
diff --git a/path/resolve_test.ts b/path/resolve_test.ts
index b734560b9..b365d40b0 100644
--- a/path/resolve_test.ts
+++ b/path/resolve_test.ts
@@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
import { cwd } from "deno";
diff --git a/path/zero_length_strings_test.ts b/path/zero_length_strings_test.ts
index 8774c51f7..f9b357bf1 100644
--- a/path/zero_length_strings_test.ts
+++ b/path/zero_length_strings_test.ts
@@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
-import { test, assertEqual } from "https://deno.land/x/testing/testing.ts";
+import { test, assertEqual } from "../testing/mod.ts";
import * as path from "./index.ts";
import { cwd } from "deno";
diff --git a/test.ts b/test.ts
index 25178ecc6..4c7f763af 100755
--- a/test.ts
+++ b/test.ts
@@ -1,27 +1,14 @@
#!/usr/bin/env deno --allow-run --allow-net --allow-write
import { run } from "deno";
-// colors tests
import "colors/main_test.ts";
-
-// flags tests
+import "examples/test.ts";
import "flags/test.ts";
-
-// net tests
+import "logging/test.ts";
+import "mkdirp/test.ts";
import "net/bufio_test.ts";
import "net/http_test.ts";
import "net/textproto_test.ts";
-import "examples/test.ts";
-import { runTests, completePromise } from "net/file_server_test.ts";
-
-// logging tests
-import "logging/test.ts";
-
-// file server test
-const fileServer = run({
- args: ["deno", "--allow-net", "net/file_server.ts", ".", "--cors"]
-});
-// path test
import "path/basename_test.ts";
import "path/dirname_test.ts";
import "path/extname_test.ts";
@@ -31,11 +18,14 @@ import "path/parse_format_test.ts";
import "path/relative_test.ts";
import "path/resolve_test.ts";
import "path/zero_length_strings_test.ts";
+import "testing/test.ts";
-// mkdirp tests
-import "mkdirp/test.ts";
+import { runTests, completePromise } from "net/file_server_test.ts";
+
+const fileServer = run({
+ args: ["deno", "--allow-net", "net/file_server.ts", ".", "--cors"]
+});
-// I am also too lazy to do this properly LOL
runTests(new Promise(res => setTimeout(res, 5000)));
(async () => {
await completePromise;
diff --git a/testing/mod.ts b/testing/mod.ts
new file mode 100644
index 000000000..f33e743fc
--- /dev/null
+++ b/testing/mod.ts
@@ -0,0 +1,162 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+
+// Do not add imports in this file in order to be compatible with Node.
+
+export function assertEqual(actual: unknown, expected: unknown, msg?: string) {
+ if (!equal(actual, expected)) {
+ let actualString: string;
+ let expectedString: string;
+ try {
+ actualString = String(actual);
+ } catch (e) {
+ actualString = "[Cannot display]";
+ }
+ try {
+ expectedString = String(expected);
+ } catch (e) {
+ expectedString = "[Cannot display]";
+ }
+ console.error(
+ "assertEqual failed. actual =",
+ actualString,
+ "expected =",
+ expectedString
+ );
+ if (!msg) {
+ msg = `actual: ${actualString} expected: ${expectedString}`;
+ }
+ throw new Error(msg);
+ }
+}
+
+export function assert(expr: boolean, msg = "") {
+ if (!expr) {
+ throw new Error(msg);
+ }
+}
+
+// TODO(ry) Use unknown here for parameters types.
+// tslint:disable-next-line:no-any
+export function equal(c: any, d: any): boolean {
+ const seen = new Map();
+ return (function compare(a, b) {
+ if (Object.is(a, b)) {
+ return true;
+ }
+ if (a && typeof a === "object" && b && typeof b === "object") {
+ if (seen.get(a) === b) {
+ return true;
+ }
+ if (Object.keys(a).length !== Object.keys(b).length) {
+ return false;
+ }
+ for (const key in { ...a, ...b }) {
+ if (!compare(a[key], b[key])) {
+ return false;
+ }
+ }
+ seen.set(a, b);
+ return true;
+ }
+ return false;
+ })(c, d);
+}
+
+export type TestFunction = () => void | Promise<void>;
+
+export interface TestDefinition {
+ fn: TestFunction;
+ name: string;
+}
+
+export const exitOnFail = true;
+
+let filterRegExp: RegExp | null;
+const tests: TestDefinition[] = [];
+
+let filtered = 0;
+const ignored = 0;
+const measured = 0;
+
+// Must be called before any test() that needs to be filtered.
+export function setFilter(s: string): void {
+ filterRegExp = new RegExp(s, "i");
+}
+
+export function test(t: TestDefinition | TestFunction): void {
+ const fn: TestFunction = typeof t === "function" ? t : t.fn;
+ const name: string = t.name;
+
+ if (!name) {
+ throw new Error("Test function may not be anonymous");
+ }
+ if (filter(name)) {
+ tests.push({ fn, name });
+ } else {
+ filtered++;
+ }
+}
+
+function filter(name: string): boolean {
+ if (filterRegExp) {
+ return filterRegExp.test(name);
+ } else {
+ return true;
+ }
+}
+
+const RESET = "\x1b[0m";
+const FG_RED = "\x1b[31m";
+const FG_GREEN = "\x1b[32m";
+
+function red_failed() {
+ return FG_RED + "FAILED" + RESET;
+}
+
+function green_ok() {
+ return FG_GREEN + "ok" + RESET;
+}
+
+async function runTests() {
+ let passed = 0;
+ let failed = 0;
+
+ console.log("running", tests.length, "tests");
+ for (let i = 0; i < tests.length; i++) {
+ const { fn, name } = tests[i];
+ let result = green_ok();
+ console.log("test", name);
+ try {
+ await fn();
+ passed++;
+ } catch (e) {
+ result = red_failed();
+ console.error((e && e.stack) || e);
+ failed++;
+ if (exitOnFail) {
+ break;
+ }
+ }
+ // TODO Do this on the same line as test name is printed.
+ console.log("...", result);
+ }
+
+ // Attempting to match the output of Rust's test runner.
+ const result = failed > 0 ? red_failed() : green_ok();
+ console.log(
+ `\ntest result: ${result}. ${passed} passed; ${failed} failed; ` +
+ `${ignored} ignored; ${measured} measured; ${filtered} filtered out\n`
+ );
+
+ if (failed === 0) {
+ // All good.
+ } else {
+ // Use setTimeout to avoid the error being ignored due to unhandled
+ // promise rejections being swallowed.
+ setTimeout(() => {
+ throw new Error(`There were ${failed} test failures.`);
+ }, 0);
+ }
+}
+
+setTimeout(runTests, 0);
diff --git a/testing/test.ts b/testing/test.ts
new file mode 100644
index 000000000..7012a6e47
--- /dev/null
+++ b/testing/test.ts
@@ -0,0 +1,57 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+
+import { test, assert, assertEqual, equal } from "./mod.ts";
+
+test(function testingEqual() {
+ assert(equal("world", "world"));
+ assert(!equal("hello", "world"));
+ assert(equal(5, 5));
+ assert(!equal(5, 6));
+ assert(equal(NaN, NaN));
+ assert(equal({ hello: "world" }, { hello: "world" }));
+ assert(!equal({ world: "hello" }, { hello: "world" }));
+ assert(
+ equal(
+ { hello: "world", hi: { there: "everyone" } },
+ { hello: "world", hi: { there: "everyone" } }
+ )
+ );
+ assert(
+ !equal(
+ { hello: "world", hi: { there: "everyone" } },
+ { hello: "world", hi: { there: "everyone else" } }
+ )
+ );
+});
+
+test(function testingAssertEqual() {
+ const a = Object.create(null);
+ a.b = "foo";
+ assertEqual(a, a);
+});
+
+test(function testingAssertEqualActualUncoercable() {
+ let didThrow = false;
+ const a = Object.create(null);
+ try {
+ assertEqual(a, "bar");
+ } catch (e) {
+ didThrow = true;
+ console.log(e.message);
+ assert(e.message === "actual: [Cannot display] expected: bar");
+ }
+ assert(didThrow);
+});
+
+test(function testingAssertEqualExpectedUncoercable() {
+ let didThrow = false;
+ const a = Object.create(null);
+ try {
+ assertEqual("bar", a);
+ } catch (e) {
+ didThrow = true;
+ console.log(e.message);
+ assert(e.message === "actual: bar expected: [Cannot display]");
+ }
+ assert(didThrow);
+});