Skip to content

Commit 20eaa0e

Browse files
committed
Eliminate reliance on ctor
1 parent 07e1edb commit 20eaa0e

14 files changed

Lines changed: 65 additions & 106 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ jobs:
108108
env:
109109
GITHUB_TOKEN: ${{ github.token }}
110110

111-
- name: Test `ci`
111+
- name: Run `ci` tests
112112
if: matrix.environment == 'ubuntu-latest'
113-
run: cargo test --config "$GROUP_RUNNER" -p ci
113+
run: cargo run -p ci
114114

115115
all-checks:
116116
needs: [test]

Cargo.lock

Lines changed: 2 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ reqwest = { version = "0.13", default-features = false, features = [
4040

4141
[dev-dependencies]
4242
assert_cmd = "2.2"
43-
ctor = "1.0"
4443
octocrab = "0.49"
4544
predicates = "3.1"
4645
rustls = { version = "0.23", default-features = false, features = [

ci/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,13 @@ version = "0.1.0"
44
edition = "2024"
55
publish = false
66

7+
[dependencies]
8+
anyhow = "1.0"
9+
cargo_metadata = "0.23"
10+
elaborate = "0.2"
11+
712
[dev-dependencies]
813
assert_cmd = "2.2"
9-
ctor = "1.0"
1014
elaborate = "0.2"
1115
regex = "1.12"
1216
serde_json = "1.0"

ci/src/bin/ci.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
use anyhow::{Result, anyhow, bail};
2+
use cargo_metadata::{Message, camino::Utf8PathBuf};
3+
use elaborate::std::process::CommandContext;
4+
use std::process::Command;
5+
6+
fn main() {
7+
let executable = test_executable().unwrap();
8+
let status = Command::new(executable).status_wc().unwrap();
9+
assert!(status.success());
10+
}
11+
12+
fn test_executable() -> Result<Utf8PathBuf> {
13+
let mut command = Command::new("cargo");
14+
let output = command
15+
.args(["build", "--workspace", "--tests", "--message-format=json"])
16+
.output_wc()?;
17+
if !output.status.success() {
18+
bail!("command failed: {command:?}");
19+
}
20+
let messages =
21+
Message::parse_stream(output.stdout.as_slice()).collect::<Result<Vec<_>, _>>()?;
22+
let executables = messages
23+
.into_iter()
24+
.filter_map(|message| {
25+
if let Message::CompilerArtifact(artifact) = message
26+
&& artifact.target.name == "ci"
27+
&& artifact.target.is_lib()
28+
&& artifact.profile.test
29+
&& let Some(executable) = artifact.executable
30+
{
31+
Some(executable)
32+
} else {
33+
None
34+
}
35+
})
36+
.collect::<Vec<_>>();
37+
if executables.len() >= 2 {
38+
bail!("found multiple test executables: {executables:?}");
39+
}
40+
executables
41+
.into_iter()
42+
.next()
43+
.ok_or_else(|| anyhow!("found no test executables"))
44+
}

ci/src/lib.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
use assert_cmd::assert::OutputAssertExt;
44
use elaborate::std::{
5-
env::{set_current_dir_wc, var_wc},
5+
env::var_wc,
66
fs::{read_to_string_wc, write_wc},
77
path::PathContext,
88
process::CommandContext,
99
};
1010
use regex::Regex;
1111
use similar_asserts::SimpleDiff;
1212
use std::{
13-
env::remove_var,
1413
ffi::OsStr,
1514
ops::Range,
1615
path::Path,
@@ -21,14 +20,6 @@ use tempfile::tempdir;
2120
use testing::split_at_cut_lines;
2221
use walkdir::WalkDir;
2322

24-
#[ctor::ctor(unsafe)]
25-
fn initialize() {
26-
unsafe {
27-
remove_var("CARGO_TERM_COLOR");
28-
}
29-
let _ = set_current_dir_wc("..");
30-
}
31-
3223
#[test]
3324
fn clippy() {
3425
Command::new("cargo")

ei/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ publish = false
66

77
[dev-dependencies]
88
assert_cmd = "2.2"
9-
ctor = "1.0"
109
elaborate = "0.2"
1110
regex = "1.12"
1211
snapbox = "1.2"

ei/tests/dogfood.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
use elaborate::std::env::set_current_dir_wc;
2-
use std::{env::remove_var, process::Command};
1+
use std::process::Command;
32
use testing::{Tee, tee};
43

5-
#[ctor::ctor(unsafe)]
6-
fn initialize() {
7-
unsafe {
8-
remove_var("CARGO_TERM_COLOR");
9-
}
10-
let _ = set_current_dir_wc("..");
11-
}
12-
134
#[test]
145
fn dogfood() {
156
let mut command = Command::new("cargo");
@@ -22,6 +13,7 @@ fn dogfood() {
2213
"unmaintained",
2314
"--color=never",
2415
]);
16+
command.current_dir("..");
2517

2618
let output = tee(command, Tee::Stdout).unwrap();
2719

ei/tests/rustsec_advisories.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
use elaborate::std::{
2-
env::{set_current_dir_wc, var_wc},
2+
env::var_wc,
33
fs::{read_to_string_wc, write_wc},
44
};
55
use regex::Regex;
66
use snapbox::assert_data_eq;
77
use std::{
8-
env::remove_var,
98
io::{Write, stderr},
109
process::Command,
1110
sync::LazyLock,
@@ -17,21 +16,14 @@ const PATH_STDOUT: &str = concat!(
1716
"/tests/rustsec_advisories.stdout"
1817
);
1918

20-
#[ctor::ctor(unsafe)]
21-
fn initialize() {
22-
unsafe {
23-
remove_var("CARGO_TERM_COLOR");
24-
}
25-
let _ = set_current_dir_wc("..");
26-
}
27-
2819
#[cfg_attr(dylint_lib = "general", allow(non_thread_safe_call_in_test))]
2920
#[test]
3021
fn rustsec_advisories() {
3122
let mut command = Command::new("cargo");
3223
command
3324
.args(["run", "--example=rustsec_advisories"])
34-
.env("RUST_BACKTRACE", "0");
25+
.env("RUST_BACKTRACE", "0")
26+
.current_dir("..");
3527

3628
let output = tee(command, Tee::Stdout).unwrap();
3729

ei/tests/rustsec_issues.rs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
1-
use elaborate::std::{
2-
env::{set_current_dir_wc, var_wc},
3-
fs::write_wc,
4-
};
1+
use elaborate::std::{env::var_wc, fs::write_wc};
52
use snapbox::{Data, assert_data_eq};
6-
use std::{env::remove_var, path::PathBuf, process::Command};
3+
use std::{path::PathBuf, process::Command};
74
use testing::{Tee, tee};
85

9-
#[ctor::ctor(unsafe)]
10-
fn initialize() {
11-
unsafe {
12-
remove_var("CARGO_TERM_COLOR");
13-
}
14-
let _ = set_current_dir_wc("..");
15-
}
16-
176
#[test]
187
fn rustsec_issues() {
198
const PATH_STDOUT: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/tests/rustsec_issues.stdout");
209

2110
let mut command = Command::new("cargo");
22-
command.args(["run", "--example=rustsec_issues"]);
11+
command
12+
.args(["run", "--example=rustsec_issues"])
13+
.current_dir("..");
2314

2415
let output = tee(command, Tee::Stdout).unwrap();
2516

0 commit comments

Comments
 (0)