2022-01-20 02:10:16 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-11-23 11:45:18 -05:00
|
|
|
import { assert, assertThrows } from "./test_util.ts";
|
2020-02-26 01:01:24 -05:00
|
|
|
|
|
|
|
// Note tests for Deno.setRaw is in integration tests.
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test({ permissions: { read: true } }, function consoleSizeFile() {
|
2021-08-11 10:20:47 -04:00
|
|
|
const file = Deno.openSync("cli/tests/testdata/hello.txt");
|
2020-07-10 10:07:12 -04:00
|
|
|
assertThrows(() => {
|
|
|
|
Deno.consoleSize(file.rid);
|
|
|
|
}, Error);
|
|
|
|
file.close();
|
|
|
|
});
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(function consoleSizeError() {
|
2020-07-10 10:07:12 -04:00
|
|
|
assertThrows(() => {
|
|
|
|
// Absurdly large rid.
|
|
|
|
Deno.consoleSize(0x7fffffff);
|
|
|
|
}, Deno.errors.BadResource);
|
|
|
|
});
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test({ permissions: { read: true } }, function isatty() {
|
2020-02-26 01:01:24 -05:00
|
|
|
// CI not under TTY, so cannot test stdin/stdout/stderr.
|
2021-08-11 10:20:47 -04:00
|
|
|
const f = Deno.openSync("cli/tests/testdata/hello.txt");
|
2020-02-26 01:01:24 -05:00
|
|
|
assert(!Deno.isatty(f.rid));
|
2020-02-29 12:45:47 -05:00
|
|
|
f.close();
|
2020-02-26 01:01:24 -05:00
|
|
|
});
|
|
|
|
|
2021-11-23 11:45:18 -05:00
|
|
|
Deno.test(function isattyError() {
|
2020-02-26 01:01:24 -05:00
|
|
|
let caught = false;
|
|
|
|
try {
|
|
|
|
// Absurdly large rid.
|
|
|
|
Deno.isatty(0x7fffffff);
|
|
|
|
} catch (e) {
|
|
|
|
caught = true;
|
|
|
|
assert(e instanceof Deno.errors.BadResource);
|
|
|
|
}
|
|
|
|
assert(caught);
|
|
|
|
});
|