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

View file

@ -81,28 +81,30 @@ function print(data: any): void {
}
}
const parsedArgs = parse(Deno.args);
if (import.meta.main) {
const parsedArgs = parse(Deno.args);
if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) {
console.log("Usage: catj [-h|--help] [file...]");
console.log();
console.log("Examples:");
console.log();
console.log("// print file:\n catj file.json");
console.log();
console.log("// print multiple files:\n catj file1.json file2.json");
console.log();
console.log("// print from stdin:\n cat file.json | catj -");
}
if (parsedArgs.h || parsedArgs.help || parsedArgs._.length === 0) {
console.log("Usage: catj [-h|--help] [file...]");
console.log();
console.log("Examples:");
console.log();
console.log("// print file:\n catj file.json");
console.log();
console.log("// print multiple files:\n catj file1.json file2.json");
console.log();
console.log("// print from stdin:\n cat file.json | catj -");
}
if (parsedArgs._[0] === "-") {
const contents = await Deno.readAll(Deno.stdin);
const json = JSON.parse(decoder.decode(contents));
print(json);
} else {
for (const fileName of parsedArgs._) {
const fileContents = await Deno.readFile(fileName);
const json = JSON.parse(decoder.decode(fileContents));
if (parsedArgs._[0] === "-") {
const contents = await Deno.readAll(Deno.stdin);
const json = JSON.parse(decoder.decode(contents));
print(json);
} else {
for (const fileName of parsedArgs._) {
const fileContents = await Deno.readFile(fileName.toString());
const json = JSON.parse(decoder.decode(fileContents));
print(json);
}
}
}

View file

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

View file

@ -23,7 +23,6 @@ Deno.test(async function xevalDelimiter(): Promise<void> {
assertEquals(chunks, ["!MAD", "ADAM!"]);
});
// https://github.com/denoland/deno/issues/2861
const xevalPath = "examples/xeval.ts";
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;
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(
setup: (arg0: string) => void | Promise<void>,
t: Deno.TestFunction
t: Deno.TestFunction,
skip = false
): Promise<void> {
const name = t.name;
async function fn(): Promise<void> {
@ -20,7 +23,7 @@ export async function testWalk(
remove(d, { recursive: true });
}
}
Deno.test({ name, fn });
Deno.test({ skip, name: `[walk] ${name}`, fn });
}
function normalize({ filename }: WalkInfo): string {
@ -239,7 +242,7 @@ testWalk(
}
);
/* TODO(ry) Re-enable followSymlinks
// TODO(ry) Re-enable followSymlinks
testWalk(
async (d: string): Promise<void> => {
await mkdir(d + "/a");
@ -268,6 +271,6 @@ testWalk(
const arr = await walkArray("a", { followSymlinks: true });
assertEquals(arr.length, 3);
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.
// We need to find a way to similarly trigger an error on Windows so that
// we can test if connection is closed.
if (Deno.build.os !== "win") {
test("respond error handling", async (): Promise<void> => {
test({
skip: Deno.build.os == "win",
name: "respond error handling",
async fn(): Promise<void> {
const connClosedPromise = deferred();
const serverRoutine = async (): Promise<void> => {
let reqCount = 0;
@ -498,5 +500,5 @@ if (Deno.build.os !== "win") {
// conn on server side enters CLOSE_WAIT state.
connClosedPromise.resolve();
await p;
});
}
}
});

View file

@ -3,47 +3,6 @@ const { test } = Deno;
import { fail, assert } from "../../testing/asserts.ts";
import { chmod, chmodSync } from "./_fs_chmod.ts";
if (Deno.build.os !== "win") {
test({
name: "ASYNC: Permissions are changed (non-Windows)",
async fn() {
const tempFile: string = await Deno.makeTempFile();
const originalFileMode: number | null = (await Deno.lstat(tempFile)).mode;
await new Promise((resolve, reject) => {
chmod(tempFile, 0o777, err => {
if (err) reject(err);
else resolve();
});
})
.then(() => {
const newFileMode: number | null = Deno.lstatSync(tempFile).mode;
assert(newFileMode && originalFileMode);
assert(newFileMode === 33279 && newFileMode > originalFileMode);
})
.catch(() => {
fail();
})
.finally(() => {
Deno.removeSync(tempFile);
});
}
});
test({
name: "SYNC: Permissions are changed (non-Windows)",
fn() {
const tempFile: string = Deno.makeTempFileSync();
const originalFileMode: number | null = Deno.lstatSync(tempFile).mode;
chmodSync(tempFile, "777");
const newFileMode: number | null = Deno.lstatSync(tempFile).mode;
assert(newFileMode && originalFileMode);
assert(newFileMode === 33279 && newFileMode > originalFileMode);
Deno.removeSync(tempFile);
}
});
}
test({
name: "ASYNC: Error passed in callback function when bad mode passed in",
async fn() {
@ -61,6 +20,7 @@ test({
});
}
});
test({
name: "SYNC: Error thrown when bad mode passed in",
fn() {
@ -73,3 +33,46 @@ test({
assert(caughtError);
}
});
const skip = Deno.build.os == "win";
test({
skip,
name: "ASYNC: Permissions are changed (non-Windows)",
async fn() {
const tempFile: string = await Deno.makeTempFile();
const originalFileMode: number | null = (await Deno.lstat(tempFile)).mode;
await new Promise((resolve, reject) => {
chmod(tempFile, 0o777, err => {
if (err) reject(err);
else resolve();
});
})
.then(() => {
const newFileMode: number | null = Deno.lstatSync(tempFile).mode;
assert(newFileMode && originalFileMode);
assert(newFileMode === 33279 && newFileMode > originalFileMode);
})
.catch(() => {
fail();
})
.finally(() => {
Deno.removeSync(tempFile);
});
}
});
test({
skip,
name: "SYNC: Permissions are changed (non-Windows)",
fn() {
const tempFile: string = Deno.makeTempFileSync();
const originalFileMode: number | null = Deno.lstatSync(tempFile).mode;
chmodSync(tempFile, "777");
const newFileMode: number | null = Deno.lstatSync(tempFile).mode;
assert(newFileMode && originalFileMode);
assert(newFileMode === 33279 && newFileMode > originalFileMode);
Deno.removeSync(tempFile);
}
});

View file

@ -3,48 +3,50 @@ const { test } = Deno;
import { fail, assertEquals } from "../../testing/asserts.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
test({
name: "ASYNC: setting existing uid/gid works as expected (non-Windows)",
async fn() {
const tempFile: string = await Deno.makeTempFile();
const originalUserId: number | null = (await Deno.lstat(tempFile)).uid;
const originalGroupId: number | null = (await Deno.lstat(tempFile)).gid;
await new Promise((resolve, reject) => {
chown(tempFile, originalUserId!, originalGroupId!, err => {
if (err) reject(err);
else resolve();
});
//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({
skip,
name: "ASYNC: setting existing uid/gid works as expected (non-Windows)",
async fn() {
const tempFile: string = await Deno.makeTempFile();
const originalUserId: number | null = (await Deno.lstat(tempFile)).uid;
const originalGroupId: number | null = (await Deno.lstat(tempFile)).gid;
await new Promise((resolve, reject) => {
chown(tempFile, originalUserId!, originalGroupId!, err => {
if (err) reject(err);
else resolve();
});
})
.then(() => {
const newUserId: number | null = Deno.lstatSync(tempFile).uid;
const newGroupId: number | null = Deno.lstatSync(tempFile).gid;
assertEquals(newUserId, originalUserId);
assertEquals(newGroupId, originalGroupId);
})
.then(() => {
const newUserId: number | null = Deno.lstatSync(tempFile).uid;
const newGroupId: number | null = Deno.lstatSync(tempFile).gid;
assertEquals(newUserId, originalUserId);
assertEquals(newGroupId, originalGroupId);
})
.catch(() => {
fail();
})
.finally(() => {
Deno.removeSync(tempFile);
});
}
});
.catch(() => {
fail();
})
.finally(() => {
Deno.removeSync(tempFile);
});
}
});
test({
name: "SYNC: setting existing uid/gid works as expected (non-Windows)",
fn() {
const tempFile: string = Deno.makeTempFileSync();
const originalUserId: number | null = Deno.lstatSync(tempFile).uid;
const originalGroupId: number | null = Deno.lstatSync(tempFile).gid;
chownSync(tempFile, originalUserId!, originalGroupId!);
test({
skip,
name: "SYNC: setting existing uid/gid works as expected (non-Windows)",
fn() {
const tempFile: string = Deno.makeTempFileSync();
const originalUserId: number | null = Deno.lstatSync(tempFile).uid;
const originalGroupId: number | null = Deno.lstatSync(tempFile).gid;
chownSync(tempFile, originalUserId!, originalGroupId!);
const newUserId: number | null = Deno.lstatSync(tempFile).uid;
const newGroupId: number | null = Deno.lstatSync(tempFile).gid;
assertEquals(newUserId, originalUserId);
assertEquals(newGroupId, originalGroupId);
Deno.removeSync(tempFile);
}
});
}
const newUserId: number | null = Deno.lstatSync(tempFile).uid;
const newGroupId: number | null = Deno.lstatSync(tempFile).gid;
assertEquals(newUserId, originalUserId);
assertEquals(newGroupId, originalGroupId);
Deno.removeSync(tempFile);
}
});

View file

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

View file

@ -17,13 +17,15 @@ const { test } = Deno;
function reader(s: string): TextProtoReader {
return new TextProtoReader(new BufReader(stringsReader(s)));
}
// test({
// name: "[textproto] Reader : DotBytes",
// 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({
skip: true,
name: "[textproto] Reader : DotBytes",
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> {
const r = reader("");