|
1 | 1 | // Copyright 2018-2025 the Deno authors. MIT license. |
2 | 2 |
|
3 | | -import { assert, assertRejects } from "@std/assert"; |
4 | | -import { lstat } from "./unstable_lstat.ts"; |
| 3 | +import { assert, assertRejects, assertThrows } from "@std/assert"; |
| 4 | +import { lstat, lstatSync } from "./unstable_lstat.ts"; |
5 | 5 | import { NotFound } from "./unstable_errors.js"; |
6 | 6 |
|
7 | | -Deno.test("lstat() returns FileInfo for a file", async () => { |
8 | | - const fileInfo = await lstat("README.md"); |
9 | | - |
10 | | - assert(fileInfo.isFile); |
| 7 | +Deno.test("lstat() and lstatSync() return FileInfo for a file", async () => { |
| 8 | + { |
| 9 | + const fileInfo = await lstat("README.md"); |
| 10 | + assert(fileInfo.isFile); |
| 11 | + } |
| 12 | + { |
| 13 | + const fileInfo = lstatSync("README.md"); |
| 14 | + assert(fileInfo.isFile); |
| 15 | + } |
11 | 16 | }); |
12 | 17 |
|
13 | | -Deno.test("lstat() does not follow symlinks", async () => { |
14 | | - const linkFile = `${import.meta.dirname}/testdata/0-link`; |
15 | | - const fileInfo = await lstat(linkFile); |
16 | | - |
17 | | - assert(fileInfo.isSymlink); |
| 18 | +Deno.test("lstat() and lstatSync() do not follow symlinks", async () => { |
| 19 | + const linkFile = new URL("testdata/0-link", import.meta.url); |
| 20 | + { |
| 21 | + const fileInfo = await lstat(linkFile); |
| 22 | + assert(fileInfo.isSymlink); |
| 23 | + } |
| 24 | + { |
| 25 | + const fileInfo = lstatSync(linkFile); |
| 26 | + assert(fileInfo.isSymlink); |
| 27 | + } |
18 | 28 | }); |
19 | 29 |
|
20 | | -Deno.test("lstat() returns FileInfo for a directory", async () => { |
21 | | - const fileInfo = await lstat("fs"); |
22 | | - |
23 | | - assert(fileInfo.isDirectory); |
| 30 | +Deno.test("lstat() and lstatSync() return FileInfo for a directory", async () => { |
| 31 | + { |
| 32 | + const fileInfo = await lstat("fs"); |
| 33 | + assert(fileInfo.isDirectory); |
| 34 | + } |
| 35 | + { |
| 36 | + const fileInfo = lstatSync("fs"); |
| 37 | + assert(fileInfo.isDirectory); |
| 38 | + } |
24 | 39 | }); |
25 | 40 |
|
26 | | -Deno.test("lstat() rejects with NotFound for a non-existent file", async () => { |
| 41 | +Deno.test("lstat() and lstatSync() throw with NotFound for a non-existent file", async () => { |
27 | 42 | await assertRejects(async () => { |
28 | 43 | await lstat("non_existent_file"); |
29 | 44 | }, NotFound); |
| 45 | + assertThrows(() => { |
| 46 | + lstatSync("non_existent_file"); |
| 47 | + }, NotFound); |
30 | 48 | }); |
0 commit comments