2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2022-10-26 00:23:21 +02:00
|
|
|
import { assert } from "./test_util.ts";
|
2020-02-25 22:01:24 -08:00
|
|
|
|
2022-09-28 15:03:56 +02:00
|
|
|
// Note tests for Deno.stdin.setRaw is in integration tests.
|
2020-02-25 22:01:24 -08:00
|
|
|
|
2022-10-26 00:23:21 +02:00
|
|
|
Deno.test(function consoleSize() {
|
|
|
|
if (!Deno.isatty(Deno.stdout.rid)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const result = Deno.consoleSize();
|
|
|
|
assert(typeof result.columns !== "undefined");
|
|
|
|
assert(typeof result.rows !== "undefined");
|
2020-07-10 10:07:12 -04:00
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test({ permissions: { read: true } }, function isatty() {
|
2020-02-25 22:01:24 -08:00
|
|
|
// CI not under TTY, so cannot test stdin/stdout/stderr.
|
2022-09-19 09:32:21 -05:00
|
|
|
const f = Deno.openSync("cli/tests/testdata/assets/hello.txt");
|
2020-02-25 22:01:24 -08:00
|
|
|
assert(!Deno.isatty(f.rid));
|
2020-02-29 18:45:47 +01:00
|
|
|
f.close();
|
2020-02-25 22:01:24 -08:00
|
|
|
});
|
|
|
|
|
2021-11-23 17:45:18 +01:00
|
|
|
Deno.test(function isattyError() {
|
2020-02-25 22:01:24 -08:00
|
|
|
let caught = false;
|
|
|
|
try {
|
|
|
|
// Absurdly large rid.
|
|
|
|
Deno.isatty(0x7fffffff);
|
|
|
|
} catch (e) {
|
|
|
|
caught = true;
|
|
|
|
assert(e instanceof Deno.errors.BadResource);
|
|
|
|
}
|
|
|
|
assert(caught);
|
|
|
|
});
|