summaryrefslogtreecommitdiff
path: root/cli/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tests/unit')
-rw-r--r--cli/tests/unit/buffer_test.ts55
-rw-r--r--cli/tests/unit/process_test.ts67
2 files changed, 57 insertions, 65 deletions
diff --git a/cli/tests/unit/buffer_test.ts b/cli/tests/unit/buffer_test.ts
index 23e655a05..c5a63b5c8 100644
--- a/cli/tests/unit/buffer_test.ts
+++ b/cli/tests/unit/buffer_test.ts
@@ -12,9 +12,6 @@ import {
unitTest,
} from "./test_util.ts";
-const { Buffer, readAll, readAllSync, writeAll, writeAllSync } = Deno;
-type Buffer = Deno.Buffer;
-
// N controls how many iterations of certain checks are performed.
const N = 100;
let testBytes: Uint8Array | null;
@@ -44,7 +41,7 @@ function check(buf: Deno.Buffer, s: string): void {
// The initial contents of buf corresponds to the string s;
// the result is the final contents of buf returned as a string.
async function fillBytes(
- buf: Buffer,
+ buf: Deno.Buffer,
s: string,
n: number,
fub: Uint8Array
@@ -62,7 +59,11 @@ async function fillBytes(
// Empty buf through repeated reads into fub.
// The initial contents of buf corresponds to the string s.
-async function empty(buf: Buffer, s: string, fub: Uint8Array): Promise<void> {
+async function empty(
+ buf: Deno.Buffer,
+ s: string,
+ fub: Uint8Array
+): Promise<void> {
check(buf, s);
while (true) {
const r = await buf.read(fub);
@@ -86,7 +87,7 @@ unitTest(function bufferNewBuffer(): void {
init();
assert(testBytes);
assert(testString);
- const buf = new Buffer(testBytes.buffer as ArrayBuffer);
+ const buf = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
check(buf, testString);
});
@@ -94,7 +95,7 @@ unitTest(async function bufferBasicOperations(): Promise<void> {
init();
assert(testBytes);
assert(testString);
- const buf = new Buffer();
+ const buf = new Deno.Buffer();
for (let i = 0; i < 5; i++) {
check(buf, "");
@@ -133,7 +134,7 @@ unitTest(async function bufferBasicOperations(): Promise<void> {
unitTest(async function bufferReadEmptyAtEOF(): Promise<void> {
// check that EOF of 'buf' is not reached (even though it's empty) if
// results are written to buffer that has 0 length (ie. it can't store any data)
- const buf = new Buffer();
+ const buf = new Deno.Buffer();
const zeroLengthTmp = new Uint8Array(0);
const result = await buf.read(zeroLengthTmp);
assertEquals(result, 0);
@@ -141,7 +142,7 @@ unitTest(async function bufferReadEmptyAtEOF(): Promise<void> {
unitTest(async function bufferLargeByteWrites(): Promise<void> {
init();
- const buf = new Buffer();
+ const buf = new Deno.Buffer();
const limit = 9;
for (let i = 3; i < limit; i += 3) {
const s = await fillBytes(buf, "", 5, testBytes!);
@@ -155,7 +156,7 @@ unitTest(async function bufferTooLargeByteWrites(): Promise<void> {
const tmp = new Uint8Array(72);
const growLen = Number.MAX_VALUE;
const xBytes = repeat("x", 0);
- const buf = new Buffer(xBytes.buffer as ArrayBuffer);
+ const buf = new Deno.Buffer(xBytes.buffer as ArrayBuffer);
await buf.read(tmp);
let err;
@@ -173,7 +174,7 @@ unitTest(async function bufferLargeByteReads(): Promise<void> {
init();
assert(testBytes);
assert(testString);
- const buf = new Buffer();
+ const buf = new Deno.Buffer();
for (let i = 3; i < 30; i += 3) {
const n = Math.floor(testBytes.byteLength / i);
const s = await fillBytes(buf, "", 5, testBytes.subarray(0, n));
@@ -183,7 +184,7 @@ unitTest(async function bufferLargeByteReads(): Promise<void> {
});
unitTest(function bufferCapWithPreallocatedSlice(): void {
- const buf = new Buffer(new ArrayBuffer(10));
+ const buf = new Deno.Buffer(new ArrayBuffer(10));
assertEquals(buf.capacity, 10);
});
@@ -191,7 +192,7 @@ unitTest(async function bufferReadFrom(): Promise<void> {
init();
assert(testBytes);
assert(testString);
- const buf = new Buffer();
+ const buf = new Deno.Buffer();
for (let i = 3; i < 30; i += 3) {
const s = await fillBytes(
buf,
@@ -199,13 +200,13 @@ unitTest(async function bufferReadFrom(): Promise<void> {
5,
testBytes.subarray(0, Math.floor(testBytes.byteLength / i))
);
- const b = new Buffer();
+ const b = new Deno.Buffer();
await b.readFrom(buf);
const fub = new Uint8Array(testString.length);
await empty(b, s, fub);
}
assertThrowsAsync(async function () {
- await new Buffer().readFrom(null!);
+ await new Deno.Buffer().readFrom(null!);
});
});
@@ -213,7 +214,7 @@ unitTest(async function bufferReadFromSync(): Promise<void> {
init();
assert(testBytes);
assert(testString);
- const buf = new Buffer();
+ const buf = new Deno.Buffer();
for (let i = 3; i < 30; i += 3) {
const s = await fillBytes(
buf,
@@ -221,13 +222,13 @@ unitTest(async function bufferReadFromSync(): Promise<void> {
5,
testBytes.subarray(0, Math.floor(testBytes.byteLength / i))
);
- const b = new Buffer();
+ const b = new Deno.Buffer();
b.readFromSync(buf);
const fub = new Uint8Array(testString.length);
await empty(b, s, fub);
}
assertThrows(function () {
- new Buffer().readFromSync(null!);
+ new Deno.Buffer().readFromSync(null!);
});
});
@@ -236,7 +237,7 @@ unitTest(async function bufferTestGrow(): Promise<void> {
for (const startLen of [0, 100, 1000, 10000, 100000]) {
const xBytes = repeat("x", startLen);
for (const growLen of [0, 100, 1000, 10000, 100000]) {
- const buf = new Buffer(xBytes.buffer as ArrayBuffer);
+ const buf = new Deno.Buffer(xBytes.buffer as ArrayBuffer);
// If we read, this affects buf.off, which is good to test.
const nread = (await buf.read(tmp)) ?? 0;
buf.grow(growLen);
@@ -258,8 +259,8 @@ unitTest(async function bufferTestGrow(): Promise<void> {
unitTest(async function testReadAll(): Promise<void> {
init();
assert(testBytes);
- const reader = new Buffer(testBytes.buffer as ArrayBuffer);
- const actualBytes = await readAll(reader);
+ const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
+ const actualBytes = await Deno.readAll(reader);
assertEquals(testBytes.byteLength, actualBytes.byteLength);
for (let i = 0; i < testBytes.length; ++i) {
assertEquals(testBytes[i], actualBytes[i]);
@@ -269,8 +270,8 @@ unitTest(async function testReadAll(): Promise<void> {
unitTest(function testReadAllSync(): void {
init();
assert(testBytes);
- const reader = new Buffer(testBytes.buffer as ArrayBuffer);
- const actualBytes = readAllSync(reader);
+ const reader = new Deno.Buffer(testBytes.buffer as ArrayBuffer);
+ const actualBytes = Deno.readAllSync(reader);
assertEquals(testBytes.byteLength, actualBytes.byteLength);
for (let i = 0; i < testBytes.length; ++i) {
assertEquals(testBytes[i], actualBytes[i]);
@@ -280,8 +281,8 @@ unitTest(function testReadAllSync(): void {
unitTest(async function testWriteAll(): Promise<void> {
init();
assert(testBytes);
- const writer = new Buffer();
- await writeAll(writer, testBytes);
+ const writer = new Deno.Buffer();
+ await Deno.writeAll(writer, testBytes);
const actualBytes = writer.bytes();
assertEquals(testBytes.byteLength, actualBytes.byteLength);
for (let i = 0; i < testBytes.length; ++i) {
@@ -292,8 +293,8 @@ unitTest(async function testWriteAll(): Promise<void> {
unitTest(function testWriteAllSync(): void {
init();
assert(testBytes);
- const writer = new Buffer();
- writeAllSync(writer, testBytes);
+ const writer = new Deno.Buffer();
+ Deno.writeAllSync(writer, testBytes);
const actualBytes = writer.bytes();
assertEquals(testBytes.byteLength, actualBytes.byteLength);
for (let i = 0; i < testBytes.length; ++i) {
diff --git a/cli/tests/unit/process_test.ts b/cli/tests/unit/process_test.ts
index c6503b2e0..cf512eea5 100644
--- a/cli/tests/unit/process_test.ts
+++ b/cli/tests/unit/process_test.ts
@@ -5,20 +5,11 @@ import {
assertStringContains,
unitTest,
} from "./test_util.ts";
-const {
- kill,
- run,
- readFile,
- open,
- makeTempDir,
- writeFile,
- writeFileSync,
-} = Deno;
unitTest(function runPermissions(): void {
let caughtError = false;
try {
- run({ cmd: ["python", "-c", "print('hello world')"] });
+ Deno.run({ cmd: ["python", "-c", "print('hello world')"] });
} catch (e) {
caughtError = true;
assert(e instanceof Deno.errors.PermissionDenied);
@@ -27,7 +18,7 @@ unitTest(function runPermissions(): void {
});
unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "print('hello world')"],
stdout: "piped",
stderr: "null",
@@ -43,7 +34,7 @@ unitTest({ perms: { run: true } }, async function runSuccess(): Promise<void> {
unitTest(
{ perms: { run: true } },
async function runCommandFailedWithCode(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys;sys.exit(41 + 1)"],
});
const status = await p.status();
@@ -61,7 +52,7 @@ unitTest(
perms: { run: true },
},
async function runCommandFailedWithSignal(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import os;os.kill(os.getpid(), 9)"],
});
const status = await p.status();
@@ -75,7 +66,7 @@ unitTest(
unitTest({ perms: { run: true } }, function runNotFound(): void {
let error;
try {
- run({ cmd: ["this file hopefully doesn't exist"] });
+ Deno.run({ cmd: ["this file hopefully doesn't exist"] });
} catch (e) {
error = e;
}
@@ -87,7 +78,7 @@ unitTest(
{ perms: { write: true, run: true } },
async function runWithCwdIsAsync(): Promise<void> {
const enc = new TextEncoder();
- const cwd = await makeTempDir({ prefix: "deno_command_test" });
+ const cwd = await Deno.makeTempDir({ prefix: "deno_command_test" });
const exitCodeFile = "deno_was_here";
const pyProgramFile = "poll_exit.py";
@@ -107,8 +98,8 @@ while True:
pass
`;
- writeFileSync(`${cwd}/${pyProgramFile}.py`, enc.encode(pyProgram));
- const p = run({
+ Deno.writeFileSync(`${cwd}/${pyProgramFile}.py`, enc.encode(pyProgram));
+ const p = Deno.run({
cwd,
cmd: ["python", `${pyProgramFile}.py`],
});
@@ -116,7 +107,7 @@ while True:
// Write the expected exit code *after* starting python.
// This is how we verify that `run()` is actually asynchronous.
const code = 84;
- writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`));
+ Deno.writeFileSync(`${cwd}/${exitCodeFile}`, enc.encode(`${code}`));
const status = await p.status();
assertEquals(status.success, false);
@@ -129,7 +120,7 @@ while True:
unitTest({ perms: { run: true } }, async function runStdinPiped(): Promise<
void
> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
stdin: "piped",
});
@@ -153,7 +144,7 @@ unitTest({ perms: { run: true } }, async function runStdinPiped(): Promise<
unitTest({ perms: { run: true } }, async function runStdoutPiped(): Promise<
void
> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
stdout: "piped",
});
@@ -182,7 +173,7 @@ unitTest({ perms: { run: true } }, async function runStdoutPiped(): Promise<
unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
void
> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; sys.stderr.write('hello')"],
stderr: "piped",
});
@@ -209,7 +200,7 @@ unitTest({ perms: { run: true } }, async function runStderrPiped(): Promise<
});
unitTest({ perms: { run: true } }, async function runOutput(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; sys.stdout.write('hello')"],
stdout: "piped",
});
@@ -222,7 +213,7 @@ unitTest({ perms: { run: true } }, async function runOutput(): Promise<void> {
unitTest({ perms: { run: true } }, async function runStderrOutput(): Promise<
void
> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; sys.stderr.write('error')"],
stderr: "piped",
});
@@ -235,14 +226,14 @@ unitTest({ perms: { run: true } }, async function runStderrOutput(): Promise<
unitTest(
{ perms: { run: true, write: true, read: true } },
async function runRedirectStdoutStderr(): Promise<void> {
- const tempDir = await makeTempDir();
+ const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
- const file = await open(fileName, {
+ const file = await Deno.open(fileName, {
create: true,
write: true,
});
- const p = run({
+ const p = Deno.run({
cmd: [
"python",
"-c",
@@ -256,7 +247,7 @@ unitTest(
p.close();
file.close();
- const fileContents = await readFile(fileName);
+ const fileContents = await Deno.readFile(fileName);
const decoder = new TextDecoder();
const text = decoder.decode(fileContents);
@@ -268,13 +259,13 @@ unitTest(
unitTest(
{ perms: { run: true, write: true, read: true } },
async function runRedirectStdin(): Promise<void> {
- const tempDir = await makeTempDir();
+ const tempDir = await Deno.makeTempDir();
const fileName = tempDir + "/redirected_stdio.txt";
const encoder = new TextEncoder();
- await writeFile(fileName, encoder.encode("hello"));
- const file = await open(fileName);
+ await Deno.writeFile(fileName, encoder.encode("hello"));
+ const file = await Deno.open(fileName);
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "import sys; assert 'hello' == sys.stdin.read();"],
stdin: file.rid,
});
@@ -287,7 +278,7 @@ unitTest(
);
unitTest({ perms: { run: true } }, async function runEnv(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: [
"python",
"-c",
@@ -306,7 +297,7 @@ unitTest({ perms: { run: true } }, async function runEnv(): Promise<void> {
});
unitTest({ perms: { run: true } }, async function runClose(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: [
"python",
"-c",
@@ -340,7 +331,7 @@ unitTest(function killPermissions(): void {
// subprocess we can safely kill. Instead we send SIGCONT to the current
// process - assuming that Deno does not have a special handler set for it
// and will just continue even if a signal is erroneously sent.
- kill(Deno.pid, Deno.Signal.SIGCONT);
+ Deno.kill(Deno.pid, Deno.Signal.SIGCONT);
} catch (e) {
caughtError = true;
assert(e instanceof Deno.errors.PermissionDenied);
@@ -349,12 +340,12 @@ unitTest(function killPermissions(): void {
});
unitTest({ perms: { run: true } }, async function killSuccess(): Promise<void> {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "from time import sleep; sleep(10000)"],
});
assertEquals(Deno.Signal.SIGINT, 2);
- kill(p.pid, Deno.Signal.SIGINT);
+ Deno.kill(p.pid, Deno.Signal.SIGINT);
const status = await p.status();
assertEquals(status.success, false);
@@ -371,7 +362,7 @@ unitTest({ perms: { run: true } }, async function killSuccess(): Promise<void> {
});
unitTest({ perms: { run: true } }, function killFailed(): void {
- const p = run({
+ const p = Deno.run({
cmd: ["python", "-c", "from time import sleep; sleep(10000)"],
});
assert(!p.stdin);
@@ -379,7 +370,7 @@ unitTest({ perms: { run: true } }, function killFailed(): void {
let err;
try {
- kill(p.pid, 12345);
+ Deno.kill(p.pid, 12345);
} catch (e) {
err = e;
}