Fix tests on Windows

Fixes #386.
This commit is contained in:
Laurenz 2023-03-28 14:28:02 +02:00
parent a0249d2309
commit e84df1a036
4 changed files with 11 additions and 15 deletions

View File

@ -2,7 +2,7 @@ use std::cell::{RefCell, RefMut};
use std::collections::HashMap;
use std::fs::{self, File};
use std::hash::Hash;
use std::io::{self, Read, Write};
use std::io::{self, Write};
use std::path::{Path, PathBuf};
use std::process;
@ -559,11 +559,8 @@ impl PathHash {
/// Read a file.
fn read(path: &Path) -> FileResult<Vec<u8>> {
let f = |e| FileError::from_io(e, path);
let mut file = File::open(path).map_err(f)?;
if file.metadata().map_err(f)?.is_file() {
let mut data = vec![];
file.read_to_end(&mut data).map_err(f)?;
Ok(data)
if fs::metadata(&path).map_err(f)?.is_file() {
fs::read(&path).map_err(f)
} else {
Err(FileError::IsDirectory)
}

View File

@ -5,6 +5,9 @@ description: |
---
# Changelog
## Unreleased
- Reduced maximum function call depth from 256 to 64.
## March 28, 2023
- **Breaking:** Enumerations now require a space after their marker, that is,
`[1.ok]` must now be written as `[1. ok]`

View File

@ -60,7 +60,7 @@ use crate::util::PathExt;
use crate::World;
const MAX_ITERATIONS: usize = 10_000;
const MAX_CALL_DEPTH: usize = 256;
const MAX_CALL_DEPTH: usize = 64;
/// Evaluate a source file and return the resulting module.
#[comemo::memoize]

View File

@ -2,8 +2,7 @@ use std::cell::{RefCell, RefMut};
use std::collections::HashMap;
use std::env;
use std::ffi::OsStr;
use std::fs::{self, File};
use std::io::Read;
use std::fs;
use std::ops::Range;
use std::path::{Path, PathBuf};
@ -325,11 +324,8 @@ fn read(path: &Path) -> FileResult<Vec<u8>> {
.unwrap_or_else(|_| path.into());
let f = |e| FileError::from_io(e, &suffix);
let mut file = File::open(&path).map_err(f)?;
if file.metadata().map_err(f)?.is_file() {
let mut data = vec![];
file.read_to_end(&mut data).map_err(f)?;
Ok(data)
if fs::metadata(&path).map_err(f)?.is_file() {
fs::read(&path).map_err(f)
} else {
Err(FileError::IsDirectory)
}
@ -472,7 +468,7 @@ fn test_part(
let mut errors: Vec<_> = errors
.into_iter()
.filter(|error| error.span.source() == id)
.map(|error| (error.range(world), error.message.to_string()))
.map(|error| (error.range(world), error.message.replace('\\', "/")))
.collect();
errors.sort_by_key(|error| error.0.start);