| 1 |
Description: Fix running tests via cargo_auto_test. |
| 2 |
There are a few issues with running the tests under cargo_auto_test. |
| 3 |
|
| 4 |
cargo_auto_test sets CARGO_TARGET_DIR, this has a couple of |
| 5 |
implications, Firstly trying to reverse-engineer the crate root |
| 6 |
directory doesn't work. We use the CARGO_MANIFEST_DIR envvar instead. |
| 7 |
|
| 8 |
Secondly CARGO_TARGET_DIR needs to be unset before building the |
| 9 |
pint executable, otherwise it will end up in cargo_auto_test's |
| 10 |
target directory rather than the target directory for our test crate. |
| 11 |
|
| 12 |
Finally the Debian cargo wrapper always passess --target, we need to |
| 13 |
account for this when looking for the location of the "pint" executable. |
| 14 |
Author: Peter Michael Green <[email protected]> |
| 15 |
Origin: vendor |
| 16 |
Forwarded: not-needed |
| 17 |
Last-Update: 2026-08-17 |
| 18 |
--- |
| 19 |
--- a/tests/capturing.rs |
| 20 |
+++ b/tests/capturing.rs |
| 21 |
@@ -2,6 +2,8 @@ extern crate tempfile; |
| 22 |
extern crate tar; |
| 23 |
|
| 24 |
use std::path::Path; |
| 25 |
+use std::path::PathBuf; |
| 26 |
+ |
| 27 |
|
| 28 |
const FILES: &'static [(&'static str, &'static str)] = &[ |
| 29 |
("Cargo.toml", r#" |
| 30 |
@@ -72,7 +74,7 @@ fn unpack_files(directory: &Path, replac |
| 31 |
fn capturing() { |
| 32 |
use std::process::Command; |
| 33 |
use std::env; |
| 34 |
- use std::str::from_utf8; |
| 35 |
+ use std::str::from_utf8; |
| 36 |
|
| 37 |
let rootdir = { |
| 38 |
let mut rootdir = env::current_exe().unwrap(); |
| 39 |
@@ -87,10 +89,11 @@ fn capturing() { |
| 40 |
.prefix("fomat-macros-capturing-test") |
| 41 |
.tempdir() |
| 42 |
.expect("Can't create tempdir"); |
| 43 |
- unpack_files(pintdir.as_ref(), rootdir.to_str().unwrap()); |
| 44 |
+ unpack_files(pintdir.as_ref(), /*rootdir.to_str().unwrap()*/&env::var("CARGO_MANIFEST_DIR").unwrap()); |
| 45 |
|
| 46 |
assert!( |
| 47 |
Command::new("cargo").arg("build") |
| 48 |
+ .env_remove("CARGO_TARGET_DIR") |
| 49 |
.current_dir(&pintdir) |
| 50 |
.status().unwrap().success() |
| 51 |
); |
| 52 |
@@ -98,7 +101,27 @@ fn capturing() { |
| 53 |
let expected_stdout = "stdout1stdout2\n"; |
| 54 |
let expected_stderr = "stderr1stderr2\nstderr1stderr2\n"; |
| 55 |
|
| 56 |
- let output = Command::new("target/debug/pint") |
| 57 |
+ /*use std::io::stdout; |
| 58 |
+ use std::io::Write; |
| 59 |
+ let output = Command::new("find") |
| 60 |
+ .current_dir(&pintdir) |
| 61 |
+ .output().unwrap(); |
| 62 |
+ stdout().write_all(&output.stdout); |
| 63 |
+ |
| 64 |
+ for (key, value) in env::vars() { |
| 65 |
+ println!("{key}: {value}"); |
| 66 |
+ }*/ |
| 67 |
+ |
| 68 |
+ let pintexe; |
| 69 |
+ if pintdir.as_ref().join("target/debug/pint").exists() { |
| 70 |
+ pintexe = PathBuf::from("target/debug/pint"); |
| 71 |
+ } else if pintdir.as_ref().join("target").join(env::var("DEB_TARGET_RUST_TYPE").unwrap_or("___envar_not_found___".to_string())).join("debug/pint").exists() { |
| 72 |
+ pintexe = Path::new("target").join(env::var("DEB_TARGET_RUST_TYPE").unwrap()).join("debug/pint"); |
| 73 |
+ } else { |
| 74 |
+ panic!("can't find pint exuctable"); |
| 75 |
+ } |
| 76 |
+ |
| 77 |
+ let output = Command::new(pintexe) |
| 78 |
.current_dir(&pintdir) |
| 79 |
.output().unwrap(); |
| 80 |
assert!(output.status.success()); |