diff --git a/tests/cli.rs b/tests/cli.rs index 2a2ef363b9..837a2f011d 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -201,10 +201,22 @@ fn execute(cmd: &mut Command, stdin: Option<&[u8]>, should_fail: bool) -> Result fn assert_output(bless: bool, output: &[u8], path: &Path, tempdir: &TempDir) -> Result<()> { let tempdir = tempdir.path().to_str().unwrap(); // sanitize the output to be consistent across platforms and handle per-test - // differences such as `%tmpdir`. + // differences such as `%tmpdir`, as well as the version number of the crate being + // tested in the producers custom section. let output = String::from_utf8_lossy(output) .replace(tempdir, "%tmpdir") - .replace("\\", "/"); + .replace("\\", "/") + .lines() + .map(|line| { + if let Some(start) = line.find("(processed-by \"wit-component\"") { + let (before, _) = line.split_at(start); + format!("{before}(processed-by \"wit-component\" \"%version\")") + } else { + line.to_owned() + } + }) + .collect::>() + .join("\n"); if bless { if output.is_empty() { @@ -222,9 +234,13 @@ fn assert_output(bless: bool, output: &[u8], path: &Path, tempdir: &TempDir) -> Ok(()) } } else { - let contents = std::fs::read_to_string(path) + let mut contents = std::fs::read_to_string(path) .with_context(|| format!("failed to read {path:?}"))? .replace("\r\n", "\n"); + // Drop any trailing newline, the lines iterator on output above will do the same + if contents.ends_with('\n') { + contents.pop(); + } if output != contents { bail!( "failed test: result is not as expected:{}", diff --git a/tests/cli/component-embed-only-custom.wit.stdout b/tests/cli/component-embed-only-custom.wit.stdout index 8ac8bd095a..74e8d4d90a 100644 --- a/tests/cli/component-embed-only-custom.wit.stdout +++ b/tests/cli/component-embed-only-custom.wit.stdout @@ -14,6 +14,6 @@ ) (export (;1;) "foo" (type 0)) (@producers - (processed-by "wit-component" "0.221.0") + (processed-by "wit-component" "%version") ) )