Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 19 additions & 5 deletions tests/dsv_cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ fn succinctly_bin() -> &'static Path {
String::from_utf8_lossy(&output.stderr)
);

let mut path = std::env::current_exe().expect("resolve current_exe");
path.pop(); // drop the test executable's file name -> `.../deps`
if path.file_name().and_then(|s| s.to_str()) == Some("deps") {
path.pop(); // drop `deps` -> `.../<profile>`
}
let mut path = target_profile_dir_from_test_exe();
path.push(format!("succinctly{}", std::env::consts::EXE_SUFFIX));
assert!(
path.is_file(),
Expand All @@ -51,6 +47,24 @@ fn succinctly_bin() -> &'static Path {
})
}

/// Derive `<target>/<profile>/` from this test executable's own path.
///
/// The classic flat layout places the test exe at
/// `<target>/<profile>/deps/<test>-<hash>`, but nightly's build-dir-layout-v2
/// (rust-lang/cargo#17258, defaulted on nightly toolchains from ~2026-07)
/// instead nests it at `<target>/<profile>/build/<pkg>/<hash>/out/<test>-<hash>`.
/// Both layouts keep `<profile>` as the path component immediately after
/// `target`, so locate it that way instead of assuming a fixed depth.
fn target_profile_dir_from_test_exe() -> PathBuf {
let current_exe = std::env::current_exe().expect("resolve current_exe");
let components: Vec<_> = current_exe.components().collect();
let target_idx = components
.iter()
.rposition(|c| c.as_os_str() == "target")
.expect("test executable path has no `target` component");
components[..=target_idx + 1].iter().collect()
}

/// Run `dsv generate` and capture stdout, stderr, and exit code.
fn run_generate(size: &str, extra_args: &[&str]) -> Result<(String, String, i32)> {
let output = Command::new(succinctly_bin())
Expand Down
28 changes: 21 additions & 7 deletions tests/json_validate_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ fn succinctly_bin() -> &'static Path {
String::from_utf8_lossy(&output.stderr)
);

// The test executable lives at `<target>/<profile>/deps/<test>-<hash>`;
// the CLI binary is its sibling at `<target>/<profile>/succinctly`.
let mut path = std::env::current_exe().expect("resolve current_exe");
path.pop(); // drop the test executable's file name -> `.../deps`
if path.file_name().and_then(|s| s.to_str()) == Some("deps") {
path.pop(); // drop `deps` -> `.../<profile>`
}
// The CLI binary is `<target>/<profile>/succinctly`, a sibling of the
// test executable's own `<target>/<profile>/` ancestor.
let mut path = target_profile_dir_from_test_exe();
path.push(format!("succinctly{}", std::env::consts::EXE_SUFFIX));
assert!(
path.is_file(),
Expand All @@ -55,6 +51,24 @@ fn succinctly_bin() -> &'static Path {
})
}

/// Derive `<target>/<profile>/` from this test executable's own path.
///
/// The classic flat layout places the test exe at
/// `<target>/<profile>/deps/<test>-<hash>`, but nightly's build-dir-layout-v2
/// (rust-lang/cargo#17258, defaulted on nightly toolchains from ~2026-07)
/// instead nests it at `<target>/<profile>/build/<pkg>/<hash>/out/<test>-<hash>`.
/// Both layouts keep `<profile>` as the path component immediately after
/// `target`, so locate it that way instead of assuming a fixed depth.
fn target_profile_dir_from_test_exe() -> PathBuf {
let current_exe = std::env::current_exe().expect("resolve current_exe");
let components: Vec<_> = current_exe.components().collect();
let target_idx = components
.iter()
.rposition(|c| c.as_os_str() == "target")
.expect("test executable path has no `target` component");
components[..=target_idx + 1].iter().collect()
}

/// Helper to run `json validate` with input from stdin.
fn run_validate_stdin(input: &str, extra_args: &[&str]) -> Result<(String, String, i32)> {
let mut cmd = Command::new(succinctly_bin())
Expand Down
24 changes: 19 additions & 5 deletions tests/text_cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,7 @@ fn succinctly_bin() -> &'static Path {
String::from_utf8_lossy(&output.stderr)
);

let mut path = std::env::current_exe().expect("resolve current_exe");
path.pop(); // drop the test executable's file name -> `.../deps`
if path.file_name().and_then(|s| s.to_str()) == Some("deps") {
path.pop(); // drop `deps` -> `.../<profile>`
}
let mut path = target_profile_dir_from_test_exe();
path.push(format!("succinctly{}", std::env::consts::EXE_SUFFIX));
assert!(
path.is_file(),
Expand All @@ -53,6 +49,24 @@ fn succinctly_bin() -> &'static Path {
})
}

/// Derive `<target>/<profile>/` from this test executable's own path.
///
/// The classic flat layout places the test exe at
/// `<target>/<profile>/deps/<test>-<hash>`, but nightly's build-dir-layout-v2
/// (rust-lang/cargo#17258, defaulted on nightly toolchains from ~2026-07)
/// instead nests it at `<target>/<profile>/build/<pkg>/<hash>/out/<test>-<hash>`.
/// Both layouts keep `<profile>` as the path component immediately after
/// `target`, so locate it that way instead of assuming a fixed depth.
fn target_profile_dir_from_test_exe() -> PathBuf {
let current_exe = std::env::current_exe().expect("resolve current_exe");
let components: Vec<_> = current_exe.components().collect();
let target_idx = components
.iter()
.rposition(|c| c.as_os_str() == "target")
.expect("test executable path has no `target` component");
components[..=target_idx + 1].iter().collect()
}

/// Run `text validate utf8` with raw bytes piped on stdin.
fn run_validate_stdin(input: &[u8], extra_args: &[&str]) -> Result<(Vec<u8>, String, i32)> {
let mut cmd = Command::new(succinctly_bin())
Expand Down
24 changes: 19 additions & 5 deletions tests/yaml_validate_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ fn succinctly_bin() -> &'static Path {
String::from_utf8_lossy(&output.stderr)
);

let mut path = std::env::current_exe().expect("resolve current_exe");
path.pop();
if path.file_name().and_then(|s| s.to_str()) == Some("deps") {
path.pop();
}
let mut path = target_profile_dir_from_test_exe();
path.push(format!("succinctly{}", std::env::consts::EXE_SUFFIX));
assert!(
path.is_file(),
Expand All @@ -43,6 +39,24 @@ fn succinctly_bin() -> &'static Path {
})
}

/// Derive `<target>/<profile>/` from this test executable's own path.
///
/// The classic flat layout places the test exe at
/// `<target>/<profile>/deps/<test>-<hash>`, but nightly's build-dir-layout-v2
/// (rust-lang/cargo#17258, defaulted on nightly toolchains from ~2026-07)
/// instead nests it at `<target>/<profile>/build/<pkg>/<hash>/out/<test>-<hash>`.
/// Both layouts keep `<profile>` as the path component immediately after
/// `target`, so locate it that way instead of assuming a fixed depth.
fn target_profile_dir_from_test_exe() -> PathBuf {
let current_exe = std::env::current_exe().expect("resolve current_exe");
let components: Vec<_> = current_exe.components().collect();
let target_idx = components
.iter()
.rposition(|c| c.as_os_str() == "target")
.expect("test executable path has no `target` component");
components[..=target_idx + 1].iter().collect()
}

fn run_validate_stdin(input: &str, extra_args: &[&str]) -> Result<(String, String, i32)> {
let mut cmd = Command::new(succinctly_bin())
.args(["yaml", "validate"])
Expand Down
Loading