mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-04 09:20:15 -06:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ba25ee491 |
+2
-1
File diff suppressed because one or more lines are too long
@@ -147,8 +147,14 @@ pub(crate) fn paste(app: &mut WordApp) -> Option<Result<Value, String>> {
|
||||
}
|
||||
let mut r = Err(String::new());
|
||||
for path in files {
|
||||
let size = std::fs::metadata(&path).map(|m| m.len()).unwrap_or(0);
|
||||
r = if size > MAX_FILE_BYTES {
|
||||
// A clipboard path can name a pipe or device that reports no length and never ends.
|
||||
let md = std::fs::metadata(&path).ok();
|
||||
let size = md.as_ref().map_or(0, |m| m.len());
|
||||
r = if md.as_ref().is_some_and(|m| !m.is_file()) {
|
||||
let e = format!("{} is not a regular file", path.display());
|
||||
app.status(e.clone());
|
||||
Err(e)
|
||||
} else if size > MAX_FILE_BYTES {
|
||||
let e = format!("{} is larger than 200 MB", path.display());
|
||||
app.status(e.clone());
|
||||
Err(e)
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+4
-2
@@ -73,8 +73,10 @@ mod tests {
|
||||
fn a_failed_file_listing_fails_the_check() {
|
||||
// #1364: outside a git checkout `git ls-files` fails, and its empty output read as "no
|
||||
// files" passed the check.
|
||||
let dir = std::env::temp_dir().join(format!("wordcraft-xtask-assets-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
// Created exclusively under a name no one can predict: an existing folder or link there would be someone else's.
|
||||
let nanos = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.subsec_nanos());
|
||||
let dir = std::env::temp_dir().join(format!("wordcraft-xtask-assets-{}-{nanos}", std::process::id()));
|
||||
std::fs::create_dir(&dir).unwrap();
|
||||
std::fs::write(dir.join("ATTRIBUTION.md"), "").unwrap();
|
||||
let inside_git = Command::new("git").current_dir(&dir).args(["rev-parse", "--git-dir"]).output().is_ok_and(|o| o.status.success());
|
||||
let result = run(&dir);
|
||||
|
||||
+18
-2
@@ -18,12 +18,14 @@ fn walk(dir: &Path, c: &mut Counts) {
|
||||
let p = e.path();
|
||||
let name = e.file_name();
|
||||
let name = name.to_string_lossy();
|
||||
if p.is_dir() {
|
||||
// A symlink is never followed: several links to an ancestor would multiply the walk.
|
||||
if e.file_type().is_ok_and(|t| t.is_dir()) {
|
||||
// Nested fuzz workspaces and build output are not part of the crate.
|
||||
if name != "target" && name != "fuzz" && !name.starts_with('.') {
|
||||
walk(&p, c);
|
||||
}
|
||||
} else if name.ends_with(".rs")
|
||||
&& e.file_type().is_ok_and(|t| t.is_file())
|
||||
&& let Ok(s) = std::fs::read_to_string(&p)
|
||||
{
|
||||
c.files += 1;
|
||||
@@ -108,11 +110,25 @@ pub fn run(_root: &Path, exact: bool) -> Result<(), String> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::count_tests;
|
||||
use super::{Counts, count_tests, walk};
|
||||
|
||||
#[test]
|
||||
fn counts_attributes_and_proptest_blocks() {
|
||||
let src = "#[test]\nfn a() {}\n// #[test] commented\n #[test]\nfn b() {}\nproptest! {\n}\n";
|
||||
assert_eq!(count_tests(src), (2, 1));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn a_walk_does_not_follow_directory_links() {
|
||||
let nanos = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.subsec_nanos());
|
||||
let dir = std::env::temp_dir().join(format!("wordcraft-xtask-stats-{}-{nanos}", std::process::id()));
|
||||
std::fs::create_dir(&dir).unwrap();
|
||||
std::fs::write(dir.join("a.rs"), "#[test]\n").unwrap();
|
||||
std::os::unix::fs::symlink(&dir, dir.join("loop")).unwrap();
|
||||
let mut c = Counts::default();
|
||||
walk(&dir, &mut c);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
assert_eq!((c.files, c.tests), (1, 1));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user