mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
refactor(std): remove testing dependencies from non-test code (#5838)
This commit is contained in:
parent
adffbacfe4
commit
3ef94c5473
26 changed files with 75 additions and 28 deletions
15
std/_util/assert.ts
Normal file
15
std/_util/assert.ts
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
32
std/_util/assert_test.ts
Normal file
32
std/_util/assert_test.ts
Normal file
|
@ -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"
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// 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(
|
export function deepAssign(
|
||||||
target: Record<string, unknown>,
|
target: Record<string, unknown>,
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*/
|
*/
|
||||||
import { MultiReader } from "../io/readers.ts";
|
import { MultiReader } from "../io/readers.ts";
|
||||||
import { BufReader } from "../io/bufio.ts";
|
import { BufReader } from "../io/bufio.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
const recordSize = 512;
|
const recordSize = 512;
|
||||||
const ustar = "ustar\u000000";
|
const ustar = "ustar\u000000";
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// 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";
|
export type DateFormat = "mm-dd-yyyy" | "dd-mm-yyyy" | "yyyy-mm-dd";
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
import { BufReader } from "../io/bufio.ts";
|
import { BufReader } from "../io/bufio.ts";
|
||||||
import { TextProtoReader } from "../textproto/mod.ts";
|
import { TextProtoReader } from "../textproto/mod.ts";
|
||||||
import { StringReader } from "../io/readers.ts";
|
import { StringReader } from "../io/readers.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
const INVALID_RUNE = ["\r", "\n", '"'];
|
const INVALID_RUNE = ["\r", "\n", '"'];
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { deepAssign } from "../_util/deep_assign.ts";
|
import { deepAssign } from "../_util/deep_assign.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
class KeyValuePair {
|
class KeyValuePair {
|
||||||
constructor(public key: string, public value: unknown) {}
|
constructor(public key: string, public value: unknown) {}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// 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 {
|
export interface Args {
|
||||||
/** Contains all the arguments that didn't have an option associated with
|
/** Contains all the arguments that didn't have an option associated with
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import * as path from "../path/mod.ts";
|
import * as path from "../path/mod.ts";
|
||||||
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
|
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
|
||||||
import { isSubdir, getFileInfoType } from "./_util.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";
|
const isWindows = Deno.build.os === "windows";
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import {
|
||||||
walk,
|
walk,
|
||||||
walkSync,
|
walkSync,
|
||||||
} from "./walk.ts";
|
} from "./walk.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
const { cwd } = Deno;
|
const { cwd } = Deno;
|
||||||
type FileInfo = Deno.FileInfo;
|
type FileInfo = Deno.FileInfo;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Documentation and interface for walk were adapted from Go
|
// Documentation and interface for walk were adapted from Go
|
||||||
// https://golang.org/pkg/path/filepath/#Walk
|
// https://golang.org/pkg/path/filepath/#Walk
|
||||||
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
|
// 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";
|
import { basename, join, normalize } from "../path/mod.ts";
|
||||||
const { readDir, readDirSync, stat, statSync } = Deno;
|
const { readDir, readDirSync, stat, statSync } = Deno;
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ export async function* walk(
|
||||||
if (entry.isSymlink) {
|
if (entry.isSymlink) {
|
||||||
if (followSymlinks) {
|
if (followSymlinks) {
|
||||||
// TODO(ry) Re-enable followSymlinks.
|
// TODO(ry) Re-enable followSymlinks.
|
||||||
unimplemented();
|
throw new Error("unimplemented");
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ export function* walkSync(
|
||||||
for (const entry of readDirSync(root)) {
|
for (const entry of readDirSync(root)) {
|
||||||
if (entry.isSymlink) {
|
if (entry.isSymlink) {
|
||||||
if (followSymlinks) {
|
if (followSymlinks) {
|
||||||
unimplemented();
|
throw new Error("unimplemented");
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { BufReader, BufWriter } from "../io/bufio.ts";
|
import { BufReader, BufWriter } from "../io/bufio.ts";
|
||||||
import { TextProtoReader } from "../textproto/mod.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 { encoder } from "../encoding/utf8.ts";
|
||||||
import { ServerRequest, Response } from "./server.ts";
|
import { ServerRequest, Response } from "./server.ts";
|
||||||
import { STATUS_TEXT } from "./http_status.ts";
|
import { STATUS_TEXT } from "./http_status.ts";
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Structured similarly to Go's cookie.go
|
// Structured similarly to Go's cookie.go
|
||||||
// https://github.com/golang/go/blob/master/src/net/http/cookie.go
|
// https://github.com/golang/go/blob/master/src/net/http/cookie.go
|
||||||
import { ServerRequest, Response } from "./server.ts";
|
import { ServerRequest, Response } from "./server.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
import { toIMF } from "../datetime/mod.ts";
|
import { toIMF } from "../datetime/mod.ts";
|
||||||
|
|
||||||
export interface Cookies {
|
export interface Cookies {
|
||||||
|
|
|
@ -10,7 +10,7 @@ const { args, stat, readDir, open, exit } = Deno;
|
||||||
import { posix, extname } from "../path/mod.ts";
|
import { posix, extname } from "../path/mod.ts";
|
||||||
import { listenAndServe, ServerRequest, Response } from "./server.ts";
|
import { listenAndServe, ServerRequest, Response } from "./server.ts";
|
||||||
import { parse } from "../flags/mod.ts";
|
import { parse } from "../flags/mod.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
interface EntryInfo {
|
interface EntryInfo {
|
||||||
mode: string;
|
mode: string;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
import { encode } from "../encoding/utf8.ts";
|
import { encode } from "../encoding/utf8.ts";
|
||||||
import { BufReader, BufWriter } from "../io/bufio.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 { deferred, Deferred, MuxAsyncIterator } from "../async/mod.ts";
|
||||||
import {
|
import {
|
||||||
bodyReader,
|
bodyReader,
|
||||||
|
|
|
@ -7,7 +7,7 @@ type Reader = Deno.Reader;
|
||||||
type Writer = Deno.Writer;
|
type Writer = Deno.Writer;
|
||||||
type WriterSync = Deno.WriterSync;
|
type WriterSync = Deno.WriterSync;
|
||||||
import { charCode, copyBytes } from "./util.ts";
|
import { charCode, copyBytes } from "./util.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
const DEFAULT_BUF_SIZE = 4096;
|
const DEFAULT_BUF_SIZE = 4096;
|
||||||
const MIN_BUF_SIZE = 16;
|
const MIN_BUF_SIZE = 16;
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
import { BufReader } from "./bufio.ts";
|
import { BufReader } from "./bufio.ts";
|
||||||
type Reader = Deno.Reader;
|
type Reader = Deno.Reader;
|
||||||
type Writer = Deno.Writer;
|
type Writer = Deno.Writer;
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
const DEFAULT_BUFFER_SIZE = 32 * 1024;
|
const DEFAULT_BUFFER_SIZE = 32 * 1024;
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import {
|
||||||
FileHandler,
|
FileHandler,
|
||||||
RotatingFileHandler,
|
RotatingFileHandler,
|
||||||
} from "./handlers.ts";
|
} from "./handlers.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
import { LevelName } from "./levels.ts";
|
import { LevelName } from "./levels.ts";
|
||||||
|
|
||||||
export { LogLevels } from "./levels.ts";
|
export { LogLevels } from "./levels.ts";
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { extname } from "../path/mod.ts";
|
||||||
import { tempFile } from "../io/util.ts";
|
import { tempFile } from "../io/util.ts";
|
||||||
import { BufReader, BufWriter } from "../io/bufio.ts";
|
import { BufReader, BufWriter } from "../io/bufio.ts";
|
||||||
import { encoder } from "../encoding/utf8.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 { TextProtoReader } from "../textproto/mod.ts";
|
||||||
import { hasOwnProperty } from "../_util/has_own_property.ts";
|
import { hasOwnProperty } from "../_util/has_own_property.ts";
|
||||||
|
|
||||||
|
@ -178,7 +178,7 @@ class PartReader implements Reader, Closer {
|
||||||
);
|
);
|
||||||
if (this.n === 0) {
|
if (this.n === 0) {
|
||||||
// Force buffered I/O to read more into buffer.
|
// Force buffered I/O to read more into buffer.
|
||||||
assertStrictEquals(eof, false);
|
assert(eof === false);
|
||||||
peekLength++;
|
peekLength++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ class PartReader implements Reader, Closer {
|
||||||
const nread = min(p.length, this.n);
|
const nread = min(p.length, this.n);
|
||||||
const buf = p.subarray(0, nread);
|
const buf = p.subarray(0, nread);
|
||||||
const r = await br.readFull(buf);
|
const r = await br.readFull(buf);
|
||||||
assertStrictEquals(r, buf);
|
assert(r === buf);
|
||||||
this.n -= nread;
|
this.n -= nread;
|
||||||
this.total += nread;
|
this.total += nread;
|
||||||
return nread;
|
return nread;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import Dirent from "./_fs_dirent.ts";
|
import Dirent from "./_fs_dirent.ts";
|
||||||
import { assert } from "../../testing/asserts.ts";
|
import { assert } from "../../_util/assert.ts";
|
||||||
|
|
||||||
export default class Dir {
|
export default class Dir {
|
||||||
private dirPath: string | Uint8Array;
|
private dirPath: string | Uint8Array;
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
import { validateIntegerRange } from "./util.ts";
|
import { validateIntegerRange } from "./util.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
export interface WrappedFunction extends Function {
|
export interface WrappedFunction extends Function {
|
||||||
listener: Function;
|
listener: Function;
|
||||||
|
|
|
@ -31,7 +31,7 @@ import * as nodeEvents from "./events.ts";
|
||||||
import * as nodeQueryString from "./querystring.ts";
|
import * as nodeQueryString from "./querystring.ts";
|
||||||
|
|
||||||
import * as path from "../path/mod.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";
|
import { pathToFileURL, fileURLToPath } from "./url.ts";
|
||||||
|
|
||||||
const CHAR_FORWARD_SLASH = "/".charCodeAt(0);
|
const CHAR_FORWARD_SLASH = "/".charCodeAt(0);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
import { SEP, SEP_PATTERN } from "./separator.ts";
|
import { SEP, SEP_PATTERN } from "./separator.ts";
|
||||||
import { globrex } from "./_globrex.ts";
|
import { globrex } from "./_globrex.ts";
|
||||||
import { join, normalize } from "./mod.ts";
|
import { join, normalize } from "./mod.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
export interface GlobOptions {
|
export interface GlobOptions {
|
||||||
extended?: boolean;
|
extended?: boolean;
|
||||||
|
|
|
@ -17,7 +17,7 @@ import {
|
||||||
normalizeString,
|
normalizeString,
|
||||||
_format,
|
_format,
|
||||||
} from "./_util.ts";
|
} from "./_util.ts";
|
||||||
import { assert } from "../testing/asserts.ts";
|
import { assert } from "../_util/assert.ts";
|
||||||
|
|
||||||
export const sep = "\\";
|
export const sep = "\\";
|
||||||
export const delimiter = ";";
|
export const delimiter = ";";
|
||||||
|
|
|
@ -8,7 +8,7 @@ import {
|
||||||
} from "./_common.ts";
|
} from "./_common.ts";
|
||||||
import { Sha1 } from "../hash/sha1.ts";
|
import { Sha1 } from "../hash/sha1.ts";
|
||||||
import { isString } from "../node/util.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;
|
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;
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Sha1 } from "../hash/sha1.ts";
|
||||||
import { writeResponse } from "../http/_io.ts";
|
import { writeResponse } from "../http/_io.ts";
|
||||||
import { TextProtoReader } from "../textproto/mod.ts";
|
import { TextProtoReader } from "../textproto/mod.ts";
|
||||||
import { Deferred, deferred } from "../async/deferred.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 { concat } from "../bytes/mod.ts";
|
||||||
import Conn = Deno.Conn;
|
import Conn = Deno.Conn;
|
||||||
import Writer = Deno.Writer;
|
import Writer = Deno.Writer;
|
||||||
|
|
Loading…
Add table
Reference in a new issue