summaryrefslogtreecommitdiff
path: root/std/examples/tests
diff options
context:
space:
mode:
authortokiedokie <thetokiedokie@gmail.com>2020-09-27 00:54:26 +0900
committerGitHub <noreply@github.com>2020-09-26 11:54:26 -0400
commit04836dc700a8e22fdb604f0640cb72be5e0194c9 (patch)
treef5828053fcef820de6f39d6160f047d82ef96802 /std/examples/tests
parentff785bc35aa650152643ffc65a2195e2b27f845b (diff)
refactor(std/example): Inconsistencies in the example tests (#7684)
Diffstat (limited to 'std/examples/tests')
-rw-r--r--std/examples/tests/cat_test.ts29
-rw-r--r--std/examples/tests/catj_test.ts91
-rw-r--r--std/examples/tests/colors_test.ts22
-rw-r--r--std/examples/tests/curl_test.ts43
-rw-r--r--std/examples/tests/echo_server_test.ts47
-rw-r--r--std/examples/tests/test_test.ts2
-rw-r--r--std/examples/tests/welcome_test.ts22
-rw-r--r--std/examples/tests/xeval_test.ts71
8 files changed, 0 insertions, 327 deletions
diff --git a/std/examples/tests/cat_test.ts b/std/examples/tests/cat_test.ts
deleted file mode 100644
index 3b6f0d40f..000000000
--- a/std/examples/tests/cat_test.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assertStrictEquals } from "../../testing/asserts.ts";
-import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
-
-const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
-
-Deno.test("[examples/cat] print multiple files", async () => {
- const decoder = new TextDecoder();
- const process = Deno.run({
- cmd: [
- Deno.execPath(),
- "run",
- "--allow-read",
- "cat.ts",
- "testdata/cat/hello.txt",
- "testdata/cat/world.txt",
- ],
- cwd: moduleDir,
- stdout: "piped",
- });
-
- try {
- const output = await process.output();
- const actual = decoder.decode(output).trim();
- assertStrictEquals(actual, "Hello\nWorld");
- } finally {
- process.close();
- }
-});
diff --git a/std/examples/tests/catj_test.ts b/std/examples/tests/catj_test.ts
deleted file mode 100644
index c79403421..000000000
--- a/std/examples/tests/catj_test.ts
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assertStrictEquals } from "../../testing/asserts.ts";
-import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
-
-const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
-
-Deno.test("[examples/catj] print an array", async () => {
- const decoder = new TextDecoder();
- const process = catj("testdata/catj/array.json");
- try {
- const output = await process.output();
- const actual = decoder.decode(output).trim();
- const expected = [
- '.[0] = "string"',
- ".[1] = 100",
- '.[2].key = "value"',
- '.[2].array[0] = "foo"',
- '.[2].array[1] = "bar"',
- ].join("\n");
-
- assertStrictEquals(actual, expected);
- } finally {
- process.stdin.close();
- process.close();
- }
-});
-
-Deno.test("[examples/catj] print an object", async () => {
- const decoder = new TextDecoder();
- const process = catj("testdata/catj/object.json");
- try {
- const output = await process.output();
- const actual = decoder.decode(output).trim();
- const expected = [
- '.string = "foobar"',
- ".number = 123",
- '.array[0].message = "hello"',
- ].join("\n");
-
- assertStrictEquals(actual, expected);
- } finally {
- process.stdin.close();
- process.close();
- }
-});
-
-Deno.test("[examples/catj] print multiple files", async () => {
- const decoder = new TextDecoder();
- const process = catj(
- "testdata/catj/simple-object.json",
- "testdata/catj/simple-array.json",
- );
- try {
- const output = await process.output();
- const actual = decoder.decode(output).trim();
- const expected = ['.message = "hello"', ".[0] = 1", ".[1] = 2"].join("\n");
-
- assertStrictEquals(actual, expected);
- } finally {
- process.stdin.close();
- process.close();
- }
-});
-
-Deno.test("[examples/catj] read from stdin", async () => {
- const decoder = new TextDecoder();
- const process = catj("-");
- const input = `{ "foo": "bar" }`;
- try {
- await process.stdin.write(new TextEncoder().encode(input));
- process.stdin.close();
- const output = await process.output();
- const actual = decoder.decode(output).trim();
-
- assertStrictEquals(actual, '.foo = "bar"');
- } finally {
- process.close();
- }
-});
-
-function catj(
- ...files: string[]
-): Deno.Process<Deno.RunOptions & { stdin: "piped"; stdout: "piped" }> {
- return Deno.run({
- cmd: [Deno.execPath(), "run", "--allow-read", "catj.ts", ...files],
- cwd: moduleDir,
- stdin: "piped",
- stdout: "piped",
- env: { NO_COLOR: "true" },
- });
-}
diff --git a/std/examples/tests/colors_test.ts b/std/examples/tests/colors_test.ts
deleted file mode 100644
index 91d016232..000000000
--- a/std/examples/tests/colors_test.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assertStrictEquals } from "../../testing/asserts.ts";
-import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
-
-const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
-
-Deno.test("[examples/colors] print a colored text", async () => {
- const decoder = new TextDecoder();
- const process = Deno.run({
- cmd: [Deno.execPath(), "run", "colors.ts"],
- cwd: moduleDir,
- stdout: "piped",
- });
- try {
- const output = await process.output();
- const actual = decoder.decode(output).trim();
- const expected = "Hello world!";
- assertStrictEquals(actual, expected);
- } finally {
- process.close();
- }
-});
diff --git a/std/examples/tests/curl_test.ts b/std/examples/tests/curl_test.ts
deleted file mode 100644
index f35edab4c..000000000
--- a/std/examples/tests/curl_test.ts
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { serve } from "../../http/server.ts";
-import { assertStrictEquals } from "../../testing/asserts.ts";
-import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
-
-const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
-
-Deno.test({
- name: "[examples/curl] send a request to a specified url",
- fn: async () => {
- const server = serve({ port: 8081 });
- const serverPromise = (async (): Promise<void> => {
- for await (const req of server) {
- req.respond({ body: "Hello world" });
- }
- })();
-
- const decoder = new TextDecoder();
- const process = Deno.run({
- cmd: [
- Deno.execPath(),
- "run",
- "--allow-net",
- "curl.ts",
- "http://localhost:8081",
- ],
- cwd: moduleDir,
- stdout: "piped",
- });
-
- try {
- const output = await process.output();
- const actual = decoder.decode(output).trim();
- const expected = "Hello world";
-
- assertStrictEquals(actual, expected);
- } finally {
- server.close();
- process.close();
- await serverPromise;
- }
- },
-});
diff --git a/std/examples/tests/echo_server_test.ts b/std/examples/tests/echo_server_test.ts
deleted file mode 100644
index 6bfcbbc3d..000000000
--- a/std/examples/tests/echo_server_test.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assertStrictEquals, assertNotEquals } from "../../testing/asserts.ts";
-import { BufReader, ReadLineResult } from "../../io/bufio.ts";
-import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
-
-const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
-
-Deno.test("[examples/echo_server]", async () => {
- const encoder = new TextEncoder();
- const decoder = new TextDecoder();
- const process = Deno.run({
- cmd: [Deno.execPath(), "run", "--allow-net", "echo_server.ts"],
- cwd: moduleDir,
- stdout: "piped",
- });
-
- let conn: Deno.Conn | undefined;
- try {
- const processReader = new BufReader(process.stdout);
- const message = await processReader.readLine();
-
- assertNotEquals(message, null);
- assertStrictEquals(
- decoder.decode((message as ReadLineResult).line).trim(),
- "Listening on 0.0.0.0:8080",
- );
-
- conn = await Deno.connect({ hostname: "127.0.0.1", port: 8080 });
- const connReader = new BufReader(conn);
-
- await conn.write(encoder.encode("Hello echo_server\n"));
- const result = await connReader.readLine();
-
- assertNotEquals(result, null);
-
- const actualResponse = decoder
- .decode((result as ReadLineResult).line)
- .trim();
- const expectedResponse = "Hello echo_server";
-
- assertStrictEquals(actualResponse, expectedResponse);
- } finally {
- conn?.close();
- process.stdout.close();
- process.close();
- }
-});
diff --git a/std/examples/tests/test_test.ts b/std/examples/tests/test_test.ts
deleted file mode 100644
index 7c9527060..000000000
--- a/std/examples/tests/test_test.ts
+++ /dev/null
@@ -1,2 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import "../test.ts";
diff --git a/std/examples/tests/welcome_test.ts b/std/examples/tests/welcome_test.ts
deleted file mode 100644
index 5f8d81988..000000000
--- a/std/examples/tests/welcome_test.ts
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { assertStrictEquals } from "../../testing/asserts.ts";
-import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
-
-const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
-
-Deno.test("[examples/welcome] print a welcome message", async () => {
- const decoder = new TextDecoder();
- const process = Deno.run({
- cmd: [Deno.execPath(), "run", "welcome.ts"],
- cwd: moduleDir,
- stdout: "piped",
- });
- try {
- const output = await process.output();
- const actual = decoder.decode(output).trim();
- const expected = "Welcome to Deno 🦕";
- assertStrictEquals(actual, expected);
- } finally {
- process.close();
- }
-});
diff --git a/std/examples/tests/xeval_test.ts b/std/examples/tests/xeval_test.ts
deleted file mode 100644
index d3493d397..000000000
--- a/std/examples/tests/xeval_test.ts
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import { xeval } from "../xeval.ts";
-import { StringReader } from "../../io/readers.ts";
-import { decode, encode } from "../../encoding/utf8.ts";
-import {
- assertEquals,
- assertStringContains,
- assert,
-} from "../../testing/asserts.ts";
-import { resolve, dirname, fromFileUrl } from "../../path/mod.ts";
-
-const moduleDir = resolve(dirname(fromFileUrl(import.meta.url)), "..");
-
-Deno.test("xevalSuccess", async function (): Promise<void> {
- const chunks: string[] = [];
- await xeval(new StringReader("a\nb\nc"), ($): number => chunks.push($));
- assertEquals(chunks, ["a", "b", "c"]);
-});
-
-Deno.test("xevalDelimiter", async function (): Promise<void> {
- const chunks: string[] = [];
- await xeval(
- new StringReader("!MADMADAMADAM!"),
- ($): number => chunks.push($),
- {
- delimiter: "MADAM",
- },
- );
- assertEquals(chunks, ["!MAD", "ADAM!"]);
-});
-
-const xevalPath = "xeval.ts";
-
-Deno.test({
- name: "xevalCliReplvar",
- fn: async function (): Promise<void> {
- const p = Deno.run({
- cmd: [
- Deno.execPath(),
- "run",
- xevalPath,
- "--replvar=abc",
- "console.log(abc)",
- ],
- cwd: moduleDir,
- stdin: "piped",
- stdout: "piped",
- stderr: "null",
- });
- assert(p.stdin != null);
- await p.stdin.write(encode("hello"));
- p.stdin.close();
- assertEquals(await p.status(), { code: 0, success: true });
- assertEquals(decode(await p.output()).trimEnd(), "hello");
- p.close();
- },
-});
-
-Deno.test("xevalCliSyntaxError", async function (): Promise<void> {
- const p = Deno.run({
- cmd: [Deno.execPath(), "run", xevalPath, "("],
- cwd: moduleDir,
- stdin: "null",
- stdout: "piped",
- stderr: "piped",
- });
- assertEquals(await p.status(), { code: 1, success: false });
- assertEquals(decode(await p.output()), "");
- assertStringContains(decode(await p.stderrOutput()), "Uncaught SyntaxError");
- p.close();
-});