1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-22 15:06:54 -05:00

refactor(std): Uncomment disabled tests, use skip option (#4378)

This commit is contained in:
Nayeem Rahman 2020-03-15 12:03:25 +00:00 committed by GitHub
parent 2f4be6e944
commit 6471d4cfab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 332 additions and 265 deletions

View file

@ -29,21 +29,22 @@ const testCases = [
Input: "a,b\rc,d\r\n", Input: "a,b\rc,d\r\n",
Output: [["a", "b\rc", "d"]] Output: [["a", "b\rc", "d"]]
}, },
// { {
// Name: "RFC4180test", Name: "RFC4180test",
// Input: `#field1,field2,field3 Input: `#field1,field2,field3
// "aaa","bbb","ccc" "aaa","bbb","ccc"
// "a,a","bbb","ccc" "a,a","bbb","ccc"
// zzz,yyy,xxx`, zzz,yyy,xxx`,
// UseFieldsPerRecord: true, UseFieldsPerRecord: true,
// FieldsPerRecord: 0, FieldsPerRecord: 0,
// Output: [ Output: [
// ["#field1", "field2", "field3"], ["#field1", "field2", "field3"],
// ["aaa", "bbb", "ccc"], ["aaa", "bbb", "ccc"],
// ["a,a", `bbb`, "ccc"], ["a,a", `bbb`, "ccc"],
// ["zzz", "yyy", "xxx"] ["zzz", "yyy", "xxx"]
// ] ],
// }, skip: true
},
{ {
Name: "NoEOLTest", Name: "NoEOLTest",
Input: "a,b,c", Input: "a,b,c",
@ -55,14 +56,15 @@ const testCases = [
Output: [["a", "b", "c"]], Output: [["a", "b", "c"]],
Comma: ";" Comma: ";"
}, },
// { {
// Name: "MultiLine", Name: "MultiLine",
// Input: `"two Input: `"two
// line","one line","three line","one line","three
// line line
// field"`, field"`,
// Output: [["two\nline"], ["one line"], ["three\nline\nfield"]] Output: [["two\nline"], ["one line"], ["three\nline\nfield"]],
// }, skip: true
},
{ {
Name: "BlankLine", Name: "BlankLine",
Input: "a,b,c\n\nd,e,f\n\n", Input: "a,b,c\n\nd,e,f\n\n",
@ -256,54 +258,62 @@ x,,,
], ],
ReuseRecord: true ReuseRecord: true
}, },
// { {
// Name: "StartLine1", // Issue 19019 Name: "StartLine1", // Issue 19019
// Input: 'a,"b\nc"d,e', Input: 'a,"b\nc"d,e',
// Error: true Error: true,
// // Error: &ParseError{StartLine: 1, Line: 2, Column: 1, Err: ErrQuote}, // Error: &ParseError{StartLine: 1, Line: 2, Column: 1, Err: ErrQuote},
// }, skip: true
// { },
// Name: "StartLine2", {
// Input: 'a,b\n"d\n\n,e', Name: "StartLine2",
// Error: true Input: 'a,b\n"d\n\n,e',
// // Error: &ParseError{StartLine: 2, Line: 5, Column: 0, Err: ErrQuote}, Error: true,
// }, // Error: &ParseError{StartLine: 2, Line: 5, Column: 0, Err: ErrQuote},
// { skip: true
// Name: "CRLFInQuotedField", // Issue 21201 },
// Input: 'A,"Hello\r\nHi",B\r\n', {
// Output: [["A", "Hello\nHi", "B"]] Name: "CRLFInQuotedField", // Issue 21201
// }, Input: 'A,"Hello\r\nHi",B\r\n',
Output: [["A", "Hello\nHi", "B"]],
skip: true
},
{ {
Name: "BinaryBlobField", // Issue 19410 Name: "BinaryBlobField", // Issue 19410
Input: "x09\x41\xb4\x1c,aktau", Input: "x09\x41\xb4\x1c,aktau",
Output: [["x09A\xb4\x1c", "aktau"]] Output: [["x09A\xb4\x1c", "aktau"]]
}, },
// { {
// Name: "TrailingCR", Name: "TrailingCR",
// Input: "field1,field2\r", Input: "field1,field2\r",
// Output: [["field1", "field2"]] Output: [["field1", "field2"]],
// }, skip: true
// { },
// Name: "QuotedTrailingCR", {
// Input: '"field"\r', Name: "QuotedTrailingCR",
// Output: [['"field"']] Input: '"field"\r',
// }, Output: [['"field"']],
// { skip: true
// Name: "QuotedTrailingCRCR", },
// Input: '"field"\r\r', {
// Error: true, Name: "QuotedTrailingCRCR",
// // Error: &ParseError{StartLine: 1, Line: 1, Column: 6, Err: ErrQuote}, Input: '"field"\r\r',
// }, Error: true,
// { // Error: &ParseError{StartLine: 1, Line: 1, Column: 6, Err: ErrQuote},
// Name: "FieldCR", skip: true
// Input: "field\rfield\r", },
// Output: [["field\rfield"]] {
// }, Name: "FieldCR",
// { Input: "field\rfield\r",
// Name: "FieldCRCR", Output: [["field\rfield"]],
// Input: "field\r\rfield\r\r", skip: true
// Output: [["field\r\rfield\r"]] },
// }, {
Name: "FieldCRCR",
Input: "field\r\rfield\r\r",
Output: [["field\r\rfield\r"]],
skip: true
},
{ {
Name: "FieldCRCRLF", Name: "FieldCRCRLF",
Input: "field\r\r\nfield\r\r\n", Input: "field\r\r\nfield\r\r\n",
@ -314,20 +324,22 @@ x,,,
Input: "field\r\r\n\rfield\r\r\n\r", Input: "field\r\r\n\rfield\r\r\n\r",
Output: [["field\r"], ["\rfield\r"]] Output: [["field\r"], ["\rfield\r"]]
}, },
// { {
// Name: "FieldCRCRLFCRCR", Name: "FieldCRCRLFCRCR",
// Input: "field\r\r\n\r\rfield\r\r\n\r\r", Input: "field\r\r\n\r\rfield\r\r\n\r\r",
// Output: [["field\r"], ["\r\rfield\r"], ["\r"]] Output: [["field\r"], ["\r\rfield\r"], ["\r"]],
// }, skip: true
// { },
// Name: "MultiFieldCRCRLFCRCR", {
// Input: "field1,field2\r\r\n\r\rfield1,field2\r\r\n\r\r,", Name: "MultiFieldCRCRLFCRCR",
// Output: [ Input: "field1,field2\r\r\n\r\rfield1,field2\r\r\n\r\r,",
// ["field1", "field2\r"], Output: [
// ["\r\rfield1", "field2\r"], ["field1", "field2\r"],
// ["\r\r", ""] ["\r\rfield1", "field2\r"],
// ] ["\r\r", ""]
// }, ],
skip: true
},
{ {
Name: "NonASCIICommaAndComment", Name: "NonASCIICommaAndComment",
Input: "a£b,c£ \td,e\n€ comment\n", Input: "a£b,c£ \td,e\n€ comment\n",
@ -358,30 +370,30 @@ x,,,
Output: [["λ"], ["λ"], ["λ"]], Output: [["λ"], ["λ"], ["λ"]],
Comment: "θ" Comment: "θ"
}, },
// { {
// Name: "QuotedFieldMultipleLF", Name: "QuotedFieldMultipleLF",
// Input: '"\n\n\n\n"', Input: '"\n\n\n\n"',
// Output: [["\n\n\n\n"]] Output: [["\n\n\n\n"]],
// }, skip: true
// { },
// Name: "MultipleCRLF", {
// Input: "\r\n\r\n\r\n\r\n" Name: "MultipleCRLF",
// }, Input: "\r\n\r\n\r\n\r\n",
skip: true
},
/** /**
* The implementation may read each line in several chunks if * The implementation may read each line in several chunks if
* it doesn't fit entirely. * it doesn't fit entirely.
* in the read buffer, so we should test the code to handle that condition. * in the read buffer, so we should test the code to handle that condition.
*/ */
// { {
// Name: "HugeLines", Name: "HugeLines",
// Input: Input:
// strings.Repeat("#ignore\n", 10000) + "#ignore\n".repeat(10000) + "@".repeat(5000) + "," + "*".repeat(5000),
// strings.Repeat("@", 5000) + Output: [["@".repeat(5000), "*".repeat(5000)]],
// "," + Comment: "#",
// strings.Repeat("*", 5000), skip: true
// Output: [[strings.Repeat("@", 5000), strings.Repeat("*", 5000)]], },
// Comment: "#"
// },
{ {
Name: "QuoteWithTrailingCRLF", Name: "QuoteWithTrailingCRLF",
Input: '"foo"bar"\r\n', Input: '"foo"bar"\r\n',
@ -394,28 +406,32 @@ x,,,
Output: [[`foo"bar`]], Output: [[`foo"bar`]],
LazyQuotes: true LazyQuotes: true
}, },
// { {
// Name: "DoubleQuoteWithTrailingCRLF", Name: "DoubleQuoteWithTrailingCRLF",
// Input: '"foo""bar"\r\n', Input: '"foo""bar"\r\n',
// Output: [[`foo"bar`]] Output: [[`foo"bar`]],
// }, skip: true
// { },
// Name: "EvenQuotes", {
// Input: `""""""""`, Name: "EvenQuotes",
// Output: [[`"""`]] Input: `""""""""`,
// }, Output: [[`"""`]],
// { skip: true
// Name: "OddQuotes", },
// Input: `"""""""`, {
// Error: true Name: "OddQuotes",
// // Error:" &ParseError{StartLine: 1, Line: 1, Column: 7, Err: ErrQuote}", Input: `"""""""`,
// }, Error: true,
// { // Error:" &ParseError{StartLine: 1, Line: 1, Column: 7, Err: ErrQuote}",
// Name: "LazyOddQuotes", skip: true
// Input: `"""""""`, },
// Output: [[`"""`]], {
// LazyQuotes: true Name: "LazyOddQuotes",
// }, Input: `"""""""`,
Output: [[`"""`]],
LazyQuotes: true,
skip: true
},
{ {
Name: "BadComma1", Name: "BadComma1",
Comma: "\n", Comma: "\n",
@ -450,6 +466,7 @@ x,,,
]; ];
for (const t of testCases) { for (const t of testCases) {
Deno.test({ Deno.test({
skip: !!t.skip,
name: `[CSV] ${t.Name}`, name: `[CSV] ${t.Name}`,
async fn(): Promise<void> { async fn(): Promise<void> {
let comma = ","; let comma = ",";

View file

@ -81,6 +81,7 @@ function print(data: any): void {
} }
} }
if (import.meta.main) {
const parsedArgs = parse(Deno.args); const parsedArgs = parse(Deno.args);
if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) { if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) {
@ -101,8 +102,9 @@ if (parsedArgs._[0] === "-") {
print(json); print(json);
} else { } else {
for (const fileName of parsedArgs._) { for (const fileName of parsedArgs._) {
const fileContents = await Deno.readFile(fileName); const fileContents = await Deno.readFile(fileName.toString());
const json = JSON.parse(decoder.decode(fileContents)); const json = JSON.parse(decoder.decode(fileContents));
print(json); print(json);
} }
} }
}

View file

@ -24,29 +24,47 @@ async function startServer(): Promise<void> {
const { test, build } = Deno; const { test, build } = Deno;
// TODO: https://github.com/denoland/deno/issues/4108 // TODO: https://github.com/denoland/deno/issues/4108
if (build.os !== "win") { const skip = build.os == "win";
test("beforeAll", async () => {
test({
skip,
name: "beforeAll",
async fn() {
await startServer(); await startServer();
}
}); });
test("GET / should serve html", async () => { test({
skip,
name: "GET / should serve html",
async fn() {
const resp = await fetch("http://127.0.0.1:8080/"); const resp = await fetch("http://127.0.0.1:8080/");
assertEquals(resp.status, 200); assertEquals(resp.status, 200);
assertEquals(resp.headers.get("content-type"), "text/html"); assertEquals(resp.headers.get("content-type"), "text/html");
const html = await resp.body.text(); const html = await resp.body.text();
assert(html.includes("ws chat example"), "body is ok"); assert(html.includes("ws chat example"), "body is ok");
}
}); });
let ws: WebSocket | undefined; let ws: WebSocket | undefined;
test("GET /ws should upgrade conn to ws", async () => {
test({
skip,
name: "GET /ws should upgrade conn to ws",
async fn() {
ws = await connectWebSocket("http://127.0.0.1:8080/ws"); ws = await connectWebSocket("http://127.0.0.1:8080/ws");
const it = ws.receive(); const it = ws.receive();
assertEquals((await it.next()).value, "Connected: [1]"); assertEquals((await it.next()).value, "Connected: [1]");
ws.send("Hello"); ws.send("Hello");
assertEquals((await it.next()).value, "[1]: Hello"); assertEquals((await it.next()).value, "[1]: Hello");
}
}); });
test("afterAll", () => {
test({
skip,
name: "afterAll",
fn() {
server?.close(); server?.close();
ws?.conn.close(); ws?.conn.close();
});
} }
});

View file

@ -23,7 +23,6 @@ Deno.test(async function xevalDelimiter(): Promise<void> {
assertEquals(chunks, ["!MAD", "ADAM!"]); assertEquals(chunks, ["!MAD", "ADAM!"]);
}); });
// https://github.com/denoland/deno/issues/2861
const xevalPath = "examples/xeval.ts"; const xevalPath = "examples/xeval.ts";
Deno.test(async function xevalCliReplvar(): Promise<void> { Deno.test(async function xevalCliReplvar(): Promise<void> {

View file

@ -1,11 +1,14 @@
const { cwd, chdir, makeTempDir, mkdir, open } = Deno; const { cwd, chdir, makeTempDir, mkdir, open, symlink } = Deno;
const { remove } = Deno; const { remove } = Deno;
import { walk, walkSync, WalkOptions, WalkInfo } from "./walk.ts"; import { walk, walkSync, WalkOptions, WalkInfo } from "./walk.ts";
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts"; import { assert, assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
const isWindows = Deno.build.os == "win";
export async function testWalk( export async function testWalk(
setup: (arg0: string) => void | Promise<void>, setup: (arg0: string) => void | Promise<void>,
t: Deno.TestFunction t: Deno.TestFunction,
skip = false
): Promise<void> { ): Promise<void> {
const name = t.name; const name = t.name;
async function fn(): Promise<void> { async function fn(): Promise<void> {
@ -20,7 +23,7 @@ export async function testWalk(
remove(d, { recursive: true }); remove(d, { recursive: true });
} }
} }
Deno.test({ name, fn }); Deno.test({ skip, name: `[walk] ${name}`, fn });
} }
function normalize({ filename }: WalkInfo): string { function normalize({ filename }: WalkInfo): string {
@ -239,7 +242,7 @@ testWalk(
} }
); );
/* TODO(ry) Re-enable followSymlinks // TODO(ry) Re-enable followSymlinks
testWalk( testWalk(
async (d: string): Promise<void> => { async (d: string): Promise<void> => {
await mkdir(d + "/a"); await mkdir(d + "/a");
@ -268,6 +271,6 @@ testWalk(
const arr = await walkArray("a", { followSymlinks: true }); const arr = await walkArray("a", { followSymlinks: true });
assertEquals(arr.length, 3); assertEquals(arr.length, 3);
assert(arr.some((f): boolean => f.endsWith("/b/z"))); assert(arr.some((f): boolean => f.endsWith("/b/z")));
} },
true
); );
*/

View file

@ -445,8 +445,10 @@ test("close server while iterating", async (): Promise<void> => {
// receive a RST and thus trigger an error during response for us to test. // receive a RST and thus trigger an error during response for us to test.
// We need to find a way to similarly trigger an error on Windows so that // We need to find a way to similarly trigger an error on Windows so that
// we can test if connection is closed. // we can test if connection is closed.
if (Deno.build.os !== "win") { test({
test("respond error handling", async (): Promise<void> => { skip: Deno.build.os == "win",
name: "respond error handling",
async fn(): Promise<void> {
const connClosedPromise = deferred(); const connClosedPromise = deferred();
const serverRoutine = async (): Promise<void> => { const serverRoutine = async (): Promise<void> => {
let reqCount = 0; let reqCount = 0;
@ -498,5 +500,5 @@ if (Deno.build.os !== "win") {
// conn on server side enters CLOSE_WAIT state. // conn on server side enters CLOSE_WAIT state.
connClosedPromise.resolve(); connClosedPromise.resolve();
await p; await p;
});
} }
});

View file

@ -3,8 +3,41 @@ const { test } = Deno;
import { fail, assert } from "../../testing/asserts.ts"; import { fail, assert } from "../../testing/asserts.ts";
import { chmod, chmodSync } from "./_fs_chmod.ts"; import { chmod, chmodSync } from "./_fs_chmod.ts";
if (Deno.build.os !== "win") {
test({ test({
name: "ASYNC: Error passed in callback function when bad mode passed in",
async fn() {
await new Promise((resolve, reject) => {
chmod("some_pretend_file.txt", "999", err => {
if (err) reject(err);
else resolve();
});
})
.then(() => {
fail("Expected exception to be thrown");
})
.catch(err => {
assert(err);
});
}
});
test({
name: "SYNC: Error thrown when bad mode passed in",
fn() {
let caughtError: Error | undefined;
try {
chmodSync("some_pretend_file.txt", "999");
} catch (err) {
caughtError = err;
}
assert(caughtError);
}
});
const skip = Deno.build.os == "win";
test({
skip,
name: "ASYNC: Permissions are changed (non-Windows)", name: "ASYNC: Permissions are changed (non-Windows)",
async fn() { async fn() {
const tempFile: string = await Deno.makeTempFile(); const tempFile: string = await Deno.makeTempFile();
@ -30,6 +63,7 @@ if (Deno.build.os !== "win") {
}); });
test({ test({
skip,
name: "SYNC: Permissions are changed (non-Windows)", name: "SYNC: Permissions are changed (non-Windows)",
fn() { fn() {
const tempFile: string = Deno.makeTempFileSync(); const tempFile: string = Deno.makeTempFileSync();
@ -42,34 +76,3 @@ if (Deno.build.os !== "win") {
Deno.removeSync(tempFile); Deno.removeSync(tempFile);
} }
}); });
}
test({
name: "ASYNC: Error passed in callback function when bad mode passed in",
async fn() {
await new Promise((resolve, reject) => {
chmod("some_pretend_file.txt", "999", err => {
if (err) reject(err);
else resolve();
});
})
.then(() => {
fail("Expected exception to be thrown");
})
.catch(err => {
assert(err);
});
}
});
test({
name: "SYNC: Error thrown when bad mode passed in",
fn() {
let caughtError: Error | undefined;
try {
chmodSync("some_pretend_file.txt", "999");
} catch (err) {
caughtError = err;
}
assert(caughtError);
}
});

View file

@ -3,9 +3,11 @@ const { test } = Deno;
import { fail, assertEquals } from "../../testing/asserts.ts"; import { fail, assertEquals } from "../../testing/asserts.ts";
import { chown, chownSync } from "./_fs_chown.ts"; import { chown, chownSync } from "./_fs_chown.ts";
if (Deno.build.os !== "win") {
//chown is difficult to test. Best we can do is set the existing user id/group id again //chown is difficult to test. Best we can do is set the existing user id/group id again
const skip = Deno.build.os == "win";
test({ test({
skip,
name: "ASYNC: setting existing uid/gid works as expected (non-Windows)", name: "ASYNC: setting existing uid/gid works as expected (non-Windows)",
async fn() { async fn() {
const tempFile: string = await Deno.makeTempFile(); const tempFile: string = await Deno.makeTempFile();
@ -33,6 +35,7 @@ if (Deno.build.os !== "win") {
}); });
test({ test({
skip,
name: "SYNC: setting existing uid/gid works as expected (non-Windows)", name: "SYNC: setting existing uid/gid works as expected (non-Windows)",
fn() { fn() {
const tempFile: string = Deno.makeTempFileSync(); const tempFile: string = Deno.makeTempFileSync();
@ -47,4 +50,3 @@ if (Deno.build.os !== "win") {
Deno.removeSync(tempFile); Deno.removeSync(tempFile);
} }
}); });
}

View file

@ -50,9 +50,16 @@ test(function readFileEncodeUtf8Success() {
}); });
// Just for now, until we implement symlink for Windows. // Just for now, until we implement symlink for Windows.
if (Deno.build.os !== "win") { const skip = Deno.build.os == "win";
if (!skip) {
Deno.symlinkSync(oldname, newname); Deno.symlinkSync(oldname, newname);
test(async function readlinkSuccess() { }
test({
skip,
name: "readlinkSuccess",
async fn() {
const data = await new Promise((res, rej) => { const data = await new Promise((res, rej) => {
readlink(newname, (err, data) => { readlink(newname, (err, data) => {
if (err) { if (err) {
@ -64,9 +71,13 @@ if (Deno.build.os !== "win") {
assertEquals(typeof data, "string"); assertEquals(typeof data, "string");
assertEquals(data as string, oldname); assertEquals(data as string, oldname);
}
}); });
test(async function readlinkEncodeBufferSuccess() { test({
skip,
name: "readlinkEncodeBufferSuccess",
async fn() {
const data = await new Promise((res, rej) => { const data = await new Promise((res, rej) => {
readlink(newname, { encoding: "buffer" }, (err, data) => { readlink(newname, { encoding: "buffer" }, (err, data) => {
if (err) { if (err) {
@ -78,17 +89,25 @@ if (Deno.build.os !== "win") {
assert(data instanceof Uint8Array); assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), oldname); assertEquals(new TextDecoder().decode(data as Uint8Array), oldname);
}
}); });
test(function readlinkSyncSuccess() { test({
skip,
name: "readlinkSyncSuccess",
fn() {
const data = readlinkSync(newname); const data = readlinkSync(newname);
assertEquals(typeof data, "string"); assertEquals(typeof data, "string");
assertEquals(data as string, oldname); assertEquals(data as string, oldname);
}
}); });
test(function readlinkEncodeBufferSuccess() { test({
skip,
name: "readlinkEncodeBufferSuccess",
fn() {
const data = readlinkSync(newname, { encoding: "buffer" }); const data = readlinkSync(newname, { encoding: "buffer" });
assert(data instanceof Uint8Array); assert(data instanceof Uint8Array);
assertEquals(new TextDecoder().decode(data as Uint8Array), oldname); assertEquals(new TextDecoder().decode(data as Uint8Array), oldname);
});
} }
});

View file

@ -17,13 +17,15 @@ const { test } = Deno;
function reader(s: string): TextProtoReader { function reader(s: string): TextProtoReader {
return new TextProtoReader(new BufReader(stringsReader(s))); return new TextProtoReader(new BufReader(stringsReader(s)));
} }
// test({
// name: "[textproto] Reader : DotBytes", test({
// async fn(): Promise<void> { skip: true,
// const input = name: "[textproto] Reader : DotBytes",
// "dotlines\r\n.foo\r\n..bar\n...baz\nquux\r\n\r\n.\r\nanot.her\r\n"; async fn(): Promise<void> {
// } const _input =
// }); "dotlines\r\n.foo\r\n..bar\n...baz\nquux\r\n\r\n.\r\nanot.her\r\n";
}
});
test(async function textprotoReadEmpty(): Promise<void> { test(async function textprotoReadEmpty(): Promise<void> {
const r = reader(""); const r = reader("");