Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
427cf94
run_make_support: move `impl_common_helpers` into own `macros` module
jieyouxu Jul 15, 2024
544dda3
run_make_support: move target checks into `targets` module
jieyouxu Jul 15, 2024
a02008e
run_make_support: move `env_var{,_os}` into `env_checked` module
jieyouxu Jul 15, 2024
288c572
run_make_support: move external deps to `external_deps` module
jieyouxu Jul 15, 2024
f042e72
run_make_support: cleanup and document some lib.rs reexports
jieyouxu Jul 15, 2024
439c6f6
run_make_support: move `ar` into own module
jieyouxu Jul 15, 2024
483328d
run_make_support: move artifact name helpers into `artifact_names` mo…
jieyouxu Jul 15, 2024
dc95315
run_make_support: move path-related helpers into own module
jieyouxu Jul 15, 2024
17212ab
run_make_support: move fs helpers to own module
jieyouxu Jul 15, 2024
66cef19
run_make_support: move `run_in_tmpdir` and `test_while_readonly` to `…
jieyouxu Jul 15, 2024
f66d3d3
run_make_support: move assertions and helpers into own module
jieyouxu Jul 15, 2024
230804d
run_make_support: rename `recursive_diff` to `assert_recursive_eq`
jieyouxu Jul 15, 2024
56cbfa8
tests: update rustdoc test for renamed `assert_recursive_eq`
jieyouxu Jul 15, 2024
88fd1df
run_make_support: move `assert_recursive_eq` into `assertion_helpers`
jieyouxu Jul 15, 2024
e956808
run_make_support: move `handle_failed_output` into `util` module
jieyouxu Jul 15, 2024
aadd085
run_make_support: make `set_host_rpath` private and move into `util`
jieyouxu Jul 15, 2024
b7f7205
run_make_support: move `build_native_static_lib` under `external_deps`
jieyouxu Jul 17, 2024
a443dc4
run_make_support: rename `env_checked` -> `env`
jieyouxu Jul 17, 2024
13a1751
run_make_support: rename `cygpath_windows` to `get_windows_path` and …
jieyouxu Jul 17, 2024
e1569fd
run_make_support: coalesce fs helpers into single `fs` module
jieyouxu Jul 17, 2024
636be91
tests: update for renamed `fs` module in run_make_support
jieyouxu Jul 17, 2024
0dfecb3
run_make_support: move some helpers from assertion to path
jieyouxu Jul 17, 2024
57a2f76
run_make_support: moved some helpers into `string` module
jieyouxu Jul 17, 2024
30bdc4a
run_make_support: rename `assert_recursive_eq` to `assert_dirs_are_eq…
jieyouxu Jul 17, 2024
a00b860
tests: update rustdoc test for renamed `assert_dirs_are_equal`
jieyouxu Jul 17, 2024
1f1bf4c
run_make_support: use `fs` internally, but `rfs` to tests
jieyouxu Jul 17, 2024
d69cc1c
tests: update for `rfs` rename
jieyouxu Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
run_make_support: moved some helpers into string module
  • Loading branch information
jieyouxu committed Jul 17, 2024
commit 57a2f76557c3b4ea4ad0c40f1c9dc9c11ca9d289
46 changes: 0 additions & 46 deletions src/tools/run-make-support/src/assertion_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,6 @@ use std::path::Path;

use crate::fs as rfs;

/// Gathers all files in the current working directory that have the extension `ext`, and counts
/// the number of lines within that contain a match with the regex pattern `re`.
pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));

let mut count = 0;
for file in fetched_files {
let content = rfs::read_to_string(file);
count += content.lines().filter(|line| re.is_match(&line)).count();
}

count
}

/// Read the contents of a file that cannot simply be read by
/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert
/// that it contains `expected`.
#[track_caller]
pub fn invalid_utf8_contains<P: AsRef<Path>, S: AsRef<str>>(path: P, expected: S) {
let buffer = rfs::read(path.as_ref());
let expected = expected.as_ref();
if !String::from_utf8_lossy(&buffer).contains(expected) {
eprintln!("=== FILE CONTENTS (LOSSY) ===");
eprintln!("{}", String::from_utf8_lossy(&buffer));
eprintln!("=== SPECIFIED TEXT ===");
eprintln!("{}", expected);
panic!("specified text was not found in file");
}
}

/// Read the contents of a file that cannot simply be read by
/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert
/// that it does not contain `expected`.
#[track_caller]
pub fn invalid_utf8_not_contains<P: AsRef<Path>, S: AsRef<str>>(path: P, expected: S) {
let buffer = rfs::read(path.as_ref());
let expected = expected.as_ref();
if String::from_utf8_lossy(&buffer).contains(expected) {
eprintln!("=== FILE CONTENTS (LOSSY) ===");
eprintln!("{}", String::from_utf8_lossy(&buffer));
eprintln!("=== SPECIFIED TEXT ===");
eprintln!("{}", expected);
panic!("specified text was unexpectedly found in file");
}
}

/// Assert that `actual` is equal to `expected`.
#[track_caller]
pub fn assert_equals<A: AsRef<str>, E: AsRef<str>>(actual: A, expected: E) {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/run-make-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod fs;
pub mod path_helpers;
pub mod run;
pub mod scoped_run;
pub mod string;
pub mod targets;

// Re-exports of third-party library crates.
Expand Down Expand Up @@ -71,5 +72,8 @@ pub use scoped_run::{run_in_tmpdir, test_while_readonly};

pub use assertion_helpers::{
assert_contains, assert_equals, assert_not_contains, assert_recursive_eq,
};

pub use string::{
count_regex_matches_in_files_with_extension, invalid_utf8_contains, invalid_utf8_not_contains,
};
50 changes: 50 additions & 0 deletions src/tools/run-make-support/src/string.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use std::path::Path;

use crate::fs as rfs;
use crate::path_helpers::{cwd, has_extension, shallow_find_files};

/// Gathers all files in the current working directory that have the extension `ext`, and counts
/// the number of lines within that contain a match with the regex pattern `re`.
pub fn count_regex_matches_in_files_with_extension(re: &regex::Regex, ext: &str) -> usize {
let fetched_files = shallow_find_files(cwd(), |path| has_extension(path, ext));

let mut count = 0;
for file in fetched_files {
let content = rfs::read_to_string(file);
count += content.lines().filter(|line| re.is_match(&line)).count();
}

count
}

/// Read the contents of a file that cannot simply be read by
/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert
/// that it contains `expected`.
#[track_caller]
pub fn invalid_utf8_contains<P: AsRef<Path>, S: AsRef<str>>(path: P, expected: S) {
let buffer = rfs::read(path.as_ref());
let expected = expected.as_ref();
if !String::from_utf8_lossy(&buffer).contains(expected) {
eprintln!("=== FILE CONTENTS (LOSSY) ===");
eprintln!("{}", String::from_utf8_lossy(&buffer));
eprintln!("=== SPECIFIED TEXT ===");
eprintln!("{}", expected);
panic!("specified text was not found in file");
}
}

/// Read the contents of a file that cannot simply be read by
/// [`read_to_string`][crate::fs::read_to_string], due to invalid UTF-8 data, then assert
/// that it does not contain `expected`.
#[track_caller]
pub fn invalid_utf8_not_contains<P: AsRef<Path>, S: AsRef<str>>(path: P, expected: S) {
let buffer = rfs::read(path.as_ref());
let expected = expected.as_ref();
if String::from_utf8_lossy(&buffer).contains(expected) {
eprintln!("=== FILE CONTENTS (LOSSY) ===");
eprintln!("{}", String::from_utf8_lossy(&buffer));
eprintln!("=== SPECIFIED TEXT ===");
eprintln!("{}", expected);
panic!("specified text was unexpectedly found in file");
}
}