mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 12:16:11 -05:00
Merge remote-tracking branch 'upstream/main' into check-workspace-member-compiler-options
This commit is contained in:
commit
8f5465e5ef
21 changed files with 144 additions and 25 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -3086,9 +3086,9 @@ checksum = "c007b1ae3abe1cb6f85a16305acd418b7ca6343b953633fee2b76d8f108b830f"
|
|||
|
||||
[[package]]
|
||||
name = "file_test_runner"
|
||||
version = "0.7.2"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05b23dcc1b671771c6f59fdace6da685735c925f859733e8fd07fba6cae6462a"
|
||||
checksum = "cf50901549edf2241e33d1715aec0575adc5510a09724877a1e0afe7ffafb0fb"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"crossbeam-channel",
|
||||
|
|
|
@ -4454,11 +4454,7 @@ fn op_load<'s>(
|
|||
== NodeModuleKind::Cjs,
|
||||
})
|
||||
};
|
||||
|
||||
lsp_warn!("op_load {} {}", &specifier, maybe_load_response.is_some());
|
||||
|
||||
let serialized = serde_v8::to_v8(scope, maybe_load_response)?;
|
||||
|
||||
state.performance.measure(mark);
|
||||
Ok(serialized)
|
||||
}
|
||||
|
|
|
@ -634,7 +634,7 @@ impl FileBackedVfsFile {
|
|||
}
|
||||
|
||||
fn read_to_buf(&self, buf: &mut [u8]) -> FsResult<usize> {
|
||||
let pos = {
|
||||
let read_pos = {
|
||||
let mut pos = self.pos.lock();
|
||||
let read_pos = *pos;
|
||||
// advance the position due to the read
|
||||
|
@ -643,12 +643,12 @@ impl FileBackedVfsFile {
|
|||
};
|
||||
self
|
||||
.vfs
|
||||
.read_file(&self.file, pos, buf)
|
||||
.read_file(&self.file, read_pos, buf)
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
|
||||
fn read_to_end(&self) -> FsResult<Vec<u8>> {
|
||||
let pos = {
|
||||
let read_pos = {
|
||||
let mut pos = self.pos.lock();
|
||||
let read_pos = *pos;
|
||||
// todo(dsherret): should this always set it to the end of the file?
|
||||
|
@ -658,12 +658,12 @@ impl FileBackedVfsFile {
|
|||
}
|
||||
read_pos
|
||||
};
|
||||
if pos > self.file.len {
|
||||
if read_pos > self.file.len {
|
||||
return Ok(Vec::new());
|
||||
}
|
||||
let size = (self.file.len - pos) as usize;
|
||||
let size = (self.file.len - read_pos) as usize;
|
||||
let mut buf = vec![0; size];
|
||||
self.vfs.read_file(&self.file, pos, &mut buf)?;
|
||||
self.vfs.read_file(&self.file, read_pos, &mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
}
|
||||
|
@ -893,8 +893,9 @@ impl FileBackedVfs {
|
|||
buf: &mut [u8],
|
||||
) -> std::io::Result<usize> {
|
||||
let read_range = self.get_read_range(file, pos, buf.len() as u64)?;
|
||||
buf.copy_from_slice(&self.vfs_data[read_range]);
|
||||
Ok(buf.len())
|
||||
let read_len = read_range.len();
|
||||
buf[..read_len].copy_from_slice(&self.vfs_data[read_range]);
|
||||
Ok(read_len)
|
||||
}
|
||||
|
||||
fn get_read_range(
|
||||
|
@ -903,15 +904,15 @@ impl FileBackedVfs {
|
|||
pos: u64,
|
||||
len: u64,
|
||||
) -> std::io::Result<Range<usize>> {
|
||||
let data = &self.vfs_data;
|
||||
let start = self.fs_root.start_file_offset + file.offset + pos;
|
||||
let end = start + len;
|
||||
if end > data.len() as u64 {
|
||||
if pos > file.len {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::UnexpectedEof,
|
||||
"unexpected EOF",
|
||||
));
|
||||
}
|
||||
let file_offset = self.fs_root.start_file_offset + file.offset;
|
||||
let start = file_offset + pos;
|
||||
let end = file_offset + std::cmp::min(pos + len, file.len);
|
||||
Ok(start as usize..end as usize)
|
||||
}
|
||||
|
||||
|
|
|
@ -549,7 +549,11 @@ pub fn format_sql(
|
|||
// Add single new line to the end of file.
|
||||
formatted_str.push('\n');
|
||||
|
||||
Ok(Some(formatted_str))
|
||||
Ok(if formatted_str == file_text {
|
||||
None
|
||||
} else {
|
||||
Some(formatted_str)
|
||||
})
|
||||
}
|
||||
|
||||
/// Formats a single TS, TSX, JS, JSX, JSONC, JSON, MD, IPYNB or SQL file.
|
||||
|
|
|
@ -88,7 +88,7 @@ export function readFile(
|
|||
}
|
||||
const buffer = maybeDecode(data, encoding);
|
||||
(cb as BinaryCallback)(null, buffer);
|
||||
}, (err) => cb && cb(denoErrorToNodeError(err)));
|
||||
}, (err) => cb && cb(denoErrorToNodeError(err, { path, syscall: "open" })));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ export function readFileSync(
|
|||
try {
|
||||
data = Deno.readFileSync(path);
|
||||
} catch (err) {
|
||||
throw denoErrorToNodeError(err);
|
||||
throw denoErrorToNodeError(err, { path, syscall: "open" });
|
||||
}
|
||||
const encoding = getEncoding(opt);
|
||||
if (encoding && encoding !== "binary") {
|
||||
|
|
|
@ -45,7 +45,7 @@ deno_semver.workspace = true
|
|||
deno_terminal.workspace = true
|
||||
deno_tls.workspace = true
|
||||
fastwebsockets = { workspace = true, features = ["upgrade", "unstable-split"] }
|
||||
file_test_runner = "0.7.2"
|
||||
file_test_runner = "0.7.3"
|
||||
flaky_test = "=0.2.2"
|
||||
hickory-client = "=0.24"
|
||||
hickory-server = "=0.24"
|
||||
|
|
27
tests/specs/compile/include/buffered_reads/__test__.jsonc
Normal file
27
tests/specs/compile/include/buffered_reads/__test__.jsonc
Normal file
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
"tempDir": true,
|
||||
"steps": [{
|
||||
"args": "run -A setup.js",
|
||||
"output": "[WILDCARD]"
|
||||
}, {
|
||||
"if": "unix",
|
||||
"args": "compile --allow-read=data --include data --output main main.ts",
|
||||
"output": "[WILDCARD]"
|
||||
}, {
|
||||
"if": "unix",
|
||||
"commandName": "./main",
|
||||
"args": [],
|
||||
"output": "[WILDCARD]",
|
||||
"exitCode": 0
|
||||
}, {
|
||||
"if": "windows",
|
||||
"args": "compile --allow-read=data --include data --output main.exe main.ts",
|
||||
"output": "[WILDCARD]"
|
||||
}, {
|
||||
"if": "windows",
|
||||
"commandName": "./main.exe",
|
||||
"args": [],
|
||||
"output": "[WILDCARD]",
|
||||
"exitCode": 0
|
||||
}]
|
||||
}
|
57
tests/specs/compile/include/buffered_reads/main.ts
Normal file
57
tests/specs/compile/include/buffered_reads/main.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
// buffer larger than file
|
||||
{
|
||||
using file = Deno.openSync(import.meta.dirname + "/data/1.txt");
|
||||
const data = new Uint8Array(13);
|
||||
const len = file.readSync(data);
|
||||
if (len !== 13) {
|
||||
throw new Error("Unexpected read length");
|
||||
}
|
||||
if (file.readSync(new Uint8Array(1024)) !== null) {
|
||||
throw new Error("Unexpected.");
|
||||
}
|
||||
const textData = new TextDecoder().decode(data);
|
||||
if (textData !== "Hello, world!") {
|
||||
throw new Error("Unexpected file data (1): " + textData);
|
||||
}
|
||||
}
|
||||
|
||||
// buffer smaller than file
|
||||
{
|
||||
using file = Deno.openSync(import.meta.dirname + "/data/1.txt");
|
||||
const finalData = new Uint8Array(13);
|
||||
const data = new Uint8Array(2);
|
||||
let pos = 0;
|
||||
while (true) {
|
||||
const len = file.readSync(data);
|
||||
if (len === 0 || len == null) {
|
||||
break;
|
||||
}
|
||||
finalData.set(data.subarray(0, len), pos);
|
||||
pos += len;
|
||||
}
|
||||
const textData = new TextDecoder().decode(finalData);
|
||||
if (textData !== "Hello, world!") {
|
||||
throw new Error("Unexpected file data (2): " + textData);
|
||||
}
|
||||
}
|
||||
|
||||
// large amount of data, small reads
|
||||
{
|
||||
const bytes = new Uint8Array((1024 ** 2) * 20);
|
||||
using file = Deno.openSync(import.meta.dirname + "/data/2.dat");
|
||||
const buffer = new Uint8Array(2);
|
||||
let pos = 0;
|
||||
while (true) {
|
||||
const len = file.readSync(buffer);
|
||||
if (len === 0 || len == null) {
|
||||
break;
|
||||
}
|
||||
bytes.set(buffer.subarray(0, len), pos);
|
||||
pos += len;
|
||||
}
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
if (bytes[i] !== i % 256) {
|
||||
throw new Error("Unexpected data.");
|
||||
}
|
||||
}
|
||||
}
|
7
tests/specs/compile/include/buffered_reads/setup.js
Normal file
7
tests/specs/compile/include/buffered_reads/setup.js
Normal file
|
@ -0,0 +1,7 @@
|
|||
Deno.mkdirSync("data");
|
||||
Deno.writeTextFileSync("data/1.txt", "Hello, world!");
|
||||
const bytes = new Uint8Array((1024 ** 2) * 20);
|
||||
for (let i = 0; i < bytes.length; i++) {
|
||||
bytes[i] = i % 256;
|
||||
}
|
||||
Deno.writeFileSync("data/2.dat", bytes);
|
|
@ -7,7 +7,7 @@
|
|||
},
|
||||
"flag": {
|
||||
"args": "fmt --unstable-sql",
|
||||
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
|
||||
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 7 files\n"
|
||||
},
|
||||
"config_file": {
|
||||
"steps": [{
|
||||
|
@ -18,8 +18,12 @@
|
|||
"output": "[WILDCARD]"
|
||||
}, {
|
||||
"args": "fmt",
|
||||
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]well_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
|
||||
"output": "[UNORDERED_START]\n[WILDLINE]badly_formatted.sql\n[WILDLINE]wrong_file_ignore.sql\n[UNORDERED_END]\nChecked 8 files\n"
|
||||
}]
|
||||
},
|
||||
"well_formatted_check": {
|
||||
"args": "fmt --unstable-sql --check well_formatted.sql",
|
||||
"output": "Checked 1 file\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { assertCallbackErrorUncaught } from "../_test_utils.ts";
|
||||
import { promises, readFile, readFileSync } from "node:fs";
|
||||
import * as path from "@std/path";
|
||||
import { assert, assertEquals } from "@std/assert";
|
||||
import { assert, assertEquals, assertMatch } from "@std/assert";
|
||||
|
||||
const moduleDir = path.dirname(path.fromFileUrl(import.meta.url));
|
||||
const testData = path.resolve(moduleDir, "testdata", "hello.txt");
|
||||
|
@ -121,3 +121,26 @@ Deno.test("fs.promises.readFile with no arg call rejects with error correctly",
|
|||
// @ts-ignore no arg call needs to be supported
|
||||
await promises.readFile().catch((_e) => {});
|
||||
});
|
||||
|
||||
Deno.test("fs.readFile error message contains path + syscall", async () => {
|
||||
const path = "/does/not/exist";
|
||||
const err = await new Promise((resolve) => {
|
||||
readFile(path, "utf-8", (err) => resolve(err));
|
||||
});
|
||||
if (err instanceof Error) {
|
||||
assert(err.message.includes(path), "Path not found in error message");
|
||||
assertMatch(err.message, /[,\s]open\s/);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test("fs.readFileSync error message contains path + syscall", () => {
|
||||
const path = "/does/not/exist";
|
||||
try {
|
||||
readFileSync(path, "utf-8");
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
assert(err.message.includes(path), "Path not found in error message");
|
||||
assertMatch(err.message, /[,\s]open\s/);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue