Skip to content

Commit c1e531e

Browse files
committed
Fix elaborate_disallowed_methods test
1 parent 314389f commit c1e531e

7 files changed

Lines changed: 47 additions & 40 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ci/src/lib.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#![cfg(test)]
22

33
use assert_cmd::assert::OutputAssertExt;
4+
use elaborate::std::{
5+
env::{set_current_dir_wc, var_wc},
6+
fs::{read_to_string_wc, write_wc},
7+
path::PathContext,
8+
process::CommandContext,
9+
};
410
use regex::Regex;
511
use similar_asserts::SimpleDiff;
612
use std::{
7-
env::{remove_var, set_current_dir, var},
13+
env::remove_var,
814
ffi::OsStr,
9-
fs::{read_to_string, write},
1015
ops::Range,
1116
path::Path,
1217
process::{Command, ExitStatus},
@@ -21,7 +26,7 @@ fn initialize() {
2126
unsafe {
2227
remove_var("CARGO_TERM_COLOR");
2328
}
24-
set_current_dir("..");
29+
let _ = set_current_dir_wc("..");
2530
}
2631

2732
#[test]
@@ -55,7 +60,7 @@ fn dylint() {
5560
#[test]
5661
fn elaborate_disallowed_methods() {
5762
elaborate::disallowed_methods()
58-
.args(["--all-features", "--all-targets"])
63+
.args(["--workspace", "--all-features", "--all-targets"])
5964
.env("RUSTUP_TOOLCHAIN", "nightly")
6065
.assert()
6166
.success();
@@ -174,7 +179,7 @@ fn prettier() {
174179
// smoelius: Copied from Necessist:
175180
// Prettier's handling of `..` seems to have changed between versions 3.4 and 3.5.
176181
// Manually collapsing the `..` avoids the problem.
177-
let parent = Path::new(env!("CARGO_MANIFEST_DIR")).parent().unwrap();
182+
let parent = Path::new(env!("CARGO_MANIFEST_DIR")).parent_wc().unwrap();
178183

179184
let tempdir = tempdir().unwrap();
180185

@@ -197,10 +202,10 @@ fn prettier() {
197202

198203
#[test]
199204
fn readme_contains_expected_contents() {
200-
let contents = read_to_string("ei/tests/rustsec_advisories.stdout").unwrap();
205+
let contents = read_to_string_wc("ei/tests/rustsec_advisories.stdout").unwrap();
201206
let (_, middle_expected, bottom_expected) = split_at_cut_lines(&contents).unwrap();
202207

203-
let readme = read_to_string("README.md").unwrap();
208+
let readme = read_to_string_wc("README.md").unwrap();
204209
let lines = readme.lines();
205210

206211
let mut lines = lines.skip_while(|&line| line != "<!-- as-of start -->");
@@ -225,7 +230,7 @@ fn readme_contains_expected_contents() {
225230
#[cfg_attr(target_os = "windows", ignore)]
226231
#[test]
227232
fn readme_contains_usage() {
228-
let readme = read_to_string("README.md").unwrap();
233+
let readme = read_to_string_wc("README.md").unwrap();
229234

230235
let assert = Command::new("cargo")
231236
.args([
@@ -256,7 +261,7 @@ fn readme_contains_usage() {
256261
#[test]
257262
fn readme_reference_links_are_sorted() {
258263
let re = Regex::new(r"^\[[^\]]*\]:").unwrap();
259-
let readme = read_to_string("README.md").unwrap();
264+
let readme = read_to_string_wc("README.md").unwrap();
260265
let links = readme
261266
.lines()
262267
.filter(|line| re.is_match(line))
@@ -269,7 +274,7 @@ fn readme_reference_links_are_sorted() {
269274
#[test]
270275
fn readme_reference_links_are_used() {
271276
let re = Regex::new(r"(?m)^(\[[^\]]*\]):").unwrap();
272-
let readme = read_to_string("README.md").unwrap();
277+
let readme = read_to_string_wc("README.md").unwrap();
273278
for captures in re.captures_iter(&readme) {
274279
assert_eq!(2, captures.len());
275280
let m = captures.get(1).unwrap();
@@ -289,7 +294,7 @@ fn dependencies_are_sorted() {
289294
.filter(|e| e.file_name() == OsStr::new("Cargo.toml"))
290295
{
291296
let path = entry.path();
292-
let contents = read_to_string(path).unwrap();
297+
let contents = read_to_string_wc(path).unwrap();
293298
let document = contents.parse::<toml_edit::Document<_>>().unwrap();
294299
for table_name in ["dependencies", "dev-dependencies", "build-dependencies"] {
295300
let Some(span) = key_value_pair_span(&document, table_name) else {
@@ -366,7 +371,7 @@ fn group_starts<S: AsRef<str>>(
366371
fn supply_chain() {
367372
let mut command = Command::new("cargo");
368373
command.args(["supply-chain", "update", "--cache-max-age=0s"]);
369-
let _: ExitStatus = command.status().unwrap();
374+
let _: ExitStatus = command.status_wc().unwrap();
370375

371376
let mut command = Command::new("cargo");
372377
command.args(["supply-chain", "json", "--no-dev"]);
@@ -380,9 +385,9 @@ fn supply_chain() {
380385
let path_buf = Path::new(env!("CARGO_MANIFEST_DIR")).join("supply_chain.json");
381386

382387
if enabled("BLESS") {
383-
write(path_buf, stdout_normalized).unwrap();
388+
write_wc(path_buf, stdout_normalized).unwrap();
384389
} else {
385-
let stdout_expected = read_to_string(&path_buf).unwrap();
390+
let stdout_expected = read_to_string_wc(&path_buf).unwrap();
386391

387392
assert!(
388393
stdout_expected == stdout_normalized,
@@ -416,5 +421,5 @@ fn remove_avatars(value: &mut serde_json::Value) {
416421
}
417422

418423
fn enabled(key: &str) -> bool {
419-
var(key).is_ok_and(|value| value != "0")
424+
var_wc(key).is_ok_and(|value| value != "0")
420425
}

ei/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ publish = false
77
[dev-dependencies]
88
assert_cmd = "2.2"
99
ctor = "1.0"
10+
elaborate = "0.2"
1011
regex = "1.12"
1112
snapbox = "1.2"
1213

ei/tests/dogfood.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
use std::{
2-
env::{remove_var, set_current_dir},
3-
process::Command,
4-
};
1+
use elaborate::std::env::set_current_dir_wc;
2+
use std::{env::remove_var, process::Command};
53
use testing::{Tee, tee};
64

75
#[ctor::ctor(unsafe)]
86
fn initialize() {
97
unsafe {
108
remove_var("CARGO_TERM_COLOR");
119
}
12-
set_current_dir("..");
10+
let _ = set_current_dir_wc("..");
1311
}
1412

1513
#[test]

ei/tests/rustsec_advisories.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
use elaborate::std::{
2+
env::{set_current_dir_wc, var_wc},
3+
fs::{read_to_string_wc, write_wc},
4+
};
15
use regex::Regex;
26
use snapbox::assert_data_eq;
37
use std::{
4-
env::{remove_var, set_current_dir, var},
5-
fs::{read_to_string, write},
8+
env::remove_var,
69
io::{Write, stderr},
710
process::Command,
811
sync::LazyLock,
@@ -19,7 +22,7 @@ fn initialize() {
1922
unsafe {
2023
remove_var("CARGO_TERM_COLOR");
2124
}
22-
set_current_dir("..");
25+
let _ = set_current_dir_wc("..");
2326
}
2427

2528
#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
@@ -32,11 +35,11 @@ fn rustsec_advisories() {
3235

3336
let output = tee(command, Tee::Stdout).unwrap();
3437

35-
let stdout_expected = read_to_string(PATH_STDOUT).unwrap();
38+
let stdout_expected = read_to_string_wc(PATH_STDOUT).unwrap();
3639
let stdout_actual = std::str::from_utf8(&output.captured).unwrap();
3740

38-
if var("BLESS").is_ok() {
39-
write(PATH_STDOUT, stdout_actual).unwrap();
41+
if var_wc("BLESS").is_ok() {
42+
write_wc(PATH_STDOUT, stdout_actual).unwrap();
4043
update_readme(stdout_actual);
4144

4245
#[allow(clippy::explicit_write)]
@@ -56,7 +59,7 @@ fn rustsec_advisories() {
5659
fn update_readme(stdout: &str) {
5760
let (_, middle, bottom) = split_at_cut_lines(stdout).unwrap();
5861

59-
let readme = read_to_string("README.md").unwrap();
62+
let readme = read_to_string_wc("README.md").unwrap();
6063

6164
let updated_with_as_of = replace_section(
6265
&readme,
@@ -72,7 +75,7 @@ fn update_readme(stdout: &str) {
7275
&format!("\n\n{}\n\n", bottom.trim()),
7376
);
7477

75-
write("README.md", readme_with_as_of_and_not_identified).unwrap();
78+
write_wc("README.md", readme_with_as_of_and_not_identified).unwrap();
7679
}
7780

7881
fn replace_section(content: &str, start_marker: &str, end_marker: &str, insertion: &str) -> String {
@@ -95,7 +98,7 @@ static TMP_RE: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"/tmp\b").unwrap()
9598

9699
#[test]
97100
fn sanitary() {
98-
let contents = read_to_string(PATH_STDOUT).unwrap();
101+
let contents = read_to_string_wc(PATH_STDOUT).unwrap();
99102

100103
for line in contents.lines() {
101104
assert!(

ei/tests/rustsec_issues.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
use snapbox::{Data, assert_data_eq};
2-
use std::{
3-
env::{remove_var, set_current_dir, var},
4-
fs::write,
5-
path::PathBuf,
6-
process::Command,
1+
use elaborate::std::{
2+
env::{set_current_dir_wc, var_wc},
3+
fs::write_wc,
74
};
5+
use snapbox::{Data, assert_data_eq};
6+
use std::{env::remove_var, path::PathBuf, process::Command};
87
use testing::{Tee, tee};
98

109
#[ctor::ctor(unsafe)]
1110
fn initialize() {
1211
unsafe {
1312
remove_var("CARGO_TERM_COLOR");
1413
}
15-
set_current_dir("..");
14+
let _ = set_current_dir_wc("..");
1615
}
1716

1817
#[test]
@@ -26,8 +25,8 @@ fn rustsec_issues() {
2625

2726
let stdout_actual = std::str::from_utf8(&output.captured).unwrap();
2827

29-
if var("BLESS").is_ok() {
30-
write(PATH_STDOUT, stdout_actual).unwrap();
28+
if var_wc("BLESS").is_ok() {
29+
write_wc(PATH_STDOUT, stdout_actual).unwrap();
3130
} else {
3231
assert_data_eq!(
3332
stdout_actual,

ei/tests/snapbox_real_github.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
use std::env::set_current_dir;
1+
use elaborate::std::env::set_current_dir_wc;
22

33
#[ctor::ctor(unsafe)]
44
fn initialize() {
5-
set_current_dir("..");
5+
let _ = set_current_dir_wc("..");
66
}
77

88
#[test]

0 commit comments

Comments
 (0)