summaryrefslogtreecommitdiff
path: root/test_util/src/assertions.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-02-27 16:52:49 -0400
committerGitHub <noreply@github.com>2023-02-27 16:52:49 -0400
commit7c090b1b14e6b5000dbbed434525387c414ca62c (patch)
tree1645fbd8a8b1aee55f79cfe74d2bb7ecadcf5215 /test_util/src/assertions.rs
parent6bbb4c3af60d568a34e1472a0721ddd8a3dab469 (diff)
chore: test builders for integration tests (#17965)
Start of adding test builders to simplify integration tests. I only updated a few test files. We can complete upgrading over time.
Diffstat (limited to 'test_util/src/assertions.rs')
-rw-r--r--test_util/src/assertions.rs60
1 files changed, 60 insertions, 0 deletions
diff --git a/test_util/src/assertions.rs b/test_util/src/assertions.rs
index a004530b6..994926566 100644
--- a/test_util/src/assertions.rs
+++ b/test_util/src/assertions.rs
@@ -39,3 +39,63 @@ macro_rules! assert_not_contains {
}
}
}
+
+#[macro_export]
+macro_rules! assert_output_text {
+ ($output:expr, $expected:expr) => {
+ let expected_text = $expected;
+ let actual = $output.text();
+
+ if !expected_text.contains("[WILDCARD]") {
+ assert_eq!(actual, expected_text)
+ } else if !test_util::wildcard_match(&expected_text, actual) {
+ println!("OUTPUT START\n{}\nOUTPUT END", actual);
+ println!("EXPECTED START\n{expected_text}\nEXPECTED END");
+ panic!("pattern match failed");
+ }
+ };
+}
+
+#[macro_export]
+macro_rules! assert_output_file {
+ ($output:expr, $file_path:expr) => {
+ let output = &$output;
+ let output_path = output.testdata_dir().join($file_path);
+ println!("output path {}", output_path.display());
+ let expected_text =
+ std::fs::read_to_string(&output_path).unwrap_or_else(|err| {
+ panic!("failed loading {}\n\n{err:#}", output_path.display())
+ });
+ test_util::assert_output_text!(output, expected_text);
+ };
+}
+
+#[macro_export]
+macro_rules! assert_exit_code {
+ ($output:expr, $exit_code:expr) => {
+ let output = &$output;
+ let actual = output.text();
+ let expected_exit_code = $exit_code;
+ let actual_exit_code = output.exit_code();
+
+ if let Some(exit_code) = &actual_exit_code {
+ if *exit_code != expected_exit_code {
+ println!("OUTPUT\n{actual}\nOUTPUT");
+ panic!(
+ "bad exit code, expected: {:?}, actual: {:?}",
+ expected_exit_code, exit_code
+ );
+ }
+ } else {
+ println!("OUTPUT\n{actual}\nOUTPUT");
+ if let Some(signal) = output.signal() {
+ panic!(
+ "process terminated by signal, expected exit code: {:?}, actual signal: {:?}",
+ actual_exit_code, signal,
+ );
+ } else {
+ panic!("process terminated without status code on non unix platform, expected exit code: {:?}", actual_exit_code);
+ }
+ }
+ };
+}