0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 09:31:22 -05:00

refactor: rewrite tests in std/ to use Deno.test (#3930)

This commit is contained in:
Bartek Iwańczuk 2020-02-11 17:24:27 +01:00 committed by GitHub
parent e0bcecee60
commit 61273085e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
94 changed files with 328 additions and 1185 deletions

View file

@ -8,7 +8,6 @@
* **to run this test**
* deno run --allow-read archive/tar_test.ts
*/
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { resolve } from "../path/mod.ts";
@ -16,7 +15,7 @@ import { Tar, Untar } from "./tar.ts";
const filePath = resolve("archive", "testdata", "example.txt");
test(async function createTarArchive(): Promise<void> {
Deno.test(async function createTarArchive(): Promise<void> {
// initialize
const tar = new Tar();
@ -41,7 +40,7 @@ test(async function createTarArchive(): Promise<void> {
assertEquals(wrote, 3072);
});
test(async function deflateTarArchive(): Promise<void> {
Deno.test(async function deflateTarArchive(): Promise<void> {
const fileName = "output.txt";
const text = "hello tar world!";
@ -64,7 +63,7 @@ test(async function deflateTarArchive(): Promise<void> {
assertEquals(untarText, text);
});
test(async function appendFileWithLongNameToTarArchive(): Promise<void> {
Deno.test(async function appendFileWithLongNameToTarArchive(): Promise<void> {
// 9 * 15 + 13 = 148 bytes
const fileName = new Array(10).join("long-file-name/") + "file-name.txt";
const text = "hello tar world!";
@ -87,5 +86,3 @@ test(async function appendFileWithLongNameToTarArchive(): Promise<void> {
assertEquals(result.fileName, fileName);
assertEquals(untarText, text);
});
runIfMain(import.meta);

View file

@ -1,10 +1,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { findIndex, findLastIndex, equal, hasPrefix, repeat } from "./mod.ts";
import { test } from "../testing/mod.ts";
import { assertEquals, assertThrows } from "../testing/asserts.ts";
test(function bytesfindIndex1(): void {
Deno.test(function bytesfindIndex1(): void {
const i = findIndex(
new Uint8Array([1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 3]),
new Uint8Array([0, 1, 2])
@ -12,12 +11,12 @@ test(function bytesfindIndex1(): void {
assertEquals(i, 2);
});
test(function bytesfindIndex2(): void {
Deno.test(function bytesfindIndex2(): void {
const i = findIndex(new Uint8Array([0, 0, 1]), new Uint8Array([0, 1]));
assertEquals(i, 1);
});
test(function bytesfindLastIndex1(): void {
Deno.test(function bytesfindLastIndex1(): void {
const i = findLastIndex(
new Uint8Array([0, 1, 2, 0, 1, 2, 0, 1, 3]),
new Uint8Array([0, 1, 2])
@ -25,22 +24,22 @@ test(function bytesfindLastIndex1(): void {
assertEquals(i, 3);
});
test(function bytesfindLastIndex2(): void {
Deno.test(function bytesfindLastIndex2(): void {
const i = findLastIndex(new Uint8Array([0, 1, 1]), new Uint8Array([0, 1]));
assertEquals(i, 0);
});
test(function bytesBytesequal(): void {
Deno.test(function bytesBytesequal(): void {
const v = equal(new Uint8Array([0, 1, 2, 3]), new Uint8Array([0, 1, 2, 3]));
assertEquals(v, true);
});
test(function byteshasPrefix(): void {
Deno.test(function byteshasPrefix(): void {
const v = hasPrefix(new Uint8Array([0, 1, 2]), new Uint8Array([0, 1]));
assertEquals(v, true);
});
test(function bytesrepeat(): void {
Deno.test(function bytesrepeat(): void {
// input / output / count / error message
const repeatTestCase = [
["", "", 0],

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals, assertThrows } from "../testing/asserts.ts";
import * as datetime from "./mod.ts";
test(function parseDateTime(): void {
Deno.test(function parseDateTime(): void {
assertEquals(
datetime.parseDateTime("01-03-2019 16:30", "mm-dd-yyyy hh:mm"),
new Date(2019, 0, 3, 16, 30)
@ -30,7 +29,7 @@ test(function parseDateTime(): void {
);
});
test(function invalidParseDateTimeFormatThrows(): void {
Deno.test(function invalidParseDateTimeFormatThrows(): void {
assertThrows(
(): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -41,7 +40,7 @@ test(function invalidParseDateTimeFormatThrows(): void {
);
});
test(function parseDate(): void {
Deno.test(function parseDate(): void {
assertEquals(
datetime.parseDate("01-03-2019", "mm-dd-yyyy"),
new Date(2019, 0, 3)
@ -56,7 +55,7 @@ test(function parseDate(): void {
);
});
test(function invalidParseDateFormatThrows(): void {
Deno.test(function invalidParseDateFormatThrows(): void {
assertThrows(
(): void => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -67,17 +66,17 @@ test(function invalidParseDateFormatThrows(): void {
);
});
test(function DayOfYear(): void {
Deno.test(function DayOfYear(): void {
assertEquals(1, datetime.dayOfYear(new Date("2019-01-01T03:24:00")));
assertEquals(70, datetime.dayOfYear(new Date("2019-03-11T03:24:00")));
assertEquals(365, datetime.dayOfYear(new Date("2019-12-31T03:24:00")));
});
test(function currentDayOfYear(): void {
Deno.test(function currentDayOfYear(): void {
assertEquals(datetime.currentDayOfYear(), datetime.dayOfYear(new Date()));
});
test({
Deno.test({
name: "[DateTime] to IMF",
fn(): void {
const actual = datetime.toIMF(new Date(Date.UTC(1994, 3, 5, 15, 32)));
@ -86,7 +85,7 @@ test({
}
});
test({
Deno.test({
name: "[DateTime] to IMF 0",
fn(): void {
const actual = datetime.toIMF(new Date(0));

View file

@ -1,7 +1,6 @@
// Test cases copied from https://github.com/LinusU/base32-encode/blob/master/test.js
// Copyright (c) 2016-2017 Linus Unnebäck. MIT license.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals, assert } from "../testing/asserts.ts";
import { encode, decode } from "./base32.ts";
@ -87,7 +86,7 @@ const testCases = [
]
];
test({
Deno.test({
name: "[encoding.base32] encode",
fn(): void {
for (const [bin, b32] of testCases) {
@ -96,7 +95,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.base32] decode",
fn(): void {
for (const [bin, b32] of testCases) {
@ -105,7 +104,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.base32] decode bad length",
fn(): void {
let errorCaught = false;
@ -121,7 +120,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.base32] decode bad padding",
fn(): void {
let errorCaught = false;
@ -134,5 +133,3 @@ test({
assert(errorCaught);
}
});
runIfMain(import.meta);

View file

@ -1,6 +1,5 @@
// Test ported from Golang
// https://github.com/golang/go/blob/2cc15b1/src/encoding/csv/reader_test.go
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals, assert } from "../testing/asserts.ts";
import { readMatrix, parse } from "./csv.ts";
import { StringReader } from "../io/readers.ts";
@ -450,7 +449,7 @@ x,,,
}
];
for (const t of testCases) {
test({
Deno.test({
name: `[CSV] ${t.Name}`,
async fn(): Promise<void> {
let comma = ",";
@ -605,7 +604,7 @@ const parseTestCases = [
];
for (const testCase of parseTestCases) {
test({
Deno.test({
name: `[CSV] Parse ${testCase.name}`,
async fn(): Promise<void> {
const r = await parse(testCase.in, {
@ -616,5 +615,3 @@ for (const testCase of parseTestCases) {
}
});
}
runIfMain(import.meta);

View file

@ -4,7 +4,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test, runIfMain } from "../testing/mod.ts";
import { assertEquals, assertThrows } from "../testing/asserts.ts";
import {
@ -46,7 +45,7 @@ const errCases = [
["ffeed", "\xff\xee", errLength()]
];
test({
Deno.test({
name: "[encoding.hex] encodedLen",
fn(): void {
assertEquals(encodedLen(0), 0);
@ -57,7 +56,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.hex] encode",
fn(): void {
{
@ -92,7 +91,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.hex] encodeToString",
fn(): void {
for (const [enc, dec] of testCases) {
@ -101,7 +100,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.hex] decodedLen",
fn(): void {
assertEquals(decodedLen(0), 0);
@ -112,7 +111,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.hex] decode",
fn(): void {
// Case for decoding uppercase hex characters, since
@ -133,7 +132,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.hex] decodeString",
fn(): void {
for (const [enc, dec] of testCases) {
@ -144,7 +143,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.hex] decode error",
fn(): void {
for (const [input, output, expectedErr] of errCases) {
@ -159,7 +158,7 @@ test({
}
});
test({
Deno.test({
name: "[encoding.hex] decodeString error",
fn(): void {
for (const [input, output, expectedErr] of errCases) {
@ -178,5 +177,3 @@ test({
}
}
});
runIfMain(import.meta);

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { runIfMain, test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { existsSync } from "../fs/exists.ts";
import { readFileStrSync } from "../fs/read_file_str.ts";
@ -16,7 +15,7 @@ function parseFile(filePath: string): object {
return parse(strFile);
}
test({
Deno.test({
name: "[TOML] Strings",
fn(): void {
const expected = {
@ -38,7 +37,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] CRLF",
fn(): void {
const expected = { boolean: { bool1: true, bool2: false } };
@ -47,7 +46,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Boolean",
fn(): void {
const expected = { boolean: { bool1: true, bool2: false } };
@ -56,7 +55,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Integer",
fn(): void {
const expected = {
@ -81,7 +80,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Float",
fn(): void {
const expected = {
@ -107,7 +106,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Arrays",
fn(): void {
const expected = {
@ -124,7 +123,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Table",
fn(): void {
const expected = {
@ -157,7 +156,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Simple",
fn(): void {
const expected = {
@ -172,7 +171,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Datetime",
fn(): void {
const expected = {
@ -191,7 +190,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Inline Table",
fn(): void {
const expected = {
@ -236,7 +235,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Array of Tables",
fn(): void {
const expected = {
@ -251,7 +250,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Cargo",
fn(): void {
/* eslint-disable @typescript-eslint/camelcase */
@ -298,7 +297,7 @@ test({
}
});
test({
Deno.test({
name: "[TOML] Stringify",
fn(): void {
const src = {
@ -412,5 +411,3 @@ the = "array"
assertEquals(actual, expected);
}
});
runIfMain(import.meta);

View file

@ -4,10 +4,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { parse, parseAll } from "./parse.ts";
import { test } from "../../testing/mod.ts";
import { assertEquals } from "../../testing/asserts.ts";
test({
Deno.test({
name: "`parse` parses single document yaml string",
fn(): void {
const yaml = `
@ -24,7 +23,7 @@ test({
}
});
test({
Deno.test({
name: "`parseAll` parses the yaml string with multiple documents",
fn(): void {
const yaml = `

View file

@ -3,11 +3,10 @@
// Copyright 2011-2015 by Vitaly Puzrin. All rights reserved. MIT license.
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../../testing/mod.ts";
import { assertEquals } from "../../testing/asserts.ts";
import { stringify } from "./stringify.ts";
test({
Deno.test({
name: "stringified correctly",
fn(): void {
const FIXTURE = {

View file

@ -1,19 +1,18 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
const { run } = Deno;
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
/** Example of how to do basic tests */
test(function t1(): void {
Deno.test(function t1(): void {
assertEquals("hello", "hello");
});
test(function t2(): void {
Deno.test(function t2(): void {
assertEquals("world", "world");
});
/** A more complicated test that runs a subprocess. */
test(async function catSmoke(): Promise<void> {
Deno.test(async function catSmoke(): Promise<void> {
const p = run({
args: [
Deno.execPath(),

View file

@ -6,16 +6,15 @@ import {
assertStrContains,
assert
} from "../../testing/asserts.ts";
import { test } from "../../testing/mod.ts";
const { execPath, run } = Deno;
test(async function xevalSuccess(): Promise<void> {
Deno.test(async function xevalSuccess(): Promise<void> {
const chunks: string[] = [];
await xeval(stringsReader("a\nb\nc"), ($): number => chunks.push($));
assertEquals(chunks, ["a", "b", "c"]);
});
test(async function xevalDelimiter(): Promise<void> {
Deno.test(async function xevalDelimiter(): Promise<void> {
const chunks: string[] = [];
await xeval(stringsReader("!MADMADAMADAM!"), ($): number => chunks.push($), {
delimiter: "MADAM"
@ -26,7 +25,7 @@ test(async function xevalDelimiter(): Promise<void> {
// https://github.com/denoland/deno/issues/2861
const xevalPath = "examples/xeval.ts";
test(async function xevalCliReplvar(): Promise<void> {
Deno.test(async function xevalCliReplvar(): Promise<void> {
const p = run({
args: [execPath(), xevalPath, "--", "--replvar=abc", "console.log(abc)"],
stdin: "piped",
@ -40,7 +39,7 @@ test(async function xevalCliReplvar(): Promise<void> {
assertEquals(decode(await p.output()).trimEnd(), "hello");
});
test(async function xevalCliSyntaxError(): Promise<void> {
Deno.test(async function xevalCliSyntaxError(): Promise<void> {
const p = run({
args: [execPath(), xevalPath, "--", "("],
stdin: "null",

View file

@ -1,10 +1,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
// flag boolean true (default all --args to boolean)
test(function flagBooleanTrue(): void {
Deno.test(function flagBooleanTrue(): void {
const argv = parse(["moo", "--honk", "cow"], {
boolean: true
});
@ -18,7 +17,7 @@ test(function flagBooleanTrue(): void {
});
// flag boolean true only affects double hyphen arguments without equals signs
test(function flagBooleanTrueOnlyAffectsDoubleDash(): void {
Deno.test(function flagBooleanTrueOnlyAffectsDoubleDash(): void {
const argv = parse(["moo", "--honk", "cow", "-p", "55", "--tacos=good"], {
boolean: true
});

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function flagBooleanDefaultFalse(): void {
Deno.test(function flagBooleanDefaultFalse(): void {
const argv = parse(["moo"], {
boolean: ["t", "verbose"],
default: { verbose: false, t: false }
@ -19,7 +18,7 @@ test(function flagBooleanDefaultFalse(): void {
assertEquals(typeof argv.t, "boolean");
});
test(function booleanGroups(): void {
Deno.test(function booleanGroups(): void {
const argv = parse(["-x", "-z", "one", "two", "three"], {
boolean: ["x", "y", "z"]
});
@ -36,7 +35,7 @@ test(function booleanGroups(): void {
assertEquals(typeof argv.z, "boolean");
});
test(function booleanAndAliasWithChainableApi(): void {
Deno.test(function booleanAndAliasWithChainableApi(): void {
const aliased = ["-h", "derp"];
const regular = ["--herp", "derp"];
const aliasedArgv = parse(aliased, {
@ -57,7 +56,7 @@ test(function booleanAndAliasWithChainableApi(): void {
assertEquals(propertyArgv, expected);
});
test(function booleanAndAliasWithOptionsHash(): void {
Deno.test(function booleanAndAliasWithOptionsHash(): void {
const aliased = ["-h", "derp"];
const regular = ["--herp", "derp"];
const opts = {
@ -75,7 +74,7 @@ test(function booleanAndAliasWithOptionsHash(): void {
assertEquals(propertyArgv, expected);
});
test(function booleanAndAliasArrayWithOptionsHash(): void {
Deno.test(function booleanAndAliasArrayWithOptionsHash(): void {
const aliased = ["-h", "derp"];
const regular = ["--herp", "derp"];
const alt = ["--harp", "derp"];
@ -97,7 +96,7 @@ test(function booleanAndAliasArrayWithOptionsHash(): void {
assertEquals(altPropertyArgv, expected);
});
test(function booleanAndAliasUsingExplicitTrue(): void {
Deno.test(function booleanAndAliasUsingExplicitTrue(): void {
const aliased = ["-h", "true"];
const regular = ["--herp", "true"];
const opts = {
@ -118,7 +117,7 @@ test(function booleanAndAliasUsingExplicitTrue(): void {
// regression, see https://github.com/substack/node-optimist/issues/71
// boolean and --x=true
test(function booleanAndNonBoolean(): void {
Deno.test(function booleanAndNonBoolean(): void {
const parsed = parse(["--boool", "--other=true"], {
boolean: "boool"
});
@ -134,7 +133,7 @@ test(function booleanAndNonBoolean(): void {
assertEquals(parsed2.other, "false");
});
test(function booleanParsingTrue(): void {
Deno.test(function booleanParsingTrue(): void {
const parsed = parse(["--boool=true"], {
default: {
boool: false
@ -145,7 +144,7 @@ test(function booleanParsingTrue(): void {
assertEquals(parsed.boool, true);
});
test(function booleanParsingFalse(): void {
Deno.test(function booleanParsingFalse(): void {
const parsed = parse(["--boool=false"], {
default: {
boool: true
@ -156,7 +155,7 @@ test(function booleanParsingFalse(): void {
assertEquals(parsed.boool, false);
});
test(function booleanParsingTrueLike(): void {
Deno.test(function booleanParsingTrueLike(): void {
const parsed = parse(["-t", "true123"], { boolean: ["t"] });
assertEquals(parsed.t, true);
@ -167,7 +166,7 @@ test(function booleanParsingTrueLike(): void {
assertEquals(parsed3.t, true);
});
test(function booleanNegationAfterBoolean(): void {
Deno.test(function booleanNegationAfterBoolean(): void {
const parsed = parse(["--foo", "--no-foo"], { boolean: ["foo"] });
assertEquals(parsed.foo, false);
@ -175,7 +174,7 @@ test(function booleanNegationAfterBoolean(): void {
assertEquals(parsed2.foo, false);
});
test(function booleanAfterBooleanNegation(): void {
Deno.test(function booleanAfterBooleanNegation(): void {
const parsed = parse(["--no--foo", "--foo"], { boolean: ["foo"] });
assertEquals(parsed.foo, true);
@ -183,7 +182,7 @@ test(function booleanAfterBooleanNegation(): void {
assertEquals(parsed2.foo, true);
});
test(function latestFlagIsBooleanNegation(): void {
Deno.test(function latestFlagIsBooleanNegation(): void {
const parsed = parse(["--no-foo", "--foo", "--no-foo"], { boolean: ["foo"] });
assertEquals(parsed.foo, false);
@ -193,7 +192,7 @@ test(function latestFlagIsBooleanNegation(): void {
assertEquals(parsed2.foo, false);
});
test(function latestFlagIsBoolean(): void {
Deno.test(function latestFlagIsBoolean(): void {
const parsed = parse(["--foo", "--no-foo", "--foo"], { boolean: ["foo"] });
assertEquals(parsed.foo, true);

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function hyphen(): void {
Deno.test(function hyphen(): void {
assertEquals(parse(["-n", "-"]), { n: "-", _: [] });
assertEquals(parse(["-"]), { _: ["-"] });
assertEquals(parse(["-f-"]), { f: "-", _: [] });
@ -11,13 +10,13 @@ test(function hyphen(): void {
assertEquals(parse(["-s", "-"], { string: "s" }), { s: "-", _: [] });
});
test(function doubleDash(): void {
Deno.test(function doubleDash(): void {
assertEquals(parse(["-a", "--", "b"]), { a: true, _: ["b"] });
assertEquals(parse(["--a", "--", "b"]), { a: true, _: ["b"] });
assertEquals(parse(["--a", "--", "b"]), { a: true, _: ["b"] });
});
test(function moveArgsAfterDoubleDashIntoOwnArray(): void {
Deno.test(function moveArgsAfterDoubleDashIntoOwnArray(): void {
assertEquals(
parse(["--name", "John", "before", "--", "after"], { "--": true }),
{

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function booleanDefaultTrue(): void {
Deno.test(function booleanDefaultTrue(): void {
const argv = parse([], {
boolean: "sometrue",
default: { sometrue: true }
@ -11,7 +10,7 @@ test(function booleanDefaultTrue(): void {
assertEquals(argv.sometrue, true);
});
test(function booleanDefaultFalse(): void {
Deno.test(function booleanDefaultFalse(): void {
const argv = parse([], {
boolean: "somefalse",
default: { somefalse: false }
@ -19,7 +18,7 @@ test(function booleanDefaultFalse(): void {
assertEquals(argv.somefalse, false);
});
test(function booleanDefaultNull(): void {
Deno.test(function booleanDefaultNull(): void {
const argv = parse([], {
boolean: "maybe",
default: { maybe: null }

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function dottedAlias(): void {
Deno.test(function dottedAlias(): void {
const argv = parse(["--a.b", "22"], {
default: { "a.b": 11 },
alias: { "a.b": "aa.bb" }
@ -12,13 +11,13 @@ test(function dottedAlias(): void {
assertEquals(argv.aa.bb, 22);
});
test(function dottedDefault(): void {
Deno.test(function dottedDefault(): void {
const argv = parse([], { default: { "a.b": 11 }, alias: { "a.b": "aa.bb" } });
assertEquals(argv.a.b, 11);
assertEquals(argv.aa.bb, 11);
});
test(function dottedDefaultWithNoAlias(): void {
Deno.test(function dottedDefaultWithNoAlias(): void {
const argv = parse([], { default: { "a.b": 11 } });
assertEquals(argv.a.b, 11);
});

View file

@ -1,14 +1,13 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function short(): void {
Deno.test(function short(): void {
const argv = parse(["-b=123"]);
assertEquals(argv, { b: 123, _: [] });
});
test(function multiShort(): void {
Deno.test(function multiShort(): void {
const argv = parse(["-a=whatever", "-b=robots"]);
assertEquals(argv, { a: "whatever", b: "robots", _: [] });
});

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function longOpts(): void {
Deno.test(function longOpts(): void {
assertEquals(parse(["--bool"]), { bool: true, _: [] });
assertEquals(parse(["--pow", "xixxle"]), { pow: "xixxle", _: [] });
assertEquals(parse(["--pow=xixxle"]), { pow: "xixxle", _: [] });

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function nums(): void {
Deno.test(function nums(): void {
const argv = parse([
"-x",
"1234",
@ -33,7 +32,7 @@ test(function nums(): void {
assertEquals(typeof argv._[0], "number");
});
test(function alreadyNumber(): void {
Deno.test(function alreadyNumber(): void {
const argv = parse(["-x", 1234, 789]);
assertEquals(argv, { x: 1234, _: [789] });
assertEquals(typeof argv.x, "number");

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function _arseArgs(): void {
Deno.test(function parseArgs(): void {
assertEquals(parse(["--no-moo"]), { moo: false, _: [] });
assertEquals(parse(["-v", "a", "-v", "b", "-v", "c"]), {
v: ["a", "b", "c"],
@ -11,7 +10,7 @@ test(function _arseArgs(): void {
});
});
test(function comprehensive(): void {
Deno.test(function comprehensive(): void {
assertEquals(
parse([
"--name=meowmers",
@ -48,13 +47,13 @@ test(function comprehensive(): void {
);
});
test(function flagBoolean(): void {
Deno.test(function flagBoolean(): void {
const argv = parse(["-t", "moo"], { boolean: "t" });
assertEquals(argv, { t: true, _: ["moo"] });
assertEquals(typeof argv.t, "boolean");
});
test(function flagBooleanValue(): void {
Deno.test(function flagBooleanValue(): void {
const argv = parse(["--verbose", "false", "moo", "-t", "true"], {
boolean: ["t", "verbose"],
default: { verbose: true }
@ -70,7 +69,7 @@ test(function flagBooleanValue(): void {
assertEquals(typeof argv.t, "boolean");
});
test(function newlinesInParams(): void {
Deno.test(function newlinesInParams(): void {
const args = parse(["-s", "X\nX"]);
assertEquals(args, { _: [], s: "X\nX" });
@ -82,7 +81,7 @@ test(function newlinesInParams(): void {
assertEquals(args2, { _: [], s: "X\nX" });
});
test(function strings(): void {
Deno.test(function strings(): void {
const s = parse(["-s", "0001234"], { string: "s" }).s;
assertEquals(s, "0001234");
assertEquals(typeof s, "string");
@ -92,7 +91,7 @@ test(function strings(): void {
assertEquals(typeof x, "string");
});
test(function stringArgs(): void {
Deno.test(function stringArgs(): void {
const s = parse([" ", " "], { string: "_" })._;
assertEquals(s.length, 2);
assertEquals(typeof s[0], "string");
@ -101,7 +100,7 @@ test(function stringArgs(): void {
assertEquals(s[1], " ");
});
test(function emptyStrings(): void {
Deno.test(function emptyStrings(): void {
const s = parse(["-s"], { string: "s" }).s;
assertEquals(s, "");
assertEquals(typeof s, "string");
@ -119,7 +118,7 @@ test(function emptyStrings(): void {
assertEquals(letters.t, "");
});
test(function stringAndAlias(): void {
Deno.test(function stringAndAlias(): void {
const x = parse(["--str", "000123"], {
string: "s",
alias: { s: "str" }
@ -141,7 +140,7 @@ test(function stringAndAlias(): void {
assertEquals(typeof y.s, "string");
});
test(function slashBreak(): void {
Deno.test(function slashBreak(): void {
assertEquals(parse(["-I/foo/bar/baz"]), { I: "/foo/bar/baz", _: [] });
assertEquals(parse(["-xyz/foo/bar/baz"]), {
x: true,
@ -151,7 +150,7 @@ test(function slashBreak(): void {
});
});
test(function alias(): void {
Deno.test(function alias(): void {
const argv = parse(["-f", "11", "--zoom", "55"], {
alias: { z: "zoom" }
});
@ -160,7 +159,7 @@ test(function alias(): void {
assertEquals(argv.f, 11);
});
test(function multiAlias(): void {
Deno.test(function multiAlias(): void {
const argv = parse(["-f", "11", "--zoom", "55"], {
alias: { z: ["zm", "zoom"] }
});
@ -170,7 +169,7 @@ test(function multiAlias(): void {
assertEquals(argv.f, 11);
});
test(function nestedDottedObjects(): void {
Deno.test(function nestedDottedObjects(): void {
const argv = parse([
"--foo.bar",
"3",
@ -193,7 +192,7 @@ test(function nestedDottedObjects(): void {
assertEquals(argv.beep, { boop: true });
});
test(function flagBuiltinProperty(): void {
Deno.test(function flagBuiltinProperty(): void {
const argv = parse(["--toString", "--valueOf", "foo"]);
assertEquals(argv, { toString: true, valueOf: "foo", _: [] });
assertEquals(typeof argv.toString, "boolean");

View file

@ -1,14 +1,13 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function numbericShortArgs(): void {
Deno.test(function numbericShortArgs(): void {
assertEquals(parse(["-n123"]), { n: 123, _: [] });
assertEquals(parse(["-123", "456"]), { 1: true, 2: true, 3: 456, _: [] });
});
test(function short(): void {
Deno.test(function short(): void {
assertEquals(parse(["-b"]), { b: true, _: [] });
assertEquals(parse(["foo", "bar", "baz"]), { _: ["foo", "bar", "baz"] });
assertEquals(parse(["-cats"]), { c: true, a: true, t: true, s: true, _: [] });
@ -27,7 +26,7 @@ test(function short(): void {
});
});
test(function mixedShortBoolAndCapture(): void {
Deno.test(function mixedShortBoolAndCapture(): void {
assertEquals(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
f: true,
p: 555,
@ -36,7 +35,7 @@ test(function mixedShortBoolAndCapture(): void {
});
});
test(function shortAndLong(): void {
Deno.test(function shortAndLong(): void {
assertEquals(parse(["-h", "localhost", "-fp", "555", "script.js"]), {
f: true,
p: 555,

View file

@ -1,10 +1,9 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
// stops parsing on the first non-option when stopEarly is set
test(function stopParsing(): void {
Deno.test(function stopParsing(): void {
const argv = parse(["--aaa", "bbb", "ccc", "--ddd"], {
stopEarly: true
});

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function booleanAndAliasIsNotUnknown(): void {
Deno.test(function booleanAndAliasIsNotUnknown(): void {
const unknown: unknown[] = [];
function unknownFn(arg: unknown): boolean {
unknown.push(arg);
@ -22,7 +21,7 @@ test(function booleanAndAliasIsNotUnknown(): void {
assertEquals(unknown, ["--derp", "-d"]);
});
test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown(): void {
Deno.test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown(): void {
const unknown: unknown[] = [];
function unknownFn(arg: unknown): boolean {
unknown.push(arg);
@ -39,7 +38,7 @@ test(function flagBooleanTrueAnyDoubleHyphenArgumentIsNotUnknown(): void {
});
});
test(function stringAndAliasIsNotUnkown(): void {
Deno.test(function stringAndAliasIsNotUnkown(): void {
const unknown: unknown[] = [];
function unknownFn(arg: unknown): boolean {
unknown.push(arg);
@ -58,7 +57,7 @@ test(function stringAndAliasIsNotUnkown(): void {
assertEquals(unknown, ["--derp", "-d"]);
});
test(function defaultAndAliasIsNotUnknown(): void {
Deno.test(function defaultAndAliasIsNotUnknown(): void {
const unknown: unknown[] = [];
function unknownFn(arg: unknown): boolean {
unknown.push(arg);
@ -77,7 +76,7 @@ test(function defaultAndAliasIsNotUnknown(): void {
assertEquals(unknown, []);
});
test(function valueFollowingDoubleHyphenIsNotUnknown(): void {
Deno.test(function valueFollowingDoubleHyphenIsNotUnknown(): void {
const unknown: unknown[] = [];
function unknownFn(arg: unknown): boolean {
unknown.push(arg);

View file

@ -1,8 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { parse } from "./mod.ts";
test(function whitespaceShouldBeWhitespace(): void {
Deno.test(function whitespaceShouldBeWhitespace(): void {
assertEquals(parse(["-x", "\t"]).x, "\t");
});

View file

@ -1,22 +1,21 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import * as c from "./colors.ts";
import "../examples/colors.ts";
test(function singleColor(): void {
Deno.test(function singleColor(): void {
assertEquals(c.red("foo bar"), "foo bar");
});
test(function doubleColor(): void {
Deno.test(function doubleColor(): void {
assertEquals(c.bgBlue(c.red("foo bar")), "foo bar");
});
test(function replacesCloseCharacters(): void {
Deno.test(function replacesCloseCharacters(): void {
assertEquals(c.red("Hello"), "Hello");
});
test(function enablingColors(): void {
Deno.test(function enablingColors(): void {
assertEquals(c.getColorEnabled(), true);
c.setColorEnabled(false);
assertEquals(c.bgBlue(c.red("foo bar")), "foo bar");
@ -24,98 +23,98 @@ test(function enablingColors(): void {
assertEquals(c.red("foo bar"), "foo bar");
});
test(function testBold(): void {
Deno.test(function testBold(): void {
assertEquals(c.bold("foo bar"), "foo bar");
});
test(function testDim(): void {
Deno.test(function testDim(): void {
assertEquals(c.dim("foo bar"), "foo bar");
});
test(function testItalic(): void {
Deno.test(function testItalic(): void {
assertEquals(c.italic("foo bar"), "foo bar");
});
test(function testUnderline(): void {
Deno.test(function testUnderline(): void {
assertEquals(c.underline("foo bar"), "foo bar");
});
test(function testInverse(): void {
Deno.test(function testInverse(): void {
assertEquals(c.inverse("foo bar"), "foo bar");
});
test(function testHidden(): void {
Deno.test(function testHidden(): void {
assertEquals(c.hidden("foo bar"), "foo bar");
});
test(function testStrikethrough(): void {
Deno.test(function testStrikethrough(): void {
assertEquals(c.strikethrough("foo bar"), "foo bar");
});
test(function testBlack(): void {
Deno.test(function testBlack(): void {
assertEquals(c.black("foo bar"), "foo bar");
});
test(function testRed(): void {
Deno.test(function testRed(): void {
assertEquals(c.red("foo bar"), "foo bar");
});
test(function testGreen(): void {
Deno.test(function testGreen(): void {
assertEquals(c.green("foo bar"), "foo bar");
});
test(function testYellow(): void {
Deno.test(function testYellow(): void {
assertEquals(c.yellow("foo bar"), "foo bar");
});
test(function testBlue(): void {
Deno.test(function testBlue(): void {
assertEquals(c.blue("foo bar"), "foo bar");
});
test(function testMagenta(): void {
Deno.test(function testMagenta(): void {
assertEquals(c.magenta("foo bar"), "foo bar");
});
test(function testCyan(): void {
Deno.test(function testCyan(): void {
assertEquals(c.cyan("foo bar"), "foo bar");
});
test(function testWhite(): void {
Deno.test(function testWhite(): void {
assertEquals(c.white("foo bar"), "foo bar");
});
test(function testGray(): void {
Deno.test(function testGray(): void {
assertEquals(c.gray("foo bar"), "foo bar");
});
test(function testBgBlack(): void {
Deno.test(function testBgBlack(): void {
assertEquals(c.bgBlack("foo bar"), "foo bar");
});
test(function testBgRed(): void {
Deno.test(function testBgRed(): void {
assertEquals(c.bgRed("foo bar"), "foo bar");
});
test(function testBgGreen(): void {
Deno.test(function testBgGreen(): void {
assertEquals(c.bgGreen("foo bar"), "foo bar");
});
test(function testBgYellow(): void {
Deno.test(function testBgYellow(): void {
assertEquals(c.bgYellow("foo bar"), "foo bar");
});
test(function testBgBlue(): void {
Deno.test(function testBgBlue(): void {
assertEquals(c.bgBlue("foo bar"), "foo bar");
});
test(function testBgMagenta(): void {
Deno.test(function testBgMagenta(): void {
assertEquals(c.bgMagenta("foo bar"), "foo bar");
});
test(function testBgCyan(): void {
Deno.test(function testBgCyan(): void {
assertEquals(c.bgCyan("foo bar"), "foo bar");
});
test(function testBgWhite(): void {
Deno.test(function testBgWhite(): void {
assertEquals(c.bgWhite("foo bar"), "foo bar");
});

View file

@ -1,21 +1,20 @@
import { sprintf } from "./sprintf.ts";
import { assertEquals } from "../testing/asserts.ts";
import { test, runIfMain } from "../testing/mod.ts";
const S = sprintf;
test(function noVerb(): void {
Deno.test(function noVerb(): void {
assertEquals(sprintf("bla"), "bla");
});
test(function percent(): void {
Deno.test(function percent(): void {
assertEquals(sprintf("%%"), "%");
assertEquals(sprintf("!%%!"), "!%!");
assertEquals(sprintf("!%%"), "!%");
assertEquals(sprintf("%%!"), "%!");
});
test(function testBoolean(): void {
Deno.test(function testBoolean(): void {
assertEquals(sprintf("%t", true), "true");
assertEquals(sprintf("%10t", true), " true");
assertEquals(sprintf("%-10t", false), "false ");
@ -24,7 +23,7 @@ test(function testBoolean(): void {
assertEquals(sprintf("%tbla", false), "falsebla");
});
test(function testIntegerB(): void {
Deno.test(function testIntegerB(): void {
assertEquals(S("%b", 4), "100");
assertEquals(S("%b", -4), "-100");
assertEquals(
@ -48,7 +47,7 @@ test(function testIntegerB(): void {
assertEquals(S("%4b", 4), " 100");
});
test(function testIntegerC(): void {
Deno.test(function testIntegerC(): void {
assertEquals(S("%c", 0x31), "1");
assertEquals(S("%c%b", 0x31, 1), "11");
assertEquals(S("%c", 0x1f4a9), "💩");
@ -56,14 +55,14 @@ test(function testIntegerC(): void {
assertEquals(S("%4c", 0x31), " 1");
});
test(function testIntegerD(): void {
Deno.test(function testIntegerD(): void {
assertEquals(S("%d", 4), "4");
assertEquals(S("%d", -4), "-4");
assertEquals(S("%d", Number.MAX_SAFE_INTEGER), "9007199254740991");
assertEquals(S("%d", Number.MIN_SAFE_INTEGER), "-9007199254740991");
});
test(function testIntegerO(): void {
Deno.test(function testIntegerO(): void {
assertEquals(S("%o", 4), "4");
assertEquals(S("%o", -4), "-4");
assertEquals(S("%o", 9), "11");
@ -73,7 +72,7 @@ test(function testIntegerO(): void {
// width
assertEquals(S("%4o", 4), " 4");
});
test(function testIntegerx(): void {
Deno.test(function testIntegerx(): void {
assertEquals(S("%x", 4), "4");
assertEquals(S("%x", -4), "-4");
assertEquals(S("%x", 9), "9");
@ -87,7 +86,7 @@ test(function testIntegerx(): void {
assertEquals(S("%+4x", 4), " +4");
assertEquals(S("%-+4x", 4), "+4 ");
});
test(function testIntegerX(): void {
Deno.test(function testIntegerX(): void {
assertEquals(S("%X", 4), "4");
assertEquals(S("%X", -4), "-4");
assertEquals(S("%X", 9), "9");
@ -96,7 +95,7 @@ test(function testIntegerX(): void {
assertEquals(S("%X", Number.MIN_SAFE_INTEGER), "-1FFFFFFFFFFFFF");
});
test(function testFloate(): void {
Deno.test(function testFloate(): void {
assertEquals(S("%e", 4), "4.000000e+00");
assertEquals(S("%e", -4), "-4.000000e+00");
assertEquals(S("%e", 4.1), "4.100000e+00");
@ -104,7 +103,7 @@ test(function testFloate(): void {
assertEquals(S("%e", Number.MAX_SAFE_INTEGER), "9.007199e+15");
assertEquals(S("%e", Number.MIN_SAFE_INTEGER), "-9.007199e+15");
});
test(function testFloatE(): void {
Deno.test(function testFloatE(): void {
assertEquals(S("%E", 4), "4.000000E+00");
assertEquals(S("%E", -4), "-4.000000E+00");
assertEquals(S("%E", 4.1), "4.100000E+00");
@ -114,7 +113,7 @@ test(function testFloatE(): void {
assertEquals(S("%E", Number.MIN_VALUE), "5.000000E-324");
assertEquals(S("%E", Number.MAX_VALUE), "1.797693E+308");
});
test(function testFloatfF(): void {
Deno.test(function testFloatfF(): void {
assertEquals(S("%f", 4), "4.000000");
assertEquals(S("%F", 4), "4.000000");
assertEquals(S("%f", -4), "-4.000000");
@ -146,32 +145,32 @@ test(function testFloatfF(): void {
);
});
test(function testString(): void {
Deno.test(function testString(): void {
assertEquals(S("%s World%s", "Hello", "!"), "Hello World!");
});
test(function testHex(): void {
Deno.test(function testHex(): void {
assertEquals(S("%x", "123"), "313233");
assertEquals(S("%x", "n"), "6e");
});
test(function testHeX(): void {
Deno.test(function testHeX(): void {
assertEquals(S("%X", "123"), "313233");
assertEquals(S("%X", "n"), "6E");
});
test(function testType(): void {
Deno.test(function testType(): void {
assertEquals(S("%T", new Date()), "object");
assertEquals(S("%T", 123), "number");
assertEquals(S("%T", "123"), "string");
assertEquals(S("%.3T", "123"), "str");
});
test(function testPositional(): void {
Deno.test(function testPositional(): void {
assertEquals(S("%[1]d%[2]d", 1, 2), "12");
assertEquals(S("%[2]d%[1]d", 1, 2), "21");
});
test(function testSharp(): void {
Deno.test(function testSharp(): void {
assertEquals(S("%#x", "123"), "0x313233");
assertEquals(S("%#X", "123"), "0X313233");
assertEquals(S("%#x", 123), "0x7b");
@ -180,7 +179,7 @@ test(function testSharp(): void {
assertEquals(S("%#b", 4), "0b100");
});
test(function testWidthAndPrecision(): void {
Deno.test(function testWidthAndPrecision(): void {
assertEquals(
S("%9.99d", 9),
// eslint-disable-next-line max-len
@ -206,21 +205,21 @@ test(function testWidthAndPrecision(): void {
assertEquals(S("%#*x", 4, 1), " 0x1");
});
test(function testDash(): void {
Deno.test(function testDash(): void {
assertEquals(S("%-2s", "a"), "a ");
assertEquals(S("%-2d", 1), "1 ");
});
test(function testPlus(): void {
Deno.test(function testPlus(): void {
assertEquals(S("%-+3d", 1), "+1 ");
assertEquals(S("%+3d", 1), " +1");
assertEquals(S("%+3d", -1), " -1");
});
test(function testSpace(): void {
Deno.test(function testSpace(): void {
assertEquals(S("% -3d", 3), " 3 ");
});
test(function testZero(): void {
Deno.test(function testZero(): void {
assertEquals(S("%04s", "a"), "000a");
});
@ -586,7 +585,7 @@ const tests: Array<[string, any, string]> = [
["% +07.2f", -1.0, "-001.00"]
];
test(function testThorough(): void {
Deno.test(function testThorough(): void {
tests.forEach((t, i): void => {
// p(t)
const is = S(t[0], t[1]);
@ -599,7 +598,7 @@ test(function testThorough(): void {
});
});
test(function testWeirdos(): void {
Deno.test(function testWeirdos(): void {
assertEquals(S("%.d", 9), "9");
assertEquals(
S("dec[%d]=%d hex[%[1]d]=%#x oct[%[1]d]=%#o %s", 1, 255, "Third"),
@ -607,7 +606,7 @@ test(function testWeirdos(): void {
);
});
test(function formatV(): void {
Deno.test(function formatV(): void {
const a = { a: { a: { a: { a: { a: { a: { a: {} } } } } } } };
assertEquals(S("%v", a), "[object Object]");
assertEquals(S("%#v", a), "{ a: { a: { a: { a: [Object] } } } }");
@ -618,12 +617,12 @@ test(function formatV(): void {
assertEquals(S("%#.1v", a), "{ a: [Object] }");
});
test(function formatJ(): void {
Deno.test(function formatJ(): void {
const a = { a: { a: { a: { a: { a: { a: { a: {} } } } } } } };
assertEquals(S("%j", a), `{"a":{"a":{"a":{"a":{"a":{"a":{"a":{}}}}}}}}`);
});
test(function flagLessThan(): void {
Deno.test(function flagLessThan(): void {
const a = { a: { a: { a: { a: { a: { a: { a: {} } } } } } } };
const aArray = [a, a, a];
assertEquals(
@ -634,7 +633,7 @@ test(function flagLessThan(): void {
assertEquals(S("%<.2f", fArray), "[ 1.23, 0.99, 123456789.57 ]");
});
test(function testErrors(): void {
Deno.test(function testErrors(): void {
// wrong type : TODO strict mode ...
//assertEquals(S("%f", "not a number"), "%!(BADTYPE flag=f type=string)")
assertEquals(S("A %h", ""), "A %!(BAD VERB 'h')");
@ -664,5 +663,3 @@ test(function testErrors(): void {
assertEquals(S("%.[5]f"), "%!(BAD INDEX)");
assertEquals(S("%.[5]*f"), "%!(BAD INDEX)");
});
runIfMain(import.meta);

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import {
assertEquals,
assertThrows,
@ -22,7 +21,7 @@ async function testCopy(
name: string,
cb: (tempDir: string) => Promise<void>
): Promise<void> {
test({
Deno.test({
name,
async fn(): Promise<void> {
const tempDir = await Deno.makeTempDir({
@ -35,7 +34,7 @@ async function testCopy(
}
function testCopySync(name: string, cb: (tempDir: string) => void): void {
test({
Deno.test({
name,
fn: (): void => {
const tempDir = Deno.makeTempDirSync({

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import {
assertEquals,
assertStrContains,
@ -11,7 +10,7 @@ import { emptyDir, emptyDirSync } from "./empty_dir.ts";
const testdataDir = path.resolve("fs", "testdata");
test(async function emptyDirIfItNotExist(): Promise<void> {
Deno.test(async function emptyDirIfItNotExist(): Promise<void> {
const testDir = path.join(testdataDir, "empty_dir_test_1");
const testNestDir = path.join(testDir, "nest");
// empty a dir which not exist. then it will create new one
@ -27,7 +26,7 @@ test(async function emptyDirIfItNotExist(): Promise<void> {
}
});
test(function emptyDirSyncIfItNotExist(): void {
Deno.test(function emptyDirSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "empty_dir_test_2");
const testNestDir = path.join(testDir, "nest");
// empty a dir which not exist. then it will create new one
@ -43,7 +42,7 @@ test(function emptyDirSyncIfItNotExist(): void {
}
});
test(async function emptyDirIfItExist(): Promise<void> {
Deno.test(async function emptyDirIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "empty_dir_test_3");
const testNestDir = path.join(testDir, "nest");
// create test dir
@ -86,7 +85,7 @@ test(async function emptyDirIfItExist(): Promise<void> {
}
});
test(function emptyDirSyncIfItExist(): void {
Deno.test(function emptyDirSyncIfItExist(): void {
const testDir = path.join(testdataDir, "empty_dir_test_4");
const testNestDir = path.join(testDir, "nest");
// create test dir
@ -125,7 +124,7 @@ test(function emptyDirSyncIfItExist(): void {
}
});
test(async function emptyDirPermission(): Promise<void> {
Deno.test(async function emptyDirPermission(): Promise<void> {
interface Scenes {
read: boolean; // --allow-read
write: boolean; // --allow-write

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertThrows, assertThrowsAsync } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { ensureDir, ensureDirSync } from "./ensure_dir.ts";
@ -7,7 +6,7 @@ import { ensureFile, ensureFileSync } from "./ensure_file.ts";
const testdataDir = path.resolve("fs", "testdata");
test(async function ensureDirIfItNotExist(): Promise<void> {
Deno.test(async function ensureDirIfItNotExist(): Promise<void> {
const baseDir = path.join(testdataDir, "ensure_dir_not_exist");
const testDir = path.join(baseDir, "test");
@ -24,7 +23,7 @@ test(async function ensureDirIfItNotExist(): Promise<void> {
await Deno.remove(baseDir, { recursive: true });
});
test(function ensureDirSyncIfItNotExist(): void {
Deno.test(function ensureDirSyncIfItNotExist(): void {
const baseDir = path.join(testdataDir, "ensure_dir_sync_not_exist");
const testDir = path.join(baseDir, "test");
@ -35,7 +34,7 @@ test(function ensureDirSyncIfItNotExist(): void {
Deno.removeSync(baseDir, { recursive: true });
});
test(async function ensureDirIfItExist(): Promise<void> {
Deno.test(async function ensureDirIfItExist(): Promise<void> {
const baseDir = path.join(testdataDir, "ensure_dir_exist");
const testDir = path.join(baseDir, "test");
@ -55,7 +54,7 @@ test(async function ensureDirIfItExist(): Promise<void> {
await Deno.remove(baseDir, { recursive: true });
});
test(function ensureDirSyncIfItExist(): void {
Deno.test(function ensureDirSyncIfItExist(): void {
const baseDir = path.join(testdataDir, "ensure_dir_sync_exist");
const testDir = path.join(baseDir, "test");
@ -72,7 +71,7 @@ test(function ensureDirSyncIfItExist(): void {
Deno.removeSync(baseDir, { recursive: true });
});
test(async function ensureDirIfItAsFile(): Promise<void> {
Deno.test(async function ensureDirIfItAsFile(): Promise<void> {
const baseDir = path.join(testdataDir, "ensure_dir_exist_file");
const testFile = path.join(baseDir, "test");
@ -89,7 +88,7 @@ test(async function ensureDirIfItAsFile(): Promise<void> {
await Deno.remove(baseDir, { recursive: true });
});
test(function ensureDirSyncIfItAsFile(): void {
Deno.test(function ensureDirSyncIfItAsFile(): void {
const baseDir = path.join(testdataDir, "ensure_dir_exist_file_async");
const testFile = path.join(baseDir, "test");

View file

@ -1,12 +1,11 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertThrows, assertThrowsAsync } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { ensureFile, ensureFileSync } from "./ensure_file.ts";
const testdataDir = path.resolve("fs", "testdata");
test(async function ensureFileIfItNotExist(): Promise<void> {
Deno.test(async function ensureFileIfItNotExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_file_1");
const testFile = path.join(testDir, "test.txt");
@ -23,7 +22,7 @@ test(async function ensureFileIfItNotExist(): Promise<void> {
await Deno.remove(testDir, { recursive: true });
});
test(function ensureFileSyncIfItNotExist(): void {
Deno.test(function ensureFileSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "ensure_file_2");
const testFile = path.join(testDir, "test.txt");
@ -37,7 +36,7 @@ test(function ensureFileSyncIfItNotExist(): void {
Deno.removeSync(testDir, { recursive: true });
});
test(async function ensureFileIfItExist(): Promise<void> {
Deno.test(async function ensureFileIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_file_3");
const testFile = path.join(testDir, "test.txt");
@ -57,7 +56,7 @@ test(async function ensureFileIfItExist(): Promise<void> {
await Deno.remove(testDir, { recursive: true });
});
test(function ensureFileSyncIfItExist(): void {
Deno.test(function ensureFileSyncIfItExist(): void {
const testDir = path.join(testdataDir, "ensure_file_4");
const testFile = path.join(testDir, "test.txt");
@ -74,7 +73,7 @@ test(function ensureFileSyncIfItExist(): void {
Deno.removeSync(testDir, { recursive: true });
});
test(async function ensureFileIfItExistAsDir(): Promise<void> {
Deno.test(async function ensureFileIfItExistAsDir(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_file_5");
await Deno.mkdir(testDir, { recursive: true });
@ -90,7 +89,7 @@ test(async function ensureFileIfItExistAsDir(): Promise<void> {
await Deno.remove(testDir, { recursive: true });
});
test(function ensureFileSyncIfItExistAsDir(): void {
Deno.test(function ensureFileSyncIfItExistAsDir(): void {
const testDir = path.join(testdataDir, "ensure_file_6");
Deno.mkdirSync(testDir, { recursive: true });

View file

@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// TODO(axetroy): Add test for Windows once symlink is implemented for Windows.
import { test } from "../testing/mod.ts";
import {
assertEquals,
assertThrows,
@ -11,7 +10,7 @@ import { ensureLink, ensureLinkSync } from "./ensure_link.ts";
const testdataDir = path.resolve("fs", "testdata");
test(async function ensureLinkIfItNotExist(): Promise<void> {
Deno.test(async function ensureLinkIfItNotExist(): Promise<void> {
const srcDir = path.join(testdataDir, "ensure_link_1");
const destDir = path.join(testdataDir, "ensure_link_1_2");
const testFile = path.join(srcDir, "test.txt");
@ -26,7 +25,7 @@ test(async function ensureLinkIfItNotExist(): Promise<void> {
await Deno.remove(destDir, { recursive: true });
});
test(function ensureLinkSyncIfItNotExist(): void {
Deno.test(function ensureLinkSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "ensure_link_2");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@ -38,7 +37,7 @@ test(function ensureLinkSyncIfItNotExist(): void {
Deno.removeSync(testDir, { recursive: true });
});
test(async function ensureLinkIfItExist(): Promise<void> {
Deno.test(async function ensureLinkIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_link_3");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@ -85,7 +84,7 @@ test(async function ensureLinkIfItExist(): Promise<void> {
await Deno.remove(testDir, { recursive: true });
});
test(function ensureLinkSyncIfItExist(): void {
Deno.test(function ensureLinkSyncIfItExist(): void {
const testDir = path.join(testdataDir, "ensure_link_4");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@ -133,7 +132,7 @@ test(function ensureLinkSyncIfItExist(): void {
Deno.removeSync(testDir, { recursive: true });
});
test(async function ensureLinkDirectoryIfItExist(): Promise<void> {
Deno.test(async function ensureLinkDirectoryIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "ensure_link_origin_3");
const linkDir = path.join(testdataDir, "ensure_link_link_3");
const testFile = path.join(testDir, "test.txt");
@ -153,7 +152,7 @@ test(async function ensureLinkDirectoryIfItExist(): Promise<void> {
Deno.removeSync(testDir, { recursive: true });
});
test(function ensureLinkSyncDirectoryIfItExist(): void {
Deno.test(function ensureLinkSyncDirectoryIfItExist(): void {
const testDir = path.join(testdataDir, "ensure_link_origin_3");
const linkDir = path.join(testdataDir, "ensure_link_link_3");
const testFile = path.join(testDir, "test.txt");

View file

@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
// TODO(axetroy): Add test for Windows once symlink is implemented for Windows.
import { test } from "../testing/mod.ts";
import {
assertEquals,
assertThrows,
@ -12,7 +11,7 @@ import { ensureSymlink, ensureSymlinkSync } from "./ensure_symlink.ts";
const testdataDir = path.resolve("fs", "testdata");
const isWindows = Deno.build.os === "win";
test(async function ensureSymlinkIfItNotExist(): Promise<void> {
Deno.test(async function ensureSymlinkIfItNotExist(): Promise<void> {
const testDir = path.join(testdataDir, "link_file_1");
const testFile = path.join(testDir, "test.txt");
@ -31,7 +30,7 @@ test(async function ensureSymlinkIfItNotExist(): Promise<void> {
);
});
test(function ensureSymlinkSyncIfItNotExist(): void {
Deno.test(function ensureSymlinkSyncIfItNotExist(): void {
const testDir = path.join(testdataDir, "link_file_2");
const testFile = path.join(testDir, "test.txt");
@ -45,7 +44,7 @@ test(function ensureSymlinkSyncIfItNotExist(): void {
});
});
test(async function ensureSymlinkIfItExist(): Promise<void> {
Deno.test(async function ensureSymlinkIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "link_file_3");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@ -74,7 +73,7 @@ test(async function ensureSymlinkIfItExist(): Promise<void> {
await Deno.remove(testDir, { recursive: true });
});
test(function ensureSymlinkSyncIfItExist(): void {
Deno.test(function ensureSymlinkSyncIfItExist(): void {
const testDir = path.join(testdataDir, "link_file_4");
const testFile = path.join(testDir, "test.txt");
const linkFile = path.join(testDir, "link.txt");
@ -104,7 +103,7 @@ test(function ensureSymlinkSyncIfItExist(): void {
Deno.removeSync(testDir, { recursive: true });
});
test(async function ensureSymlinkDirectoryIfItExist(): Promise<void> {
Deno.test(async function ensureSymlinkDirectoryIfItExist(): Promise<void> {
const testDir = path.join(testdataDir, "link_file_origin_3");
const linkDir = path.join(testdataDir, "link_file_link_3");
const testFile = path.join(testDir, "test.txt");
@ -136,7 +135,7 @@ test(async function ensureSymlinkDirectoryIfItExist(): Promise<void> {
await Deno.remove(testDir, { recursive: true });
});
test(function ensureSymlinkSyncDirectoryIfItExist(): void {
Deno.test(function ensureSymlinkSyncDirectoryIfItExist(): void {
const testDir = path.join(testdataDir, "link_file_origin_3");
const linkDir = path.join(testdataDir, "link_file_link_3");
const testFile = path.join(testDir, "test.txt");

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { format, detect, EOL } from "./eol.ts";
@ -9,28 +8,28 @@ const Mixedinput2 = "deno\r\nis not\nnode";
const LFinput = "deno\nis not\nnode";
const NoNLinput = "deno is not node";
test({
Deno.test({
name: "[EOL] Detect CR LF",
fn(): void {
assertEquals(detect(CRLFinput), EOL.CRLF);
}
});
test({
Deno.test({
name: "[EOL] Detect LF",
fn(): void {
assertEquals(detect(LFinput), EOL.LF);
}
});
test({
Deno.test({
name: "[EOL] Detect No New Line",
fn(): void {
assertEquals(detect(NoNLinput), null);
}
});
test({
Deno.test({
name: "[EOL] Detect Mixed",
fn(): void {
assertEquals(detect(Mixedinput), EOL.CRLF);
@ -38,7 +37,7 @@ test({
}
});
test({
Deno.test({
name: "[EOL] Format",
fn(): void {
assertEquals(format(CRLFinput, EOL.LF), LFinput);

View file

@ -1,12 +1,11 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import { assertEquals, assertStrContains } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { exists, existsSync } from "./exists.ts";
const testdataDir = path.resolve("fs", "testdata");
test(async function existsFile(): Promise<void> {
Deno.test(async function existsFile(): Promise<void> {
assertEquals(
await exists(path.join(testdataDir, "not_exist_file.ts")),
false
@ -14,12 +13,12 @@ test(async function existsFile(): Promise<void> {
assertEquals(await existsSync(path.join(testdataDir, "0.ts")), true);
});
test(function existsFileSync(): void {
Deno.test(function existsFileSync(): void {
assertEquals(existsSync(path.join(testdataDir, "not_exist_file.ts")), false);
assertEquals(existsSync(path.join(testdataDir, "0.ts")), true);
});
test(async function existsDirectory(): Promise<void> {
Deno.test(async function existsDirectory(): Promise<void> {
assertEquals(
await exists(path.join(testdataDir, "not_exist_directory")),
false
@ -27,7 +26,7 @@ test(async function existsDirectory(): Promise<void> {
assertEquals(existsSync(testdataDir), true);
});
test(function existsDirectorySync(): void {
Deno.test(function existsDirectorySync(): void {
assertEquals(
existsSync(path.join(testdataDir, "not_exist_directory")),
false
@ -35,19 +34,19 @@ test(function existsDirectorySync(): void {
assertEquals(existsSync(testdataDir), true);
});
test(function existsLinkSync(): void {
Deno.test(function existsLinkSync(): void {
// TODO(axetroy): generate link file use Deno api instead of set a link file
// in repository
assertEquals(existsSync(path.join(testdataDir, "0-link.ts")), true);
});
test(async function existsLink(): Promise<void> {
Deno.test(async function existsLink(): Promise<void> {
// TODO(axetroy): generate link file use Deno api instead of set a link file
// in repository
assertEquals(await exists(path.join(testdataDir, "0-link.ts")), true);
});
test(async function existsPermission(): Promise<void> {
Deno.test(async function existsPermission(): Promise<void> {
interface Scenes {
read: boolean; // --allow-read
async: boolean;

View file

@ -1,6 +1,5 @@
const { cwd, execPath, run } = Deno;
import { decode } from "../strings/mod.ts";
import { test, runIfMain } from "../testing/mod.ts";
import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts";
import {
isWindows,
@ -52,7 +51,7 @@ const EG_OPTIONS: ExpandGlobOptions = {
globstar: false
};
test(async function expandGlobWildcard(): Promise<void> {
Deno.test(async function expandGlobWildcard(): Promise<void> {
const options = EG_OPTIONS;
assertEquals(await expandGlobArray("*", options), [
"abc",
@ -62,12 +61,12 @@ test(async function expandGlobWildcard(): Promise<void> {
]);
});
test(async function expandGlobTrailingSeparator(): Promise<void> {
Deno.test(async function expandGlobTrailingSeparator(): Promise<void> {
const options = EG_OPTIONS;
assertEquals(await expandGlobArray("*/", options), ["subdir"]);
});
test(async function expandGlobParent(): Promise<void> {
Deno.test(async function expandGlobParent(): Promise<void> {
const options = EG_OPTIONS;
assertEquals(await expandGlobArray("subdir/../*", options), [
"abc",
@ -77,7 +76,7 @@ test(async function expandGlobParent(): Promise<void> {
]);
});
test(async function expandGlobExt(): Promise<void> {
Deno.test(async function expandGlobExt(): Promise<void> {
const options = { ...EG_OPTIONS, extended: true };
assertEquals(await expandGlobArray("abc?(def|ghi)", options), [
"abc",
@ -97,7 +96,7 @@ test(async function expandGlobExt(): Promise<void> {
assertEquals(await expandGlobArray("abc!(def|ghi)", options), ["abc"]);
});
test(async function expandGlobGlobstar(): Promise<void> {
Deno.test(async function expandGlobGlobstar(): Promise<void> {
const options = { ...EG_OPTIONS, globstar: true };
assertEquals(
await expandGlobArray(joinGlobs(["**", "abc"], options), options),
@ -105,7 +104,7 @@ test(async function expandGlobGlobstar(): Promise<void> {
);
});
test(async function expandGlobGlobstarParent(): Promise<void> {
Deno.test(async function expandGlobGlobstarParent(): Promise<void> {
const options = { ...EG_OPTIONS, globstar: true };
assertEquals(
await expandGlobArray(joinGlobs(["subdir", "**", ".."], options), options),
@ -113,12 +112,12 @@ test(async function expandGlobGlobstarParent(): Promise<void> {
);
});
test(async function expandGlobIncludeDirs(): Promise<void> {
Deno.test(async function expandGlobIncludeDirs(): Promise<void> {
const options = { ...EG_OPTIONS, includeDirs: false };
assertEquals(await expandGlobArray("subdir", options), []);
});
test(async function expandGlobPermError(): Promise<void> {
Deno.test(async function expandGlobPermError(): Promise<void> {
const exampleUrl = new URL("testdata/expand_wildcard.js", import.meta.url);
const p = run({
args: [execPath(), exampleUrl.toString()],
@ -133,5 +132,3 @@ test(async function expandGlobPermError(): Promise<void> {
"Uncaught PermissionDenied"
);
});
runIfMain(import.meta);

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import {
assertEquals,
assertThrows,
@ -13,7 +12,7 @@ import { exists, existsSync } from "./exists.ts";
const testdataDir = path.resolve("fs", "testdata");
test(async function moveDirectoryIfSrcNotExists(): Promise<void> {
Deno.test(async function moveDirectoryIfSrcNotExists(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_1");
const destDir = path.join(testdataDir, "move_test_dest_1");
// if src directory not exist
@ -24,7 +23,7 @@ test(async function moveDirectoryIfSrcNotExists(): Promise<void> {
);
});
test(async function moveDirectoryIfDestNotExists(): Promise<void> {
Deno.test(async function moveDirectoryIfDestNotExists(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_2");
const destDir = path.join(testdataDir, "move_test_dest_2");
@ -43,7 +42,7 @@ test(async function moveDirectoryIfDestNotExists(): Promise<void> {
await Deno.remove(destDir);
});
test(async function moveFileIfSrcNotExists(): Promise<void> {
Deno.test(async function moveFileIfSrcNotExists(): Promise<void> {
const srcFile = path.join(testdataDir, "move_test_src_3", "test.txt");
const destFile = path.join(testdataDir, "move_test_dest_3", "test.txt");
@ -55,7 +54,7 @@ test(async function moveFileIfSrcNotExists(): Promise<void> {
);
});
test(async function moveFileIfDestExists(): Promise<void> {
Deno.test(async function moveFileIfDestExists(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_4");
const destDir = path.join(testdataDir, "move_test_dest_4");
const srcFile = path.join(srcDir, "test.txt");
@ -105,7 +104,7 @@ test(async function moveFileIfDestExists(): Promise<void> {
]);
});
test(async function moveDirectory(): Promise<void> {
Deno.test(async function moveDirectory(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_5");
const destDir = path.join(testdataDir, "move_test_dest_5");
const srcFile = path.join(srcDir, "test.txt");
@ -130,7 +129,7 @@ test(async function moveDirectory(): Promise<void> {
await Deno.remove(destDir, { recursive: true });
});
test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite(): Promise<
Deno.test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite(): Promise<
void
> {
const srcDir = path.join(testdataDir, "move_test_src_6");
@ -165,7 +164,7 @@ test(async function moveIfSrcAndDestDirectoryExistsAndOverwrite(): Promise<
await Deno.remove(destDir, { recursive: true });
});
test(async function moveIntoSubDir(): Promise<void> {
Deno.test(async function moveIntoSubDir(): Promise<void> {
const srcDir = path.join(testdataDir, "move_test_src_7");
const destDir = path.join(srcDir, "nest");
@ -181,7 +180,7 @@ test(async function moveIntoSubDir(): Promise<void> {
await Deno.remove(srcDir, { recursive: true });
});
test(function moveSyncDirectoryIfSrcNotExists(): void {
Deno.test(function moveSyncDirectoryIfSrcNotExists(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_1");
const destDir = path.join(testdataDir, "move_sync_test_dest_1");
// if src directory not exist
@ -190,7 +189,7 @@ test(function moveSyncDirectoryIfSrcNotExists(): void {
});
});
test(function moveSyncDirectoryIfDestNotExists(): void {
Deno.test(function moveSyncDirectoryIfDestNotExists(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_2");
const destDir = path.join(testdataDir, "move_sync_test_dest_2");
@ -209,7 +208,7 @@ test(function moveSyncDirectoryIfDestNotExists(): void {
Deno.removeSync(destDir);
});
test(function moveSyncFileIfSrcNotExists(): void {
Deno.test(function moveSyncFileIfSrcNotExists(): void {
const srcFile = path.join(testdataDir, "move_sync_test_src_3", "test.txt");
const destFile = path.join(testdataDir, "move_sync_test_dest_3", "test.txt");
@ -219,7 +218,7 @@ test(function moveSyncFileIfSrcNotExists(): void {
});
});
test(function moveSyncFileIfDestExists(): void {
Deno.test(function moveSyncFileIfDestExists(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_4");
const destDir = path.join(testdataDir, "move_sync_test_dest_4");
const srcFile = path.join(srcDir, "test.txt");
@ -266,7 +265,7 @@ test(function moveSyncFileIfDestExists(): void {
Deno.removeSync(destDir, { recursive: true });
});
test(function moveSyncDirectory(): void {
Deno.test(function moveSyncDirectory(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_5");
const destDir = path.join(testdataDir, "move_sync_test_dest_5");
const srcFile = path.join(srcDir, "test.txt");
@ -289,7 +288,7 @@ test(function moveSyncDirectory(): void {
Deno.removeSync(destDir, { recursive: true });
});
test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite(): void {
Deno.test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_6");
const destDir = path.join(testdataDir, "move_sync_test_dest_6");
const srcFile = path.join(srcDir, "test.txt");
@ -316,7 +315,7 @@ test(function moveSyncIfSrcAndDestDirectoryExistsAndOverwrite(): void {
Deno.removeSync(destDir, { recursive: true });
});
test(function moveSyncIntoSubDir(): void {
Deno.test(function moveSyncIntoSubDir(): void {
const srcDir = path.join(testdataDir, "move_sync_test_src_7");
const destDir = path.join(srcDir, "nest");

View file

@ -1,18 +1,17 @@
import { test } from "../testing/mod.ts";
import { assert } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { readFileStrSync, readFileStr } from "./read_file_str.ts";
const testdataDir = path.resolve("fs", "testdata");
test(function testReadFileSync(): void {
Deno.test(function testReadFileSync(): void {
const jsonFile = path.join(testdataDir, "json_valid_obj.json");
const strFile = readFileStrSync(jsonFile);
assert(typeof strFile === "string");
assert(strFile.length > 0);
});
test(async function testReadFile(): Promise<void> {
Deno.test(async function testReadFile(): Promise<void> {
const jsonFile = path.join(testdataDir, "json_valid_obj.json");
const strFile = await readFileStr(jsonFile);
assert(typeof strFile === "string");

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import {
assertEquals,
assertThrowsAsync,
@ -10,7 +9,7 @@ import { readJson, readJsonSync } from "./read_json.ts";
const testdataDir = path.resolve("fs", "testdata");
test(async function readJsonFileNotExists(): Promise<void> {
Deno.test(async function readJsonFileNotExists(): Promise<void> {
const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
await assertThrowsAsync(
@ -20,7 +19,7 @@ test(async function readJsonFileNotExists(): Promise<void> {
);
});
test(async function readEmptyJsonFile(): Promise<void> {
Deno.test(async function readEmptyJsonFile(): Promise<void> {
const emptyJsonFile = path.join(testdataDir, "json_empty.json");
await assertThrowsAsync(
@ -30,7 +29,7 @@ test(async function readEmptyJsonFile(): Promise<void> {
);
});
test(async function readInvalidJsonFile(): Promise<void> {
Deno.test(async function readInvalidJsonFile(): Promise<void> {
const invalidJsonFile = path.join(testdataDir, "json_invalid.json");
await assertThrowsAsync(
@ -40,7 +39,7 @@ test(async function readInvalidJsonFile(): Promise<void> {
);
});
test(async function readValidArrayJsonFile(): Promise<void> {
Deno.test(async function readValidArrayJsonFile(): Promise<void> {
const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
const json = await readJson(invalidJsonFile);
@ -48,7 +47,7 @@ test(async function readValidArrayJsonFile(): Promise<void> {
assertEquals(json, ["1", "2", "3"]);
});
test(async function readValidObjJsonFile(): Promise<void> {
Deno.test(async function readValidObjJsonFile(): Promise<void> {
const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
const json = await readJson(invalidJsonFile);
@ -56,13 +55,13 @@ test(async function readValidObjJsonFile(): Promise<void> {
assertEquals(json, { key1: "value1", key2: "value2" });
});
test(async function readValidObjJsonFileWithRelativePath(): Promise<void> {
Deno.test(async function readValidObjJsonFileWithRelativePath(): Promise<void> {
const json = await readJson("./fs/testdata/json_valid_obj.json");
assertEquals(json, { key1: "value1", key2: "value2" });
});
test(function readJsonFileNotExistsSync(): void {
Deno.test(function readJsonFileNotExistsSync(): void {
const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
assertThrows((): void => {
@ -70,7 +69,7 @@ test(function readJsonFileNotExistsSync(): void {
});
});
test(function readEmptyJsonFileSync(): void {
Deno.test(function readEmptyJsonFileSync(): void {
const emptyJsonFile = path.join(testdataDir, "json_empty.json");
assertThrows((): void => {
@ -78,7 +77,7 @@ test(function readEmptyJsonFileSync(): void {
});
});
test(function readInvalidJsonFile(): void {
Deno.test(function readInvalidJsonFile(): void {
const invalidJsonFile = path.join(testdataDir, "json_invalid.json");
assertThrows((): void => {
@ -86,7 +85,7 @@ test(function readInvalidJsonFile(): void {
});
});
test(function readValidArrayJsonFileSync(): void {
Deno.test(function readValidArrayJsonFileSync(): void {
const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
const json = readJsonSync(invalidJsonFile);
@ -94,7 +93,7 @@ test(function readValidArrayJsonFileSync(): void {
assertEquals(json, ["1", "2", "3"]);
});
test(function readValidObjJsonFileSync(): void {
Deno.test(function readValidObjJsonFileSync(): void {
const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
const json = readJsonSync(invalidJsonFile);
@ -102,7 +101,7 @@ test(function readValidObjJsonFileSync(): void {
assertEquals(json, { key1: "value1", key2: "value2" });
});
test(function readValidObjJsonFileSyncWithRelativePath(): void {
Deno.test(function readValidObjJsonFileSyncWithRelativePath(): void {
const json = readJsonSync("./fs/testdata/json_valid_obj.json");
assertEquals(json, { key1: "value1", key2: "value2" });

View file

@ -1,6 +1,5 @@
// Copyright the Browserify authors. MIT License.
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { isSubdir, getFileInfoType, PathType } from "./utils.ts";
@ -9,7 +8,7 @@ import { ensureDirSync } from "./ensure_dir.ts";
const testdataDir = path.resolve("fs", "testdata");
test(function _isSubdir(): void {
Deno.test(function _isSubdir(): void {
const pairs = [
["", "", false, path.posix.sep],
["/first/second", "/first", false, path.posix.sep],
@ -34,7 +33,7 @@ test(function _isSubdir(): void {
});
});
test(function _getFileInfoType(): void {
Deno.test(function _getFileInfoType(): void {
const pairs = [
[path.join(testdataDir, "file_type_1"), "file"],
[path.join(testdataDir, "file_type_dir_1"), "dir"]

View file

@ -3,12 +3,11 @@ const { remove } = Deno;
type ErrorKind = Deno.ErrorKind;
type DenoError = Deno.DenoError<ErrorKind>;
import { walk, walkSync, WalkOptions, WalkInfo } from "./walk.ts";
import { test, TestFunction, runIfMain } from "../testing/mod.ts";
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
export async function testWalk(
setup: (arg0: string) => void | Promise<void>,
t: TestFunction
t: Deno.TestFunction
): Promise<void> {
const name = t.name;
async function fn(): Promise<void> {
@ -23,7 +22,7 @@ export async function testWalk(
remove(d, { recursive: true });
}
}
test({ name, fn });
Deno.test({ name, fn });
}
function normalize({ filename }: WalkInfo): string {
@ -275,5 +274,3 @@ testWalk(
}
);
*/
runIfMain(import.meta);

View file

@ -1,11 +1,10 @@
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { writeFileStr, writeFileStrSync } from "./write_file_str.ts";
const testdataDir = path.resolve("fs", "testdata");
test(function testReadFileSync(): void {
Deno.test(function testReadFileSync(): void {
const jsonFile = path.join(testdataDir, "write_file_1.json");
const content = "write_file_str_test";
writeFileStrSync(jsonFile, content);
@ -21,7 +20,7 @@ test(function testReadFileSync(): void {
assertEquals(content, result);
});
test(async function testReadFile(): Promise<void> {
Deno.test(async function testReadFile(): Promise<void> {
const jsonFile = path.join(testdataDir, "write_file_2.json");
const content = "write_file_str_test";
await writeFileStr(jsonFile, content);

View file

@ -1,5 +1,4 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
import {
assertEquals,
assertThrowsAsync,
@ -10,7 +9,7 @@ import { writeJson, writeJsonSync } from "./write_json.ts";
const testdataDir = path.resolve("fs", "testdata");
test(async function writeJsonIfNotExists(): Promise<void> {
Deno.test(async function writeJsonIfNotExists(): Promise<void> {
const notExistsJsonFile = path.join(testdataDir, "file_not_exists.json");
await assertThrowsAsync(
@ -29,7 +28,7 @@ test(async function writeJsonIfNotExists(): Promise<void> {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
test(async function writeJsonIfExists(): Promise<void> {
Deno.test(async function writeJsonIfExists(): Promise<void> {
const existsJsonFile = path.join(testdataDir, "file_write_exists.json");
await Deno.writeFile(existsJsonFile, new Uint8Array());
@ -50,7 +49,7 @@ test(async function writeJsonIfExists(): Promise<void> {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
test(async function writeJsonIfExistsAnInvalidJson(): Promise<void> {
Deno.test(async function writeJsonIfExistsAnInvalidJson(): Promise<void> {
const existsInvalidJsonFile = path.join(
testdataDir,
"file_write_invalid.json"
@ -75,7 +74,7 @@ test(async function writeJsonIfExistsAnInvalidJson(): Promise<void> {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
test(async function writeJsonWithSpaces(): Promise<void> {
Deno.test(async function writeJsonWithSpaces(): Promise<void> {
const existsJsonFile = path.join(testdataDir, "file_write_spaces.json");
const invalidJsonContent = new TextEncoder().encode();
@ -97,7 +96,7 @@ test(async function writeJsonWithSpaces(): Promise<void> {
assertEquals(new TextDecoder().decode(content), `{\n "a": "1"\n}`);
});
test(async function writeJsonWithReplacer(): Promise<void> {
Deno.test(async function writeJsonWithReplacer(): Promise<void> {
const existsJsonFile = path.join(testdataDir, "file_write_replacer.json");
const invalidJsonContent = new TextEncoder().encode();
@ -125,7 +124,7 @@ test(async function writeJsonWithReplacer(): Promise<void> {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
test(function writeJsonSyncIfNotExists(): void {
Deno.test(function writeJsonSyncIfNotExists(): void {
const notExistsJsonFile = path.join(testdataDir, "file_not_exists_sync.json");
assertThrows(
@ -144,7 +143,7 @@ test(function writeJsonSyncIfNotExists(): void {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
test(function writeJsonSyncIfExists(): void {
Deno.test(function writeJsonSyncIfExists(): void {
const existsJsonFile = path.join(testdataDir, "file_write_exists_sync.json");
Deno.writeFileSync(existsJsonFile, new Uint8Array());
@ -165,7 +164,7 @@ test(function writeJsonSyncIfExists(): void {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
test(function writeJsonSyncIfExistsAnInvalidJson(): void {
Deno.test(function writeJsonSyncIfExistsAnInvalidJson(): void {
const existsInvalidJsonFile = path.join(
testdataDir,
"file_write_invalid_sync.json"
@ -190,7 +189,7 @@ test(function writeJsonSyncIfExistsAnInvalidJson(): void {
assertEquals(new TextDecoder().decode(content), `{"a":"1"}`);
});
test(function writeJsonWithSpaces(): void {
Deno.test(function writeJsonWithSpaces(): void {
const existsJsonFile = path.join(testdataDir, "file_write_spaces_sync.json");
const invalidJsonContent = new TextEncoder().encode();
@ -212,7 +211,7 @@ test(function writeJsonWithSpaces(): void {
assertEquals(new TextDecoder().decode(content), `{\n "a": "1"\n}`);
});
test(function writeJsonWithReplacer(): void {
Deno.test(function writeJsonWithReplacer(): void {
const existsJsonFile = path.join(
testdataDir,
"file_write_replacer_sync.json"

View file

@ -2,9 +2,8 @@
import { ServerRequest, Response } from "./server.ts";
import { getCookies, delCookie, setCookie } from "./cookie.ts";
import { assert, assertEquals } from "../testing/asserts.ts";
import { test } from "../testing/mod.ts";
test({
Deno.test({
name: "[HTTP] Cookie parser",
fn(): void {
const req = new ServerRequest();
@ -32,7 +31,7 @@ test({
}
});
test({
Deno.test({
name: "[HTTP] Cookie Delete",
fn(): void {
const res: Response = {};
@ -44,7 +43,7 @@ test({
}
});
test({
Deno.test({
name: "[HTTP] Cookie Set",
fn(): void {
const res: Response = {};

View file

@ -1,8 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test, runIfMain } from "../testing/mod.ts";
import { assert, assertEquals, assertStrContains } from "../testing/asserts.ts";
import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
const { test } = Deno;
let fileServer: Deno.Process;
@ -135,5 +135,3 @@ test(async function printHelp(): Promise<void> {
helpProcess.close();
helpProcess.stdout.close();
});
runIfMain(import.meta);

View file

@ -1,6 +1,5 @@
const { connect, run } = Deno;
import { test, runIfMain } from "../testing/mod.ts";
import { assert, assertEquals } from "../testing/asserts.ts";
import { BufReader } from "../io/bufio.ts";
import { TextProtoReader } from "../textproto/mod.ts";
@ -48,7 +47,7 @@ content-length: 8
World 4
`;
test(async function serverPipelineRace(): Promise<void> {
Deno.test(async function serverPipelineRace(): Promise<void> {
await startServer();
const conn = await connect({ port: 4501 });
@ -62,5 +61,3 @@ test(async function serverPipelineRace(): Promise<void> {
}
killServer();
});
runIfMain(import.meta);

View file

@ -5,9 +5,8 @@
// Ported from
// https://github.com/golang/go/blob/master/src/net/http/responsewrite_test.go
const { Buffer } = Deno;
const { Buffer, test } = Deno;
import { TextProtoReader } from "../textproto/mod.ts";
import { test, runIfMain } from "../testing/mod.ts";
import {
assert,
assertEquals,
@ -820,5 +819,3 @@ test("writeTrailer should throw", async () => {
"Not trailer"
);
});
runIfMain(import.meta);

View file

@ -5,7 +5,6 @@
const { Buffer } = Deno;
type Reader = Deno.Reader;
import { test, runIfMain } from "../testing/mod.ts";
import {
assert,
assertEquals,
@ -43,7 +42,7 @@ async function readBytes(buf: BufReader): Promise<string> {
return decoder.decode(b.subarray(0, nb));
}
test(async function bufioReaderSimple(): Promise<void> {
Deno.test(async function bufioReaderSimple(): Promise<void> {
const data = "hello world";
const b = new BufReader(stringsReader(data));
const s = await readBytes(b);
@ -111,7 +110,7 @@ const bufsizes: number[] = [
4096
];
test(async function bufioBufReader(): Promise<void> {
Deno.test(async function bufioBufReader(): Promise<void> {
const texts = new Array<string>(31);
let str = "";
let all = "";
@ -139,7 +138,7 @@ test(async function bufioBufReader(): Promise<void> {
}
});
test(async function bufioBufferFull(): Promise<void> {
Deno.test(async function bufioBufferFull(): Promise<void> {
const longString =
"And now, hello, world! It is the time for all good men to come to the" +
" aid of their party";
@ -160,7 +159,7 @@ test(async function bufioBufferFull(): Promise<void> {
assertEquals(actual, "world!");
});
test(async function bufioReadString(): Promise<void> {
Deno.test(async function bufioReadString(): Promise<void> {
const string = "And now, hello world!";
const buf = new BufReader(stringsReader(string), MIN_READ_BUFFER_SIZE);
@ -242,12 +241,12 @@ async function testReadLine(input: Uint8Array): Promise<void> {
}
}
test(async function bufioReadLine(): Promise<void> {
Deno.test(async function bufioReadLine(): Promise<void> {
await testReadLine(testInput);
await testReadLine(testInputrn);
});
test(async function bufioPeek(): Promise<void> {
Deno.test(async function bufioPeek(): Promise<void> {
const decoder = new TextDecoder();
const p = new Uint8Array(10);
// string is 16 (minReadBufferSize) long.
@ -323,7 +322,7 @@ test(async function bufioPeek(): Promise<void> {
*/
});
test(async function bufioWriter(): Promise<void> {
Deno.test(async function bufioWriter(): Promise<void> {
const data = new Uint8Array(8192);
for (let i = 0; i < data.byteLength; i++) {
@ -357,7 +356,7 @@ test(async function bufioWriter(): Promise<void> {
}
});
test(async function bufReaderReadFull(): Promise<void> {
Deno.test(async function bufReaderReadFull(): Promise<void> {
const enc = new TextEncoder();
const dec = new TextDecoder();
const text = "Hello World";
@ -382,5 +381,3 @@ test(async function bufReaderReadFull(): Promise<void> {
}
}
});
runIfMain(import.meta);

View file

@ -1,7 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
const { Buffer } = Deno;
type Reader = Deno.Reader;
import { test } from "../testing/mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import {
copyN,
@ -25,19 +24,19 @@ class BinaryReader implements Reader {
}
}
test(async function testReadShort(): Promise<void> {
Deno.test(async function testReadShort(): Promise<void> {
const r = new BinaryReader(new Uint8Array([0x12, 0x34]));
const short = await readShort(new BufReader(r));
assertEquals(short, 0x1234);
});
test(async function testReadInt(): Promise<void> {
Deno.test(async function testReadInt(): Promise<void> {
const r = new BinaryReader(new Uint8Array([0x12, 0x34, 0x56, 0x78]));
const int = await readInt(new BufReader(r));
assertEquals(int, 0x12345678);
});
test(async function testReadLong(): Promise<void> {
Deno.test(async function testReadLong(): Promise<void> {
const r = new BinaryReader(
new Uint8Array([0x00, 0x00, 0x00, 0x78, 0x12, 0x34, 0x56, 0x78])
);
@ -45,7 +44,7 @@ test(async function testReadLong(): Promise<void> {
assertEquals(long, 0x7812345678);
});
test(async function testReadLong2(): Promise<void> {
Deno.test(async function testReadLong2(): Promise<void> {
const r = new BinaryReader(
new Uint8Array([0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78])
);
@ -53,7 +52,7 @@ test(async function testReadLong2(): Promise<void> {
assertEquals(long, 0x12345678);
});
test(async function testSliceLongToBytes(): Promise<void> {
Deno.test(async function testSliceLongToBytes(): Promise<void> {
const arr = sliceLongToBytes(0x1234567890abcdef);
const actual = readLong(new BufReader(new BinaryReader(new Uint8Array(arr))));
const expected = readLong(
@ -66,12 +65,12 @@ test(async function testSliceLongToBytes(): Promise<void> {
assertEquals(actual, expected);
});
test(async function testSliceLongToBytes2(): Promise<void> {
Deno.test(async function testSliceLongToBytes2(): Promise<void> {
const arr = sliceLongToBytes(0x12345678);
assertEquals(arr, [0, 0, 0, 0, 0x12, 0x34, 0x56, 0x78]);
});
test(async function testCopyN1(): Promise<void> {
Deno.test(async function testCopyN1(): Promise<void> {
const w = new Buffer();
const r = stringsReader("abcdefghij");
const n = await copyN(w, r, 3);
@ -79,7 +78,7 @@ test(async function testCopyN1(): Promise<void> {
assertEquals(w.toString(), "abc");
});
test(async function testCopyN2(): Promise<void> {
Deno.test(async function testCopyN2(): Promise<void> {
const w = new Buffer();
const r = stringsReader("abcdefghij");
const n = await copyN(w, r, 11);

View file

@ -1,5 +1,4 @@
const { copy } = Deno;
import { test } from "../testing/mod.ts";
const { copy, test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { MultiReader, StringReader } from "./readers.ts";
import { StringWriter } from "./writers.ts";

View file

@ -1,6 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
const { remove } = Deno;
import { test } from "../testing/mod.ts";
const { remove, test } = Deno;
import { assert, assertEquals } from "../testing/asserts.ts";
import * as path from "../path/mod.ts";
import { copyBytes, tempFile } from "./util.ts";

View file

@ -1,5 +1,4 @@
const { copy } = Deno;
import { test } from "../testing/mod.ts";
const { copy, test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { StringWriter } from "./writers.ts";
import { StringReader } from "./readers.ts";

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { LogLevel, getLevelName, getLevelByName } from "./levels.ts";
import { BaseHandler } from "./handlers.ts";

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { LogRecord, Logger } from "./logger.ts";
import { LogLevel } from "./levels.ts";

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as log from "./mod.ts";
import { LogLevel } from "./levels.ts";

View file

@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import {
lookup,

View file

@ -7,7 +7,7 @@ import {
assertThrows,
assertThrowsAsync
} from "../testing/asserts.ts";
import { test, runIfMain } from "../testing/mod.ts";
const { test } = Deno;
import * as path from "../path/mod.ts";
import {
FormFile,
@ -213,5 +213,3 @@ test(async function multipartMultipartReader2(): Promise<void> {
}
}
});
runIfMain(import.meta);

View file

@ -1,4 +1,4 @@
import { test } from "../testing/mod.ts";
const { test } = Deno;
import {
assert,
assertEquals,

View file

@ -1,5 +1,5 @@
const { test } = Deno;
import { readFile, readFileSync, readlink, readlinkSync } from "./fs.ts";
import { test } from "../testing/mod.ts";
import * as path from "../path/mod.ts";
import { assertEquals, assert } from "../testing/asserts.ts";

View file

@ -1,4 +1,4 @@
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals, assert } from "../testing/asserts.ts";
import { createRequire } from "./module.ts";

View file

@ -1,4 +1,4 @@
import { test } from "../testing/mod.ts";
const { test } = Deno;
import {
assert,
assertThrows,

View file

@ -1,4 +1,4 @@
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assert, assertThrows, assertEquals } from "../testing/asserts.ts";
import { process } from "./process.ts";

View file

@ -1,4 +1,4 @@
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assert } from "../testing/asserts.ts";
import * as util from "./util.ts";

View file

@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -1,5 +1,4 @@
const { mkdir } = Deno;
import { test, runIfMain } from "../testing/mod.ts";
const { mkdir, test } = Deno;
import { assert, assertEquals } from "../testing/asserts.ts";
import { testWalk, touch, walkArray } from "../fs/walk_test.ts";
import { globToRegExp, isGlob, joinGlobs, normalizeGlob } from "./glob.ts";
@ -247,5 +246,3 @@ test(function normalizeGlobGlobstar(): void {
test(function joinGlobsGlobstar(): void {
assertEquals(joinGlobs(["**", ".."], { globstar: true }), `**${SEP}..`);
});
runIfMain(import.meta);

View file

@ -2,7 +2,7 @@
// MIT License
// Copyright (c) 2018 Terkel Gjervig Nielsen
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { GlobrexOptions, globrex } from "./globrex.ts";

View file

@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -1,4 +1,4 @@
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -3,7 +3,7 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
// TODO(kt3k): fix any types in this file
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -1,7 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -1,8 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
const { cwd } = Deno;
import { test } from "../testing/mod.ts";
const { cwd, test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -1,8 +1,7 @@
// Copyright the Browserify authors. MIT License.
// Ported from https://github.com/browserify/path-browserify/
const { cwd } = Deno;
import { test } from "../testing/mod.ts";
const { cwd, test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import * as path from "./mod.ts";

View file

@ -1,4 +1,5 @@
import { test, assertEquals, assertThrows } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals, assertThrows } from "../testing/asserts.ts";
import { delay } from "../util/async.ts";
import { signal } from "./mod.ts";

View file

@ -1,4 +1,4 @@
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { pad } from "./pad.ts";

View file

@ -14,8 +14,8 @@ import {
unimplemented,
unreachable
} from "./asserts.ts";
import { test } from "./mod.ts";
import { red, green, white, gray, bold } from "../fmt/colors.ts";
const { test } = Deno;
test(function testingEqual(): void {
assert(equal("world", "world"));

View file

@ -1,4 +1,4 @@
import { test, runIfMain } from "./mod.ts";
const { test } = Deno;
import { bench, runBenchmarks } from "./bench.ts";
import "./bench_example.ts";
@ -56,5 +56,3 @@ test(async function benching(): Promise<void> {
await runBenchmarks({ skip: /throw/ });
});
runIfMain(import.meta);

View file

@ -1,6 +1,6 @@
import diff from "./diff.ts";
import { assertEquals } from "../testing/asserts.ts";
import { test } from "./mod.ts";
const { test } = Deno;
test({
name: "empty",

View file

@ -6,7 +6,7 @@
* LICENSE file in the root directory of this source tree.
*
*/
import { test } from "./mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { format } from "./format.ts";

View file

@ -1,450 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
export * from "./asserts.ts";
export * from "./bench.ts";
import diff from "./diff.ts";
export { diff };
export * from "./format.ts";
export * from "./runner.ts";
import {
bgRed,
white,
bold,
green,
red,
gray,
yellow,
italic
} from "../fmt/colors.ts";
import { assert } from "./asserts.ts";
export type TestFunction = () => void | Promise<void>;
export interface TestDefinition {
fn: TestFunction;
name: string;
}
// Replacement of the global `console` function to be in silent mode
const noop = function(): void {};
// Clear the current line of the console.
// see: http://ascii-table.com/ansi-escape-sequences-vt-100.php
const CLEAR_LINE = "\x1b[2K\r";
// Save Object of the global `console` in case of silent mode
type Console = typeof window.console;
// ref https://console.spec.whatwg.org/#console-namespace
// For historical web-compatibility reasons, the namespace object for
// console must have as its [[Prototype]] an empty object, created as if
// by ObjectCreate(%ObjectPrototype%), instead of %ObjectPrototype%.
const disabledConsole = Object.create({}) as Console;
Object.assign(disabledConsole, {
log: noop,
debug: noop,
info: noop,
dir: noop,
warn: noop,
error: noop,
assert: noop,
count: noop,
countReset: noop,
table: noop,
time: noop,
timeLog: noop,
timeEnd: noop,
group: noop,
groupCollapsed: noop,
groupEnd: noop,
clear: noop
});
const originalConsole = window.console;
function enableConsole(): void {
window.console = originalConsole;
}
function disableConsole(): void {
window.console = disabledConsole;
}
const encoder = new TextEncoder();
function print(txt: string, newline = true): void {
if (newline) {
txt += "\n";
}
Deno.stdout.writeSync(encoder.encode(`${txt}`));
}
declare global {
interface Window {
/**
* A global property to collect all registered test cases.
*
* It is required because user's code can import multiple versions
* of `testing` module.
*
* If test cases aren't registered in a globally shared
* object, then imports from different versions would register test cases
* to registry from it's respective version of `testing` module.
*/
__DENO_TEST_REGISTRY: TestDefinition[];
}
}
let candidates: TestDefinition[] = [];
if (window["__DENO_TEST_REGISTRY"]) {
candidates = window.__DENO_TEST_REGISTRY as TestDefinition[];
} else {
window["__DENO_TEST_REGISTRY"] = candidates;
}
let filterRegExp: RegExp | null;
let filtered = 0;
// Must be called before any test() that needs to be filtered.
export function setFilter(s: string): void {
filterRegExp = new RegExp(s, "i");
}
function filter(name: string): boolean {
if (filterRegExp) {
return filterRegExp.test(name);
} else {
return true;
}
}
export function test(t: TestDefinition): void;
export function test(fn: TestFunction): void;
export function test(name: string, fn: TestFunction): void;
export function test(
t: string | TestDefinition | TestFunction,
fn?: TestFunction
): void {
let name: string;
if (typeof t === "string") {
if (!fn) {
throw new Error("Missing test function");
}
name = t;
if (!name) {
throw new Error("The name of test case can't be empty");
}
} else if (typeof t === "function") {
fn = t;
name = t.name;
if (!name) {
throw new Error("Test function can't be anonymous");
}
} else {
fn = t.fn;
if (!fn) {
throw new Error("Missing test function");
}
name = t.name;
if (!name) {
throw new Error("The name of test case can't be empty");
}
}
assert(!!name, "The name of test case shouldn't be empty");
assert(!!fn, "Test function shouldn't be empty");
if (filter(name)) {
candidates.push({ fn, name });
} else {
filtered++;
}
}
const RED_FAILED = red("FAILED");
const GREEN_OK = green("OK");
const RED_BG_FAIL = bgRed(" FAIL ");
interface TestStats {
filtered: number;
ignored: number;
measured: number;
passed: number;
failed: number;
}
interface TestResult {
timeElapsed?: number;
name: string;
error?: Error;
ok: boolean;
printed: boolean;
}
interface TestResults {
keys: Map<string, number>;
cases: Map<number, TestResult>;
}
function createTestResults(tests: TestDefinition[]): TestResults {
return tests.reduce(
(acc: TestResults, { name }: TestDefinition, i: number): TestResults => {
acc.keys.set(name, i);
acc.cases.set(i, { name, printed: false, ok: false, error: undefined });
return acc;
},
{ cases: new Map(), keys: new Map() }
);
}
function formatTestTime(time = 0): string {
return `${time.toFixed(2)}ms`;
}
function promptTestTime(time = 0, displayWarning = false): string {
// if time > 5s we display a warning
// only for test time, not the full runtime
if (displayWarning && time >= 5000) {
return bgRed(white(bold(`(${formatTestTime(time)})`)));
} else {
return gray(italic(`(${formatTestTime(time)})`));
}
}
function report(result: TestResult): void {
if (result.ok) {
print(
`${GREEN_OK} ${result.name} ${promptTestTime(
result.timeElapsed,
true
)}`
);
} else if (result.error) {
print(`${RED_FAILED} ${result.name}\n${result.error.stack}`);
} else {
print(`test ${result.name} ... unresolved`);
}
result.printed = true;
}
function printFailedSummary(results: TestResults): void {
results.cases.forEach((v): void => {
if (!v.ok) {
console.error(`${RED_BG_FAIL} ${red(v.name)}`);
console.error(v.error);
}
});
}
function printResults(
stats: TestStats,
results: TestResults,
flush: boolean,
exitOnFail: boolean,
timeElapsed: number
): void {
if (flush) {
for (const result of results.cases.values()) {
if (!result.printed) {
report(result);
if (result.error && exitOnFail) {
break;
}
}
}
}
// Attempting to match the output of Rust's test runner.
print(
`\ntest result: ${stats.failed ? RED_BG_FAIL : GREEN_OK} ` +
`${stats.passed} passed; ${stats.failed} failed; ` +
`${stats.ignored} ignored; ${stats.measured} measured; ` +
`${stats.filtered} filtered out ` +
`${promptTestTime(timeElapsed)}\n`
);
}
function previousPrinted(name: string, results: TestResults): boolean {
const curIndex = results.keys.get(name);
assert(curIndex != null);
if (curIndex === 0) {
return true;
}
const prev = results.cases.get(curIndex - 1);
assert(prev != null);
return prev.printed;
}
async function createTestCase(
stats: TestStats,
results: TestResults,
exitOnFail: boolean,
{ fn, name }: TestDefinition
): Promise<void> {
const i = results.keys.get(name);
assert(i != null);
const result = results.cases.get(i);
assert(result != null);
try {
const start = performance.now();
await fn();
const end = performance.now();
stats.passed++;
result.ok = true;
result.timeElapsed = end - start;
} catch (err) {
stats.failed++;
result.error = err;
if (exitOnFail) {
throw err;
}
}
if (previousPrinted(name, results)) {
report(result);
}
}
function initTestCases(
stats: TestStats,
results: TestResults,
tests: TestDefinition[],
exitOnFail: boolean
): Array<Promise<void>> {
return tests.map(createTestCase.bind(null, stats, results, exitOnFail));
}
async function runTestsParallel(
stats: TestStats,
results: TestResults,
tests: TestDefinition[],
exitOnFail: boolean
): Promise<void> {
try {
await Promise.all(initTestCases(stats, results, tests, exitOnFail));
} catch (_) {
// The error was thrown to stop awaiting all promises if exitOnFail === true
// stats.failed has been incremented and the error stored in results
}
}
async function runTestsSerial(
stats: TestStats,
results: TestResults,
tests: TestDefinition[],
exitOnFail: boolean,
disableLog: boolean
): Promise<void> {
for (const { fn, name } of tests) {
// Displaying the currently running test if silent mode
if (disableLog) {
print(`${yellow("RUNNING")} ${name}`, false);
}
try {
const start = performance.now();
await fn();
const end = performance.now();
if (disableLog) {
// Rewriting the current prompt line to erase `running ....`
print(CLEAR_LINE, false);
}
stats.passed++;
print(
GREEN_OK + " " + name + " " + promptTestTime(end - start, true)
);
results.cases.forEach((v): void => {
if (v.name === name) {
v.ok = true;
v.printed = true;
}
});
} catch (err) {
if (disableLog) {
print(CLEAR_LINE, false);
}
print(`${RED_FAILED} ${name}`);
print(err.stack);
stats.failed++;
results.cases.forEach((v): void => {
if (v.name === name) {
v.error = err;
v.ok = false;
v.printed = true;
}
});
if (exitOnFail) {
break;
}
}
}
}
/** Defines options for controlling execution details of a test suite. */
export interface RunTestsOptions {
parallel?: boolean;
exitOnFail?: boolean;
only?: RegExp;
skip?: RegExp;
disableLog?: boolean;
}
/**
* Runs specified test cases.
* Parallel execution can be enabled via the boolean option; default: serial.
*/
// TODO: change return type to `Promise<boolean>` - ie. don't
// exit but return value
export async function runTests({
parallel = false,
exitOnFail = false,
only = /[^\s]/,
skip = /^\s*$/,
disableLog = false
}: RunTestsOptions = {}): Promise<void> {
const tests: TestDefinition[] = candidates.filter(
({ name }): boolean => only.test(name) && !skip.test(name)
);
const stats: TestStats = {
measured: 0,
ignored: candidates.length - tests.length,
filtered: filtered,
passed: 0,
failed: 0
};
const results: TestResults = createTestResults(tests);
print(`running ${tests.length} tests`);
const start = performance.now();
if (Deno.args.includes("--quiet")) {
disableLog = true;
}
if (disableLog) {
disableConsole();
}
if (parallel) {
await runTestsParallel(stats, results, tests, exitOnFail);
} else {
await runTestsSerial(stats, results, tests, exitOnFail, disableLog);
}
const end = performance.now();
if (disableLog) {
enableConsole();
}
printResults(stats, results, parallel, exitOnFail, end - start);
if (stats.failed) {
// Use setTimeout to avoid the error being ignored due to unhandled
// promise rejections being swallowed.
setTimeout((): void => {
console.error(`There were ${stats.failed} test failures.`);
printFailedSummary(results);
Deno.exit(1);
}, 0);
}
}
/**
* Runs specified test cases if the enclosing script is main.
* Execution mode is toggleable via opts.parallel, defaults to false.
*/
export async function runIfMain(
meta: ImportMeta,
opts?: RunTestsOptions
): Promise<void> {
if (meta.main) {
return runTests(opts);
}
}

View file

@ -3,7 +3,6 @@
import { parse } from "../flags/mod.ts";
import { ExpandGlobOptions, expandGlob } from "../fs/mod.ts";
import { isWindows, join } from "../path/mod.ts";
import { RunTestsOptions, runTests } from "./mod.ts";
const { DenoError, ErrorKind, args, cwd, exit } = Deno;
const DIR_GLOBS = [join("**", "?(*_)test.{js,ts}")];
@ -110,7 +109,7 @@ export async function* findTestModules(
yield* includeUrls.filter(shouldIncludeUrl);
}
export interface RunTestModulesOptions extends RunTestsOptions {
export interface RunTestModulesOptions extends Deno.RunTestsOptions {
include?: string[];
exclude?: string[];
allowNone?: boolean;
@ -168,7 +167,6 @@ export async function runTestModules({
include = ["."],
exclude = [],
allowNone = false,
parallel = false,
exitOnFail = false,
only = /[^\s]/,
skip = /^\s*$/,
@ -233,8 +231,7 @@ export async function runTestModules({
console.log(`Found ${moduleCount} matching test modules.`);
}
await runTests({
parallel,
await Deno.runTests({
exitOnFail,
only,
skip,

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assertEquals } from "../testing/asserts.ts";
import { isWindows } from "../path/mod.ts";
import { test } from "./mod.ts";
import { findTestModules } from "./runner.ts";
const { cwd } = Deno;
const { cwd, test } = Deno;
function urlToFilePath(url: URL): string {
// Since `new URL('file:///C:/a').pathname` is `/C:/a`, remove leading slash.

View file

@ -1,293 +0,0 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test, runIfMain } from "./mod.ts";
import {
assert,
assertEquals,
assertStrictEq,
assertThrows,
assertThrowsAsync
} from "./asserts.ts";
test(function testingAssertEqualActualUncoercable(): void {
let didThrow = false;
const a = Object.create(null);
try {
assertEquals(a, "bar");
} catch (e) {
didThrow = true;
}
assert(didThrow);
});
test(function testingAssertEqualExpectedUncoercable(): void {
let didThrow = false;
const a = Object.create(null);
try {
assertStrictEq("bar", a);
} catch (e) {
didThrow = true;
}
assert(didThrow);
});
test(function testingAssertStrictEqual(): void {
const a = {};
const b = a;
assertStrictEq(a, b);
});
test(function testingAssertNotStrictEqual(): void {
let didThrow = false;
const a = {};
const b = {};
try {
assertStrictEq(a, b);
} catch (e) {
assert(e.message === "actual: [object Object] expected: [object Object]");
didThrow = true;
}
assert(didThrow);
});
test(function testingDoesThrow(): void {
let count = 0;
assertThrows((): void => {
count++;
throw new Error();
});
assert(count === 1);
});
test(function testingDoesNotThrow(): void {
let count = 0;
let didThrow = false;
try {
assertThrows((): void => {
count++;
console.log("Hello world");
});
} catch (e) {
assert(e.message === "Expected function to throw.");
didThrow = true;
}
assert(count === 1);
assert(didThrow);
});
test(function testingThrowsErrorType(): void {
let count = 0;
assertThrows((): void => {
count++;
throw new TypeError();
}, TypeError);
assert(count === 1);
});
test(function testingThrowsNotErrorType(): void {
let count = 0;
let didThrow = false;
try {
assertThrows((): void => {
count++;
throw new TypeError();
}, RangeError);
} catch (e) {
assert(e.message === `Expected error to be instance of "RangeError".`);
didThrow = true;
}
assert(count === 1);
assert(didThrow);
});
test(function testingThrowsMsgIncludes(): void {
let count = 0;
assertThrows(
(): void => {
count++;
throw new TypeError("Hello world!");
},
TypeError,
"world"
);
assert(count === 1);
});
test(function testingThrowsMsgNotIncludes(): void {
let count = 0;
let didThrow = false;
try {
assertThrows(
(): void => {
count++;
throw new TypeError("Hello world!");
},
TypeError,
"foobar"
);
} catch (e) {
assert(
e.message ===
`Expected error message to include "foobar", but got "Hello world!".`
);
didThrow = true;
}
assert(count === 1);
assert(didThrow);
});
test(async function testingDoesThrowAsync(): Promise<void> {
let count = 0;
await assertThrowsAsync(
async (): Promise<void> => {
count++;
throw new Error();
}
);
assert(count === 1);
});
test(async function testingDoesReject(): Promise<void> {
let count = 0;
await assertThrowsAsync(
(): Promise<never> => {
count++;
return Promise.reject(new Error());
}
);
assert(count === 1);
});
test(async function testingDoesNotThrowAsync(): Promise<void> {
let count = 0;
let didThrow = false;
try {
await assertThrowsAsync(
async (): Promise<void> => {
count++;
console.log("Hello world");
}
);
} catch (e) {
assert(e.message === "Expected function to throw.");
didThrow = true;
}
assert(count === 1);
assert(didThrow);
});
test(async function testingDoesNotRejectAsync(): Promise<void> {
let count = 0;
let didThrow = false;
try {
await assertThrowsAsync(
(): Promise<void> => {
count++;
console.log("Hello world");
return Promise.resolve();
}
);
} catch (e) {
assert(e.message === "Expected function to throw.");
didThrow = true;
}
assert(count === 1);
assert(didThrow);
});
test(async function testingThrowsAsyncErrorType(): Promise<void> {
let count = 0;
await assertThrowsAsync((): Promise<void> => {
count++;
throw new TypeError();
}, TypeError);
assert(count === 1);
});
test(async function testingThrowsAsyncNotErrorType(): Promise<void> {
let count = 0;
let didThrow = false;
try {
await assertThrowsAsync(async (): Promise<void> => {
count++;
throw new TypeError();
}, RangeError);
} catch (e) {
assert(e.message === `Expected error to be instance of "RangeError".`);
didThrow = true;
}
assert(count === 1);
assert(didThrow);
});
test(async function testingThrowsAsyncMsgIncludes(): Promise<void> {
let count = 0;
await assertThrowsAsync(
async (): Promise<void> => {
count++;
throw new TypeError("Hello world!");
},
TypeError,
"world"
);
assert(count === 1);
});
test(async function testingThrowsAsyncMsgNotIncludes(): Promise<void> {
let count = 0;
let didThrow = false;
try {
await assertThrowsAsync(
async (): Promise<void> => {
count++;
throw new TypeError("Hello world!");
},
TypeError,
"foobar"
);
} catch (e) {
assert(
e.message ===
`Expected error message to include "foobar", but got "Hello world!".`
);
didThrow = true;
}
assert(count === 1);
assert(didThrow);
});
test("test fn overloading", (): void => {
// just verifying that you can use this test definition syntax
assert(true);
});
test("The name of test case can't be empty", () => {
assertThrows(
() => {
test("", () => {});
},
Error,
"The name of test case can't be empty"
);
assertThrows(
() => {
test({
name: "",
fn: () => {}
});
},
Error,
"The name of test case can't be empty"
);
});
test("test function can't be anonymous", () => {
assertThrows(
() => {
test(function() {});
},
Error,
"Test function can't be anonymous"
);
});
runIfMain(import.meta);

View file

@ -1,18 +0,0 @@
import { bench, runIfMain } from "./bench.ts";
import { runTests } from "./mod.ts";
import "./asserts_test.ts";
bench(async function testingSerial(b): Promise<void> {
b.start();
await runTests();
b.stop();
});
bench(async function testingParallel(b): Promise<void> {
b.start();
await runTests({ parallel: true });
b.stop();
});
runIfMain(import.meta);

View file

@ -12,7 +12,7 @@ import {
assertNotEquals,
assertThrows
} from "../testing/asserts.ts";
import { test, runIfMain } from "../testing/mod.ts";
const { test } = Deno;
function assertNotEOF<T extends {}>(val: T | Deno.EOF): T {
assertNotEquals(val, Deno.EOF);
@ -180,5 +180,3 @@ test({
assertEquals(m.get("Content-Disposition"), 'form-data; name="test"');
}
});
runIfMain(import.meta);

View file

@ -5,7 +5,7 @@
import { append } from "./mod.ts";
import { assertEquals } from "../testing/asserts.ts";
import { test } from "../testing/mod.ts";
const { test } = Deno;
test(async function textprotoAppend(): Promise<void> {
const enc = new TextEncoder();

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test, runIfMain } from "../testing/mod.ts";
const { test } = Deno;
import { assert, assertEquals, assertStrictEq } from "../testing/asserts.ts";
import { collectUint8Arrays, deferred, MuxAsyncIterator } from "./async.ts";
@ -69,5 +69,3 @@ test(async function collectUint8Arrays4(): Promise<void> {
assertStrictEq(result[i], i + 1);
}
});
runIfMain(import.meta);

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals, assert } from "../testing/asserts.ts";
import { deepAssign } from "./deep_assign.ts";

View file

@ -1,6 +1,5 @@
#!/usr/bin/env -S deno run
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { runIfMain } from "../testing/mod.ts";
// Generic Tests
import "./tests/isNil.ts";
@ -8,5 +7,3 @@ import "./tests/isNil.ts";
// V4 Tests
import "./tests/v4/validate.ts";
import "./tests/v4/generate.ts";
runIfMain(import.meta);

View file

@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert } from "../../testing/asserts.ts";
import { test } from "../../testing/mod.ts";
const { test } = Deno;
// @ts-ignore
import { NIL_UUID, isNil } from "../mod.ts";

View file

@ -1,6 +1,6 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert, assertEquals } from "../../../testing/asserts.ts";
import { test } from "../../../testing/mod.ts";
const { test } = Deno;
import { generate, validate } from "../../v4.ts";
test({

View file

@ -1,9 +1,8 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { assert } from "../../../testing/asserts.ts";
import { test } from "../../../testing/mod.ts";
import { generate, validate } from "../../v4.ts";
test({
Deno.test({
name: "[UUID] is_valid_uuid_v4",
fn(): void {
const u = generate();

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { test } from "../testing/mod.ts";
const { test } = Deno;
import { assertEquals } from "../testing/asserts.ts";
import { Sha1 } from "./sha1.ts";

View file

@ -1,7 +1,7 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { BufReader, BufWriter } from "../io/bufio.ts";
import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
import { runIfMain, test } from "../testing/mod.ts";
const { test } = Deno;
import { TextProtoReader } from "../textproto/mod.ts";
import * as bytes from "../bytes/mod.ts";
import {
@ -326,5 +326,3 @@ test("WebSocket.send(), WebSocket.ping() should be exclusive", async (): Promise
assertEquals(third.opcode, OpCode.BinaryFrame);
assertEquals(bytes.equal(third.payload, new Uint8Array([3])), true);
});
runIfMain(import.meta);