summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Knight <cknight1234@gmail.com>2020-06-07 14:20:33 +0100
committerGitHub <noreply@github.com>2020-06-07 09:20:33 -0400
commit3ef94c5473ac77366d009c7a7c665f695670f886 (patch)
tree0baa502ca705e9e0a38e013def65f1ab545e643b
parentadffbacfe49aac480fc34e78035200ab9602443c (diff)
refactor(std): remove testing dependencies from non-test code (#5838)
-rw-r--r--std/_util/assert.ts15
-rw-r--r--std/_util/assert_test.ts32
-rw-r--r--std/_util/deep_assign.ts2
-rw-r--r--std/archive/tar.ts2
-rw-r--r--std/datetime/mod.ts2
-rw-r--r--std/encoding/csv.ts2
-rw-r--r--std/encoding/toml.ts2
-rw-r--r--std/flags/mod.ts2
-rw-r--r--std/fs/copy.ts2
-rw-r--r--std/fs/expand_glob.ts2
-rw-r--r--std/fs/walk.ts6
-rw-r--r--std/http/_io.ts2
-rw-r--r--std/http/cookie.ts2
-rwxr-xr-xstd/http/file_server.ts2
-rw-r--r--std/http/server.ts2
-rw-r--r--std/io/bufio.ts2
-rw-r--r--std/io/ioutil.ts2
-rw-r--r--std/log/mod.ts2
-rw-r--r--std/mime/multipart.ts6
-rw-r--r--std/node/_fs/_fs_dir.ts2
-rw-r--r--std/node/events.ts2
-rw-r--r--std/node/module.ts2
-rw-r--r--std/path/glob.ts2
-rw-r--r--std/path/win32.ts2
-rw-r--r--std/uuid/v5.ts2
-rw-r--r--std/ws/mod.ts2
26 files changed, 75 insertions, 28 deletions
diff --git a/std/_util/assert.ts b/std/_util/assert.ts
new file mode 100644
index 000000000..d797591fe
--- /dev/null
+++ b/std/_util/assert.ts
@@ -0,0 +1,15 @@
+// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
+
+export class DenoStdInternalError extends Error {
+ constructor(message: string) {
+ super(message);
+ this.name = "DenoStdInternalError";
+ }
+}
+
+/** Make an assertion, if not `true`, then throw. */
+export function assert(expr: unknown, msg = ""): asserts expr {
+ if (!expr) {
+ throw new DenoStdInternalError(msg);
+ }
+}
diff --git a/std/_util/assert_test.ts b/std/_util/assert_test.ts
new file mode 100644
index 000000000..38aeae91b
--- /dev/null
+++ b/std/_util/assert_test.ts
@@ -0,0 +1,32 @@
+import { assert, DenoStdInternalError } from "./assert.ts";
+import { assertThrows } from "../testing/asserts.ts";
+
+const { test } = Deno;
+
+test({
+ name: "assert valid scenario",
+ fn(): void {
+ assert(true);
+ },
+});
+
+test({
+ name: "assert invalid scenario, no message",
+ fn(): void {
+ assertThrows(() => {
+ assert(false);
+ }, DenoStdInternalError);
+ },
+});
+test({
+ name: "assert invalid scenario, with message",
+ fn(): void {
+ assertThrows(
+ () => {
+ assert(false, "Oops! Should be true");
+ },
+ DenoStdInternalError,
+ "Oops! Should be true"
+ );
+ },
+});
diff --git a/std/_util/deep_assign.ts b/std/_util/deep_assign.ts
index 9034d89bd..ca1f0aba1 100644
--- a/std/_util/deep_assign.ts
+++ b/std/_util/deep_assign.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
export function deepAssign(
target: Record<string, unknown>,
diff --git a/std/archive/tar.ts b/std/archive/tar.ts
index 225bcb769..52af7bd69 100644
--- a/std/archive/tar.ts
+++ b/std/archive/tar.ts
@@ -28,7 +28,7 @@
*/
import { MultiReader } from "../io/readers.ts";
import { BufReader } from "../io/bufio.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
const recordSize = 512;
const ustar = "ustar\u000000";
diff --git a/std/datetime/mod.ts b/std/datetime/mod.ts
index 258388397..7503eccb4 100644
--- a/std/datetime/mod.ts
+++ b/std/datetime/mod.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
export type DateFormat = "mm-dd-yyyy" | "dd-mm-yyyy" | "yyyy-mm-dd";
diff --git a/std/encoding/csv.ts b/std/encoding/csv.ts
index 3e7164cbb..5af054530 100644
--- a/std/encoding/csv.ts
+++ b/std/encoding/csv.ts
@@ -7,7 +7,7 @@
import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { StringReader } from "../io/readers.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
const INVALID_RUNE = ["\r", "\n", '"'];
diff --git a/std/encoding/toml.ts b/std/encoding/toml.ts
index 7e44bdc18..8a0715ab6 100644
--- a/std/encoding/toml.ts
+++ b/std/encoding/toml.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { deepAssign } from "../_util/deep_assign.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
class KeyValuePair {
constructor(public key: string, public value: unknown) {}
diff --git a/std/flags/mod.ts b/std/flags/mod.ts
index e3680087d..5c8fcc0d9 100644
--- a/std/flags/mod.ts
+++ b/std/flags/mod.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
export interface Args {
/** Contains all the arguments that didn't have an option associated with
diff --git a/std/fs/copy.ts b/std/fs/copy.ts
index d45ac17c9..269340e85 100644
--- a/std/fs/copy.ts
+++ b/std/fs/copy.ts
@@ -2,7 +2,7 @@
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
import { isSubdir, getFileInfoType } from "./_util.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
const isWindows = Deno.build.os === "windows";
diff --git a/std/fs/expand_glob.ts b/std/fs/expand_glob.ts
index e5abdabcf..4b7b11885 100644
--- a/std/fs/expand_glob.ts
+++ b/std/fs/expand_glob.ts
@@ -14,7 +14,7 @@ import {
walk,
walkSync,
} from "./walk.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
const { cwd } = Deno;
type FileInfo = Deno.FileInfo;
diff --git a/std/fs/walk.ts b/std/fs/walk.ts
index ccd5097a4..553e52b2e 100644
--- a/std/fs/walk.ts
+++ b/std/fs/walk.ts
@@ -1,7 +1,7 @@
// Documentation and interface for walk were adapted from Go
// https://golang.org/pkg/path/filepath/#Walk
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
-import { unimplemented, assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
import { basename, join, normalize } from "../path/mod.ts";
const { readDir, readDirSync, stat, statSync } = Deno;
@@ -107,7 +107,7 @@ export async function* walk(
if (entry.isSymlink) {
if (followSymlinks) {
// TODO(ry) Re-enable followSymlinks.
- unimplemented();
+ throw new Error("unimplemented");
} else {
continue;
}
@@ -159,7 +159,7 @@ export function* walkSync(
for (const entry of readDirSync(root)) {
if (entry.isSymlink) {
if (followSymlinks) {
- unimplemented();
+ throw new Error("unimplemented");
} else {
continue;
}
diff --git a/std/http/_io.ts b/std/http/_io.ts
index 82954ccee..1db0fc292 100644
--- a/std/http/_io.ts
+++ b/std/http/_io.ts
@@ -1,6 +1,6 @@
import { BufReader, BufWriter } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
import { encoder } from "../encoding/utf8.ts";
import { ServerRequest, Response } from "./server.ts";
import { STATUS_TEXT } from "./http_status.ts";
diff --git a/std/http/cookie.ts b/std/http/cookie.ts
index a138eb350..88a71626c 100644
--- a/std/http/cookie.ts
+++ b/std/http/cookie.ts
@@ -2,7 +2,7 @@
// Structured similarly to Go's cookie.go
// https://github.com/golang/go/blob/master/src/net/http/cookie.go
import { ServerRequest, Response } from "./server.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
import { toIMF } from "../datetime/mod.ts";
export interface Cookies {
diff --git a/std/http/file_server.ts b/std/http/file_server.ts
index 7614c3ab2..66babfd57 100755
--- a/std/http/file_server.ts
+++ b/std/http/file_server.ts
@@ -10,7 +10,7 @@ const { args, stat, readDir, open, exit } = Deno;
import { posix, extname } from "../path/mod.ts";
import { listenAndServe, ServerRequest, Response } from "./server.ts";
import { parse } from "../flags/mod.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
interface EntryInfo {
mode: string;
diff --git a/std/http/server.ts b/std/http/server.ts
index faf5da6af..3cc95a9e4 100644
--- a/std/http/server.ts
+++ b/std/http/server.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { encode } from "../encoding/utf8.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
import { deferred, Deferred, MuxAsyncIterator } from "../async/mod.ts";
import {
bodyReader,
diff --git a/std/io/bufio.ts b/std/io/bufio.ts
index 5c005672a..4ebec13e1 100644
--- a/std/io/bufio.ts
+++ b/std/io/bufio.ts
@@ -7,7 +7,7 @@ type Reader = Deno.Reader;
type Writer = Deno.Writer;
type WriterSync = Deno.WriterSync;
import { charCode, copyBytes } from "./util.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
const DEFAULT_BUF_SIZE = 4096;
const MIN_BUF_SIZE = 16;
diff --git a/std/io/ioutil.ts b/std/io/ioutil.ts
index aff9f05e2..3d9e72b56 100644
--- a/std/io/ioutil.ts
+++ b/std/io/ioutil.ts
@@ -2,7 +2,7 @@
import { BufReader } from "./bufio.ts";
type Reader = Deno.Reader;
type Writer = Deno.Writer;
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
const DEFAULT_BUFFER_SIZE = 32 * 1024;
diff --git a/std/log/mod.ts b/std/log/mod.ts
index 983e82401..e596c81ba 100644
--- a/std/log/mod.ts
+++ b/std/log/mod.ts
@@ -7,7 +7,7 @@ import {
FileHandler,
RotatingFileHandler,
} from "./handlers.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
import { LevelName } from "./levels.ts";
export { LogLevels } from "./levels.ts";
diff --git a/std/mime/multipart.ts b/std/mime/multipart.ts
index 5d9ee7cf9..73a6544b5 100644
--- a/std/mime/multipart.ts
+++ b/std/mime/multipart.ts
@@ -12,7 +12,7 @@ import { extname } from "../path/mod.ts";
import { tempFile } from "../io/util.ts";
import { BufReader, BufWriter } from "../io/bufio.ts";
import { encoder } from "../encoding/utf8.ts";
-import { assertStrictEquals, assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { hasOwnProperty } from "../_util/has_own_property.ts";
@@ -178,7 +178,7 @@ class PartReader implements Reader, Closer {
);
if (this.n === 0) {
// Force buffered I/O to read more into buffer.
- assertStrictEquals(eof, false);
+ assert(eof === false);
peekLength++;
}
}
@@ -190,7 +190,7 @@ class PartReader implements Reader, Closer {
const nread = min(p.length, this.n);
const buf = p.subarray(0, nread);
const r = await br.readFull(buf);
- assertStrictEquals(r, buf);
+ assert(r === buf);
this.n -= nread;
this.total += nread;
return nread;
diff --git a/std/node/_fs/_fs_dir.ts b/std/node/_fs/_fs_dir.ts
index a39422ce0..7f2085b3b 100644
--- a/std/node/_fs/_fs_dir.ts
+++ b/std/node/_fs/_fs_dir.ts
@@ -1,5 +1,5 @@
import Dirent from "./_fs_dirent.ts";
-import { assert } from "../../testing/asserts.ts";
+import { assert } from "../../_util/assert.ts";
export default class Dir {
private dirPath: string | Uint8Array;
diff --git a/std/node/events.ts b/std/node/events.ts
index aa62e4d43..cb9acb0f5 100644
--- a/std/node/events.ts
+++ b/std/node/events.ts
@@ -22,7 +22,7 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
import { validateIntegerRange } from "./util.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
export interface WrappedFunction extends Function {
listener: Function;
diff --git a/std/node/module.ts b/std/node/module.ts
index 8d0160f78..daa01d2b2 100644
--- a/std/node/module.ts
+++ b/std/node/module.ts
@@ -31,7 +31,7 @@ import * as nodeEvents from "./events.ts";
import * as nodeQueryString from "./querystring.ts";
import * as path from "../path/mod.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
import { pathToFileURL, fileURLToPath } from "./url.ts";
const CHAR_FORWARD_SLASH = "/".charCodeAt(0);
diff --git a/std/path/glob.ts b/std/path/glob.ts
index 34fc213f6..c7d23b344 100644
--- a/std/path/glob.ts
+++ b/std/path/glob.ts
@@ -4,7 +4,7 @@
import { SEP, SEP_PATTERN } from "./separator.ts";
import { globrex } from "./_globrex.ts";
import { join, normalize } from "./mod.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
export interface GlobOptions {
extended?: boolean;
diff --git a/std/path/win32.ts b/std/path/win32.ts
index f556c5b73..8e438a79c 100644
--- a/std/path/win32.ts
+++ b/std/path/win32.ts
@@ -17,7 +17,7 @@ import {
normalizeString,
_format,
} from "./_util.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
export const sep = "\\";
export const delimiter = ";";
diff --git a/std/uuid/v5.ts b/std/uuid/v5.ts
index 3c04873fe..f982d9745 100644
--- a/std/uuid/v5.ts
+++ b/std/uuid/v5.ts
@@ -8,7 +8,7 @@ import {
} from "./_common.ts";
import { Sha1 } from "../hash/sha1.ts";
import { isString } from "../node/util.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
diff --git a/std/ws/mod.ts b/std/ws/mod.ts
index f98e70d92..f58828aea 100644
--- a/std/ws/mod.ts
+++ b/std/ws/mod.ts
@@ -8,7 +8,7 @@ import { Sha1 } from "../hash/sha1.ts";
import { writeResponse } from "../http/_io.ts";
import { TextProtoReader } from "../textproto/mod.ts";
import { Deferred, deferred } from "../async/deferred.ts";
-import { assert } from "../testing/asserts.ts";
+import { assert } from "../_util/assert.ts";
import { concat } from "../bytes/mod.ts";
import Conn = Deno.Conn;
import Writer = Deno.Writer;