### Enable Examples Feature for Snapbox Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Add this to your Cargo.toml to enable building and testing example binaries. ```toml [dependencies] snapbox = { version = "1.2", features = ["examples"] } ``` -------------------------------- ### Complete Directory Testing Example Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md A comprehensive test function demonstrating setup of a mutable temporary directory, running a generator command, and verifying the output structure using pattern matching. ```rust use snapbox::{cmd::Command, dir::DirRoot, assert_subset_matches}; use std::path::Path; #[test] fn test_project_generation() -> snapbox::assert::Result<()> { // Setup working directory let root = DirRoot::mutable_temp()?; let work_dir = root.path().unwrap(); // Run generator command Command::new(snapbox::cargo_bin!("generator")) .arg("--output") .arg(work_dir) .current_dir(work_dir) .assert() .success(); // Verify generated structure assert_subset_matches( "tests/expected_structure", work_dir ); // Cleanup (optional) root.close()?; Ok(()) } ``` -------------------------------- ### Directory Pattern Examples Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Provides practical examples of directory patterns for matching temporary files, version-specific outputs, platform executables, source files, and multi-line content. ```rust // Match any temporary files /tmp/[..]/output.txt // Match version-specific output version-[..].json // Match exe on all platforms program[EXE] // Match all files in directory src/[..].rs // Match any number of lines start ... end ``` -------------------------------- ### cargo_bin! Macro Example Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Example demonstrating how to use the cargo_bin! macro to get the path to a tool binary and then execute it using Command. ```rust Command::new(cargo_bin!("my-tool")).assert().success(); ``` -------------------------------- ### file! Macro Examples Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Examples of using the file! macro to load snapshots from explicit paths, auto-generated filenames, and with forced data formats like Json. ```rust // Explicit path (relative to source file) Assert::new().eq(actual, file!["expected.txt"]); // Auto-generated filename, auto-detected format Assert::new().eq(actual, file![_]); // Auto-generated filename, forced format Assert::new().eq(actual, file![_: Json]); ``` -------------------------------- ### str![] Macro Examples Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Provides examples of using the `str![]` macro for simple, multi-line, raw, and empty string literals. Requires importing `snapbox::str`. ```rust use snapbox::str; // Simple string let expected = str!["hello world"]; // Multi-line string let expected = str![[ "line 1 line 2 line 3" ]]; // Raw string literal let expected = str![r#"{"json": "value"}"#]; // Empty let expected = str![]; ``` -------------------------------- ### assert_data_eq! Macro Examples Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Examples demonstrating the usage of assert_data_eq! with string literals and vectors, showcasing wildcard filtering. ```rust assert_data_eq!("hello world", "hello [..]"); assert_data_eq!(vec![1, 2, 3], "[..]\n"); ``` -------------------------------- ### Create a new command builder Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `Command::new` to start building a command for a specified program. This is the entry point for most command-line testing scenarios. ```rust pub fn new(program: impl AsRef) -> Self ``` ```rust use snapbox::cmd::Command; Command::new("echo") .arg("hello") .assert() .success(); ``` -------------------------------- ### Manual Color Control Examples Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md Provides examples of how to manually control color output in tests using environment variables. `CLICOLOR_FORCE=1` forces colors, while `NO_COLOR=1` forces no colors. ```shell CLICOLOR_FORCE=1 cargo test # Force colors NO_COLOR=1 cargo test # Force no colors ``` -------------------------------- ### str! Macro Example Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Example showing how to declare an inline JSON snapshot using the str! macro and assert its equality with actual data after converting it to JSON. ```rust let expected = str![[r#"{"key": "value"}"#]]; assert_data_eq!(actual, expected.is_json()); ``` -------------------------------- ### file![] Macro Examples Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Demonstrates using the `file![]` macro with explicit paths, forced formats, and auto-generated paths based on function names. Requires importing `snapbox::file`. ```rust use snapbox::file; // Relative path let expected = file!["../expected/output.txt"]; // Force format let expected = file!["output: Json"]; // Auto-generated by function name // Function: test_my_feature() → tests/snapshots/test_my_feature.txt let expected = file![_]; // Auto-generated with format // Function: test_json() → tests/snapshots/test_json.json let expected = file![_: Json]; ``` -------------------------------- ### Assert::new Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Creates a new assertion builder with default configuration. This is the starting point for most snapshot assertions. ```APIDOC ## Assert::new ### Description Creates a new assertion builder with default configuration. ### Method `new()` ### Returns - `Self`: A new `Assert` instance configured to verify snapshots (fail on mismatch). ``` -------------------------------- ### Inline Snapshot Usage Example Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Demonstrates how to use the Inline and Position types, showing automatic position capture and accessing source data. ```rust use snapbox::Inline; use snapbox::data::Position; // Position is automatically captured by macros let expected = str!["content"]; // Position auto-captured // Access via Data if let Some(source) = data.source() { // Source information available } ``` -------------------------------- ### Mismatch Output Example Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md Illustrates the output when a verification action encounters a mismatch. It shows the expected, actual, and diff content, along with a hint for updating snapshots. ```text ---- test_example stdout ---- thread 'test_example' panicked at ' expected: hello world actual: hello there diff: hello [removed: world] [added: there] Update with SNAPSHOTS=overwrite ' ``` -------------------------------- ### Test Completeness of Help Documentation Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Verifies that the help output of a command-line application contains expected sections like USAGE, OPTIONS, and EXAMPLES. Ensures comprehensive help information is provided. ```rust use snapbox::cmd::Command; #[test] #[cfg(feature = "cmd")] fn test_help_is_complete() { let help = Command::new(snapbox::cargo_bin!("myapp")) .arg("--help") .assert() .success(); // Verify key sections are present help.stdout_matches("[..] USAGE [..]"); help.stdout_matches("[..] OPTIONS [..]"); help.stdout_matches("[..] EXAMPLES [..]"); } ``` -------------------------------- ### Snapbox Redactions Builder Example Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Demonstrates how to create and use the Redactions builder to insert and apply placeholder replacements for sensitive data in strings. ```rust let mut redactions = Redactions::new(); redactions.insert("[HASH]", "abc123def456").unwrap(); redactions.insert("[EXE]", std::env::consts::EXE_SUFFIX).unwrap(); let filtered = redactions.redact("Process hash=abc123def456 exe.exe"); // → "Process hash=[HASH] exe[EXE]" ``` -------------------------------- ### Setup Mutable Temporary Directory Root Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Use DirRoot::mutable_temp() to create an auto-cleaning temporary directory for tests. Errors during creation are propagated. ```rust use snapbox::dir::DirRoot; let root = DirRoot::mutable_temp()?; // Creates auto-cleaning temp directory // Errors propagated (permission issues, etc.) // Get path if let Some(path) = root.path() { println!("Working in: {}", path.display()); } // Clean up (optional, happens automatically on drop) root.close()?; ``` -------------------------------- ### Setup No Sandboxing Directory Root Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Use DirRoot::none() for tests that do not require directory isolation. Assertions are disabled in this mode. ```rust use snapbox::dir::DirRoot; let root = DirRoot::none(); // No directory isolation, assertions disabled ``` -------------------------------- ### Create a new Assert instance Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md Initializes a new Assert struct with default settings. This is the starting point for configuring snapshot assertions. ```rust use snapbox::Assert; let assert = Assert::new(); ``` -------------------------------- ### Auto-Path Generation Example Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Shows how `file![_]` generates snapshot paths based on module and function names. For multiple assertions in the same function, suffixes are appended. ```rust mod my_module { #[test] fn test_feature() { let expected = file![_]; // → tests/snapshots/my_module__test_feature.txt } } #[test] fn test_multiple() { let exp1 = file![_]; // → ...@1.txt let exp2 = file![_]; // → ...@2.txt let exp3 = file![_]; // → ...@3.txt } ``` -------------------------------- ### ToDebug Trait Example Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Demonstrates how to use the to_debug method to capture the debug representation of a vector. ```rust use snapbox::ToDebug as _; let value = vec![1, 2, 3]; let snapshot = value.to_debug(); // Captures "[\n 1,\n 2,\n 3,\n]\n" ``` -------------------------------- ### Execute command and get assertion builder Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Call `assert` on a configured `Command` to execute it and obtain an `OutputAssert` instance for verifying the results. ```rust pub fn assert(self) -> OutputAssert ``` ```rust OutputAssert for verifying command output ``` -------------------------------- ### Setup Immutable Directory Root Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Use DirRoot::immutable() to create a read-only reference to an existing directory. This is useful for tests that need to inspect a fixed directory structure. ```rust use snapbox::dir::DirRoot; use std::path::Path; let root = DirRoot::immutable(Path::new("/path/to/existing")); // Read-only reference to existing directory ``` -------------------------------- ### Snapbox Cargo.toml Dependencies Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Examples of how to add Snapbox as a dependency in your Cargo.toml file, including default, specific versions with features, latest from Git, optional dependencies, and dev dependencies. ```toml # Default (color-auto, diff) snapbox = "1.2" ``` ```toml # Specific version with features snapbox = { version = "1.2", features = ["json", "cmd"] } ``` ```toml # Latest version snapbox = { git = "https://github.com/assert-rs/snapbox" } ``` ```toml # With optional dependency snapbox = { version = "1.2", features = ["regex"], optional = true } ``` ```toml # As dev dependency (common) [dev-dependencies] snapbox = "1.2" ``` -------------------------------- ### Example: Uppercase Filter Implementation Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Provides a concrete implementation of the `Filter` trait to convert text data to uppercase. Demonstrates usage with sample data. ```rust use snapbox::filter::Filter; use snapbox::Data; struct UppercaseFilter; impl Filter for UppercaseFilter { fn filter(&self, data: Data) -> Data { let text = data.render() .unwrap_or_default() .to_uppercase(); Data::text(text) } } // Usage let data = Data::text("hello"); let filtered = UppercaseFilter.filter(data); assert_eq!(filtered.render().unwrap(), "HELLO"); ``` -------------------------------- ### Setup Mutable Directory Root at Specific Path Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Use DirRoot::mutable_at() to create or clear a directory at a specified path. This is useful for tests requiring a predictable directory location. ```rust use snapbox::dir::DirRoot; use std::path::Path; let root = DirRoot::mutable_at(Path::new("./test_dir"))?; // Creates or clears directory at path ``` -------------------------------- ### Command Failure and Environment Variable Test Source: https://github.com/assert-rs/snapbox/blob/main/examples/demo_trycmd/README.md Tests command failure scenarios and passing environment variables to the command. The first example shows an error message for missing arguments. ```console $ simple ? 1 Must supply exactly one argument. $ GOODBYE=true simple World Goodbye World! ``` -------------------------------- ### Test CLI Help Output with Snapbox Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/README.md Use this pattern to verify the help output of a command-line application. It spawns the specified binary and asserts that its standard output matches the expected pattern. ```rust Command::new(snapbox::cargo_bin!("myapp")) .arg("--help") .assert() .success() .stdout_matches("Usage [..]"); ``` -------------------------------- ### Create Binary Data Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Shows how to create Data instances from binary content. ```rust let data = Data::binary(b"binary content".to_vec()); let data = Data::binary(&b"binary"[..]); ``` -------------------------------- ### Testing Help and Version Flags Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Verify the output of standard `--help` and `--version` flags for your command-line application. Uses `snapbox::cargo_bin!` to locate the executable. ```rust use snapbox::cmd::Command; // Help flag Command::new(snapbox::cargo_bin!("myapp")) .arg("--help") .assert() .success() .stdout_matches("Usage: myapp [..]"); // Version flag Command::new(snapbox::cargo_bin!("myapp")) .arg("--version") .assert() .success() .stdout_matches("myapp [..]"); ``` -------------------------------- ### Running Tests with Snapshot Actions Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Demonstrates how to run tests with different snapshot behaviors using environment variables. ```bash # Normal mode (verify snapshots) cargo test # Update snapshots SNAPSHOTS=overwrite cargo test # Skip tests SNAPSHOTS=skip cargo test # Ignore failures SNAPSHOTS=ignore cargo test ``` -------------------------------- ### Create Snapshots with Macros Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Illustrates using macros like `str!` and `file!` for inline and external snapshots. ```rust use snapbox::{str, file, IntoData}; // Inline snapshot let expected = str!["expected content"]; let expected = str![[r#"{"json": "value"}"#]]; // External file snapshot let expected = file!["expected.txt"]; let expected = file!["output.json": Json]; // Auto-generated filename let expected = file![_]; let expected = file![_: Json]; ``` -------------------------------- ### Get Data Format Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `Data::format` to retrieve the current `DataFormat` of the instance. ```rust pub fn format(&self) -> DataFormat ``` -------------------------------- ### Create Project Structure with DirFixture Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Demonstrates how to define a project structure using the `DirFixture` trait and write it to a temporary directory. Useful for setting up test environments. ```rust use snapbox::dir::{DirRoot, DirFixture}; pub struct ProjectStructure; impl DirFixture for ProjectStructure { fn write_to_path(&self, path: &std::path::Path) -> snapbox::assert::Result<()> { std::fs::create_dir(path.join("src"))?; std::fs::write(path.join("src/lib.rs"), "pub fn hello() {}")?; std::fs::create_dir(path.join("tests"))?; std::fs::write(path.join("tests/integration.rs"), "#[test]\nfn test() {}")?; Ok(()) } } #[test] #[cfg(feature = "dir")] fn test_project_generation() -> snapbox::assert::Result<()> { let root = DirRoot::mutable_temp()? .with_template(&ProjectStructure)?; let path = root.path().unwrap(); assert!(path.join("src/lib.rs").exists()); assert!(path.join("tests/integration.rs").exists()); Ok(()) } ``` -------------------------------- ### Get Debug Representation of Data Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Shows how to obtain the debug representation of a value and use it for assertions. ```rust use snapbox::{ToDebug, assert_data_eq}; let value = vec![1, 2, 3]; let debug_repr = value.to_debug(); // Equivalent to: format!("{:#?}\n", value) assert_data_eq!(value.to_debug(), "[..]\n"); ``` -------------------------------- ### Creating Data with Source Information Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Illustrates creating `Data` instances with and without source tracking. Inline macros like `str!` capture source location, while `Data::text` does not. ```rust use snapbox::Data; use std::path::Path; // Creating with source (file) let data = Data::read_from(Path::new("expected.txt"), None); // Has source information // Creating from inline let data = str!["content"]; // Source points to source file location // Creating from string literal let data = Data::text("content"); // No source (will not be writable) ``` -------------------------------- ### Get Data Source Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `Data::source` to retrieve the `DataSource` location, which can be a file path or inline source. ```rust pub fn source(&self) -> Option<&DataSource> ``` -------------------------------- ### Get the DirRoot path Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `DirRoot::path()` to retrieve the `Option<&Path>` representing the directory's path if it has been set. ```rust pub fn path(&self) -> Option<&std::path::Path> ``` -------------------------------- ### cargo_bin!(name) Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Macro to get the path to an integration test binary. This is useful for invoking binaries built as part of your crate during testing. ```APIDOC ## cargo_bin!(name) ### Description Get the path to an integration test binary. This macro is used to reference binaries compiled as part of your crate, typically for use in integration tests. ### Usage ```rust let binary_path = cargo_bin!("my-tool"); ``` ### Output `&'static std::path::Path` ### Example ```rust use snapbox::cargo_bin; use std::process::Command; // Assuming a binary target named 'my-tool' exists // Command::new(cargo_bin!("my-tool")).assert().success(); ``` ``` -------------------------------- ### Compare Data with Different Formats Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Demonstrates setting a storage format and a comparison format for data. ```rust use snapbox::{IntoData, data::DataFormat}; // Store as JSON Lines for readability // Compare as JSON for flexibility let data = str![[ "{\"type\": \"log\"}" "{\"type\": \"error\"}" ]].is(DataFormat::JsonLines) .against(DataFormat::Json); ``` -------------------------------- ### DirRoot::with_template Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Initializes a directory context from a provided template fixture, setting up initial file structures. ```APIDOC ## DirRoot::with_template ### Description Initializes the directory from a template. ### Method Rust function call ### Parameters #### Request Body - **self** (`DirRoot`) - Required - The current `DirRoot` instance. - **template** (`&F`) - Required - A reference to a `DirFixture` implementing the template structure. ``` -------------------------------- ### Initialize DirRoot from a template Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `DirRoot::with_template()` to initialize a directory from a template fixture. This allows setting up a directory structure based on a predefined template. Requires the `dir` feature. ```rust #[cfg(feature = "dir")] pub fn with_template(self, template: &F) -> Result where F: crate::dir::DirFixture + ?Sized ``` -------------------------------- ### Minimal Snapbox Dependencies Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Use this configuration for a library with minimal dependencies, excluding features like colors, diffs, JSON, commands, and directory testing. ```toml [dependencies] snapbox = { version = "1.2", default-features = false } ``` -------------------------------- ### Full-Featured Snapbox Dependencies Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Includes all features except for doc generation and external tool building. This configuration is suitable for comprehensive testing needs. ```toml [dependencies] snapbox = { version = "1.2", features = [ "color-auto", "diff", "json", "term-svg", "dir", "cmd", "regex", "detect-encoding", "debug" ] } ``` -------------------------------- ### Reading Data with Source Information Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Demonstrates reading data from a file path and writing it back to its source if available. Requires importing `snapbox::Data` and `std::path::Path`. ```rust use snapbox::Data; use std::path::Path; let data = Data::read_from(Path::new("snapshot.json"), None); if let Some(source) = data.source() { // Source is present (file-based) // Used for writing snapshots back data.write_to(source)?; } ``` -------------------------------- ### Command::new Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Creates a new command builder for a specified program. This is the entry point for defining a command to be executed and asserted. ```APIDOC ## Command::new ### Description Create a command builder for a specified program. ### Method `new` ### Parameters - `program` (impl AsRef) - The program to execute. ### Example ```rust use snapbox::cmd::Command; Command::new("echo") .arg("hello") .assert() .success(); ``` ``` -------------------------------- ### Render Data to String Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `Data::render` to get the string representation of the data if available (Text, JSON, TermSvg). Returns None for Binary or Error types. ```rust pub fn render(&self) -> Option ``` -------------------------------- ### Command Composition with Piped Output Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Simulate command piping by capturing the output of one command and using it as the input for another. Demonstrates how to chain commands logically. ```rust use snapbox::cmd::Command; // Pipe-like patterns let output1 = Command::new("echo") .arg("data") .assert() .success(); Command::new("cat") .stdin(output1.stdout.clone()) .assert() .success(); ``` -------------------------------- ### Test with Temporary Directory using Snapbox Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/README.md Utilize `DirRoot::mutable_temp()` to create a temporary directory for testing file system interactions. Populate the directory and then assert its contents against expected patterns. ```rust let root = DirRoot::mutable_temp()?; // ... populate and test assert_subset_matches("expected", root.path().unwrap()); ``` -------------------------------- ### Creating Snapbox Command from Standard Command Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Convert a standard library `std::process::Command` into a Snapbox `Command` for enhanced assertion capabilities. Useful for piping stdin. ```rust use snapbox::cmd::Command; use std::process::Command as StdCommand; let std_cmd = StdCommand::new("cat"); let cmd = Command::from_std(std_cmd); cmd.stdin("input data") .assert() .success(); ``` -------------------------------- ### Snapbox Dependencies for CLI Testing Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Configure Snapbox with features for testing CLI applications, including command execution, output assertion, and colored diffs. ```toml [dependencies] snapbox = { version = "1.2", features = ["cmd", "color-auto", "diff"] } ``` -------------------------------- ### Directory Pattern Wildcards Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Illustrates the use of wildcards for matching lines, characters, and platform-specific file extensions within directory patterns. ```shell # Line wildcard (matches any lines) line 1 ... line 3 # Character wildcard (matches characters within line) version: [..] # Platform-specific program[EXE] # Path normalization (automatic) path\to\file → path/to/file ``` -------------------------------- ### Verify Action Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md The default action, `verify`, runs assertions normally, fails on mismatch, displays a colored diff, and suggests an update command. ```bash SNAPSHOTS=verify cargo test ``` -------------------------------- ### Create a command for a cargo-built binary Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `Command::cargo_bin` to easily reference binaries built by Cargo. This method panics if the binary is not found in the target directory. ```rust pub fn cargo_bin(name: &str) -> Self ``` ```rust Command::cargo_bin("my-cli") .arg("--help") .assert() .stdout_eq("..."); ``` -------------------------------- ### Format Inference from File Extensions Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Demonstrates how Snapbox infers data formats (like JSON, Text, JsonLines) based on file extensions. Shows handling of single, multiple, and unrecognized extensions. ```rust use snapbox::data::DataFormat; use std::path::Path; // Single extension DataFormat::from(Path::new("data.json")); // Json DataFormat::from(Path::new("data.txt")); // Text DataFormat::from(Path::new("data.jsonl")); // JsonLines // Multiple extensions (processed right to left) DataFormat::from(Path::new("data.stdout.json")); // Json DataFormat::from(Path::new("snapshot.term.svg")); // TermSvg // No recognized extension DataFormat::from(Path::new("data.custom")); // Text (default) DataFormat::from(Path::new(".env")); // Text // Hidden files with extensions DataFormat::from(Path::new(".config.json")); // Json ``` -------------------------------- ### Test Basic Command Help Output Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Asserts that a command's help output matches an expected string. Requires the 'cmd' feature. ```rust use snapbox::cmd::Command; #[test] #[cfg(feature = "cmd")] fn test_help_output() { Command::new(snapbox::cargo_bin!("myapp")) .arg("--help") .assert() .success() .stdout_matches("Usage: myapp [..]"); } ``` -------------------------------- ### Directory Pattern File Type Matching Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Demonstrates how Snapbox's `FileType` enum can be used to differentiate between regular files, directories, and symlinks. ```rust use snapbox::dir::FileType; // Different types are detected: // - Regular files // - Directories // - Symlinks (on supported platforms) ``` -------------------------------- ### Directory Fixtures with DirRoot Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Use DirRoot for sandboxing and assert_subset_matches for comparing directory trees. Requires the 'dir' feature. ```rust #[cfg(feature = "dir")] { use snapbox::dir::DirRoot; let root = DirRoot::mutable_temp()?; // ... populate directory snapbox::assert_subset_matches( "tests/expected", root.path().unwrap() ); } ``` -------------------------------- ### Wrap a standard std::process::Command Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `Command::from_std` to integrate existing `std::process::Command` instances with snapbox assertions. ```rust pub fn from_std(cmd: std::process::Command) -> Self ``` -------------------------------- ### Snapbox Dependencies for API Testing Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Configure Snapbox with features for testing JSON APIs and serialization, including JSON comparison, pretty output, and diffs. ```toml [dependencies] snapbox = { version = "1.2", features = ["json", "color-auto", "diff"] } ``` -------------------------------- ### Create Text Data Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Demonstrates creating Data instances from strings, including multi-line strings. ```rust use snapbox::{Data, IntoData}; // Direct creation let data = Data::text("hello world"); // From IntoData trait let data: Data = "hello world".into_data(); // From String let data = Data::text(String::from("hello")); // Multi-line strings let data = Data::text("line 1\nline 2\nline 3"); ``` -------------------------------- ### Basic Command Execution Test Source: https://github.com/assert-rs/snapbox/blob/main/examples/demo_trycmd/README.md Tests the output of a simple command with different arguments. Ensure the binary is available in the PATH. ```console $ simple World Hello World! $ simple Ferris Hello Ferris! ``` -------------------------------- ### Create a no-op DirRoot Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `DirRoot::none()` to create a directory root that performs no operations, effectively disabling sandboxing. ```rust pub fn none() -> Self ``` -------------------------------- ### Standard Snapshot Testing Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md Use this pattern for basic snapshot testing where you compare actual output against a file snapshot. Ensure the SNAPSHOTS environment variable is set for action. ```rust use snapbox::Assert; #[test] fn test_standard() { Assert::new() .action_env("SNAPSHOTS") .eq(actual, file![_]); } ``` -------------------------------- ### Conditional Testing Based on Target OS Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Demonstrates how to perform platform-specific assertions using `#[cfg]` attributes. Compares output against expected values for different operating systems. ```rust use snapbox::assert_data_eq; #[test] fn test_platform_specific() { let output = get_platform_info(); #[cfg(target_os = "windows")] let expected = "Windows"; #[cfg(target_os = "unix")] let expected = "Unix"; assert_data_eq!(output, expected); } ``` -------------------------------- ### Enable Cmd Feature for Snapbox Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Add this to your Cargo.toml to enable command execution and output verification features. ```toml [dependencies] snapbox = { version = "1.2", features = ["cmd"] } ``` -------------------------------- ### Custom Snapshot Paths Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/README.md Define custom paths for storing snapshots using the `snapbox::file!` macro. Paths are relative to the source file. ```rust snapbox::file!["custom/path.txt"] # Relative to source file snapbox::file!["../expected.json"] ``` -------------------------------- ### Basic Command Execution and Assertion Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Execute simple commands and assert their success, stdout content, or stdout patterns. ```rust use snapbox::cmd::Command; // Simple success check Command::new("echo") .arg("hello") .assert() .success(); // Check stdout Command::new("echo") .arg("hello") .assert() .stdout_eq("hello\n"); // Pattern matching on stdout Command::new("echo") .arg("hello world") .assert() .stdout_matches("hello [..]"); ``` -------------------------------- ### Initialize trycmd TestCases in Rust Source: https://github.com/assert-rs/snapbox/blob/main/crates/trycmd/README.md Create a test function in tests/cli_tests.rs to define the test case sources. ```rust #[test] fn cli_tests() { trycmd::TestCases::new() .case("tests/cmd/*.toml") .case("README.md"); } ``` -------------------------------- ### Conditional Assertions Based on Environment Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md Illustrates how to perform assertions conditionally, such as based on the operating system. This is useful for testing platform-specific behavior. ```rust use snapbox::Assert; #[test] fn test_conditional() { let actual = compute_result(); let expected = if cfg!(unix) { "unix-output" } else { "windows-output" }; Assert::new() .normalize_paths(true) .eq(actual, expected); } ``` -------------------------------- ### Create JSON Data Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Illustrates creating Data instances from JSON, including auto-serialization. ```rust use snapbox::{Data, IntoData}; let json = serde_json::json!({"key": "value"}); let data = Data::json(json); // Auto-serialize from Serialize types use snapbox::IntoJson as _; #[derive(serde::Serialize)] struct Point { x: i32, y: i32 } let data = Point { x: 10, y: 20 }.into_json(); ``` -------------------------------- ### Enable Document-Features Feature for Snapbox Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Add this to your Cargo.toml to include feature documentation in rustdoc. ```toml [dependencies] snapbox = { version = "1.2", features = ["document-features"] } ``` -------------------------------- ### Command Execution and Assertion Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Use the Command struct to spawn processes, assert success, and verify stdout. Requires the 'cmd' feature. ```rust #[cfg(feature = "cmd")] { use snapbox::cmd::Command; Command::new("echo") .arg("hello") .assert() .success() .stdout_eq("hello\n"); } ``` -------------------------------- ### Command Methods Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/INDEX.md Methods for building and executing commands with assertions. ```APIDOC ## Command Methods ### Description Methods for building and executing commands with assertions. ### Methods - `Command::new(prog)`: Create a command builder. - `Command::cargo_bin(name)`: Specify a cargo binary. - `Command::arg(arg)`: Add a single argument. - `Command::args(args)`: Add multiple arguments. - `Command::env(key, val)`: Set an environment variable. - `Command::current_dir(path)`: Set the working directory. - `Command::stdin(data)`: Provide standard input. - `Command::assert()`: Execute the command and perform assertions. ``` -------------------------------- ### Running Tests with Different Snapshot Actions Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md Demonstrates how to run cargo tests with various `SNAPSHOTS` environment variable values to control assertion behavior: verify (default), overwrite, skip, and ignore. ```bash # Verify (default): fail on mismatch cargo test # Overwrite: update snapshots SNAPSHOTS=overwrite cargo test # Skip: don't run tests SNAPSHOTS=skip cargo test # Ignore: run but don't fail SNAPSHOTS=ignore cargo test ``` -------------------------------- ### Assertion Failure: Full Configuration Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md Demonstrates a fully configured assertion with both `action_env` set and a file source for the expected value. This configuration will show the diff and suggest the correct environment variable for updating snapshots. ```rust use snapbox::Assert; Assert::new() .action_env("SNAPSHOTS") .eq(actual, file!["expected.txt"]); // If fails: // - Shows diff // - Suggests: SNAPSHOTS=overwrite ``` -------------------------------- ### Convert Data Formats Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Demonstrates converting data between binary, text, and JSON formats. Invalid conversions to JSON will retain the original Text format. ```rust use snapbox::{Data, data::DataFormat}; // Binary → Text let binary = Data::binary(b"hello".to_vec()); let text = binary.coerce_to(DataFormat::Text); // Text → JSON (if valid) let text = Data::text(r#"{"a": 1}"#); let json = text.coerce_to(DataFormat::Json); assert_eq!(json.format(), DataFormat::Json); // Invalid conversion let text = Data::text("not json"); let json = text.coerce_to(DataFormat::Json); assert_eq!(json.format(), DataFormat::Text); // Remains Text ``` -------------------------------- ### Enable Dir Feature for Snapbox Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Add this to your Cargo.toml to enable directory fixtures and recursive comparison features. ```toml [dependencies] snapbox = { version = "1.2", features = ["dir"] } ``` -------------------------------- ### Directory Comparison: Exact Match Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Use assert_subset_eq to compare two directories for an exact match. This is useful for verifying generated files, directory structures, and file content. ```rust use snapbox::assert_subset_eq; // Compare two directories for exact match assert_subset_eq( "tests/expected/output", "tests/actual/output" ); // Useful for: // - Verifying generated files // - Checking directory structure // - File content validation ``` -------------------------------- ### Command::assert Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Executes the configured command and returns an `OutputAssert` builder. This builder is used to make assertions about the command's execution and output. ```APIDOC ## Command::assert ### Description Execute the command and return assertion builder. ### Method `assert` ### Returns `OutputAssert` for verifying command output. ``` -------------------------------- ### Platform-Specific Wildcard Matching Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Use `[EXE]` to match `.exe` on Windows and an empty string on Unix-like systems. This allows for platform-agnostic assertions. ```Rust // [EXE] matches .exe on Windows, empty string on Unix #[cfg(target_os = "windows")] let program = "program.exe"; #[cfg(not(target_os = "windows"))] let program = "program"; let expected = format!("running program[EXE]"); assert_data_eq!(actual, expected); ``` -------------------------------- ### Assertions with Fixture Integration Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/assert-configuration.md Shows how to integrate Snapbox assertions with fixtures, loading test data from files and comparing it against expected output. Useful for testing file processing logic. ```rust use snapbox::Assert; #[test] fn test_with_fixture() { let fixture = load_fixture("test-data"); let result = process(&fixture); Assert::new() .action_env("SNAPSHOTS") .eq(result, file!["expected_output.json"]) } ``` -------------------------------- ### Create Binary Data Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `Data::binary` to create a Data instance from a byte vector. ```rust pub fn binary(raw: impl Into>) -> Self ``` -------------------------------- ### Directory Comparison: Pattern Matching Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Use assert_subset_matches for directory comparison with pattern wildcards. Supports '...', '[..]', '[EXE]', and path normalization. ```rust use snapbox::assert_subset_matches; // Compare with pattern wildcards assert_subset_matches( "tests/patterns/expected", "tests/actual/output" ); // Pattern syntax: // - ... (on own line) → any number of lines // - [..] (in line) → any characters // - [EXE] → executable extension // - \ → / (path normalization) ``` -------------------------------- ### Define and Use a Directory Fixture Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Implement the DirFixture trait to define custom directory structures. Use with DirRoot::with_template() to initialize a directory with the fixture's content. ```rust use snapbox::dir::{DirRoot, DirFixture}; pub struct MyFixture; impl DirFixture for MyFixture { fn write_to_path(&self, path: &std::path::Path) -> snapbox::assert::Result<()> { std::fs::write( path.join("file.txt"), "content" )?; std::fs::create_dir(path.join("subdir"))?; std::fs::write( path.join("subdir/nested.txt"), "nested content" )?; Ok(()) } } // Initialize directory with fixture let root = DirRoot::mutable_temp()? .with_template(&MyFixture)?; // root.path() now contains: // - file.txt // - subdir/nested.txt ``` -------------------------------- ### Snapbox All Features Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Enables all available features for maximum functionality. Use when all optional features are required. ```toml [dependencies] snapbox = { version = "1.2", features = ["full"] } ``` -------------------------------- ### Snapbox No Features Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Disables all default features. Use for minimal builds or when specific features are manually enabled. ```toml [dependencies] snapbox = { version = "1.2", default-features = false } ``` -------------------------------- ### DirRoot::none Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Creates a no-op directory root, effectively disabling sandboxing for filesystem operations. ```APIDOC ## DirRoot::none ### Description Creates a no-op directory root (sandboxing disabled). ### Method Rust function call ### Parameters None ### Returns - `Self`: A new `DirRoot` instance configured for no-op operations. ``` -------------------------------- ### Data::binary Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Creates a Data instance from raw binary data. Use this for non-textual snapshots. ```APIDOC ## Data::binary ### Description Creates a Data instance from raw binary data. Use this for non-textual snapshots. ### Method `Data::binary(raw: impl Into>) -> Self` ``` -------------------------------- ### Command::args Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Adds multiple arguments to the command. This is a convenient way to add several arguments at once. ```APIDOC ## Command::args ### Description Add multiple arguments. ### Method `args` ### Parameters - `args` (impl IntoIterator>) - An iterator of arguments to add. ``` -------------------------------- ### Read Data from Files Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/data-and-filters.md Shows how to read data from files, with auto-detection or forced format, and a fallible version. ```rust use snapbox::Data; use std::path::Path; // Auto-detect format from extension let data = Data::read_from(Path::new("expected.json"), None); // Force specific format use snapbox::data::DataFormat; let data = Data::read_from( Path::new("output.txt"), Some(DataFormat::Text) ); // Fallible version let data = Data::try_read_from( Path::new("snapshot.json"), Some(DataFormat::Json) )?; ``` -------------------------------- ### Enable Detect-Encoding Feature for Snapbox Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/feature-flags-and-patterns.md Add this to your Cargo.toml to enable smart binary file detection and encoding inspection. ```toml [dependencies] snapbox = { version = "1.2", features = ["detect-encoding"] } ``` -------------------------------- ### Command::envs Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Sets multiple environment variables for the command. This is useful for configuring the environment for the spawned process. ```APIDOC ## Command::envs ### Description Set multiple environment variables. ### Method `envs` ### Parameters - `vars` (impl IntoIterator) - An iterator of key-value pairs for environment variables. ``` -------------------------------- ### Data::format Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Returns the current DataFormat of the instance (e.g., Text, Binary, Json). ```APIDOC ## Data::format ### Description Returns the current DataFormat of the instance (e.g., Text, Binary, Json). ### Method `Data::format(&self) -> DataFormat` ### Returns One of: `Text`, `Binary`, `Json`, `JsonLines`, `TermSvg`, or `Error` ``` -------------------------------- ### CLI Command Output Assertion Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/README.md Test command-line applications using `snapbox::cmd::Command`. Assert success and match standard output against a snapshot. ```rust use snapbox::cmd::Command; #[test] fn test_command() { Command::new(snapbox::cargo_bin!("myapp")) .arg("--help") .assert() .success() .stdout_matches("Usage [..]"); } ``` -------------------------------- ### Auto-Detect DataFormat from Path Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/types-and-formats.md Infers the DataFormat from a file path based on its extension. Unknown extensions default to the Text format. ```rust use snapbox::data::DataFormat; use std::path::Path; let format = DataFormat::from(Path::new("output.json")); assert_eq!(format, DataFormat::Json); let format = DataFormat::from(Path::new("log.jsonl")); assert_eq!(format, DataFormat::JsonLines); let format = DataFormat::from(Path::new("result.txt")); assert_eq!(format, DataFormat::Text); // Unknown extension defaults to Text let format = DataFormat::from(Path::new("data.unknown")); assert_eq!(format, DataFormat::Text); ``` -------------------------------- ### Test Basic Command Version Output Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Asserts that a command's version output matches an expected string. Requires the 'cmd' feature. ```rust use snapbox::cmd::Command; #[test] #[cfg(feature = "cmd")] fn test_version() { Command::new(snapbox::cargo_bin!("myapp")) .arg("--version") .assert() .success() .stdout_matches("myapp [..]"); } ``` -------------------------------- ### Test Command with Standard Input Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Tests a command that reads from standard input and produces a specific standard output. Requires the 'cmd' feature. ```rust use snapbox::cmd::Command; #[test] #[cfg(feature = "cmd")] fn test_cat_with_stdin() { Command::new("cat") .stdin("input data\nmore input") .assert() .success() .stdout_eq("input data\nmore input"); } ``` -------------------------------- ### Try Read Data from File Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Use `Data::try_read_from` for a non-panicking version of `read_from` that returns a Result. ```rust pub fn try_read_from( path: &std::path::Path, data_format: Option, ) -> crate::assert::Result ``` -------------------------------- ### Setting the Working Directory for Commands Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Specify a different current working directory for command execution. Supports absolute paths and relative paths. ```rust use snapbox::cmd::Command; use std::path::Path; // Run command in different directory Command::new("pwd") .current_dir("/tmp") .assert() .stdout_matches("/tmp"); // Run in source directory Command::new("ls") .current_dir("src") .assert() .success(); ``` -------------------------------- ### Simulating Interactive Input via Stdin Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Provide multi-line input to a command's standard input using the `stdin` method. Useful for testing interactive scripts or prompts. ```rust use snapbox::cmd::Command; // Multiple lines via stdin let input = "option1\n\nconfirm\n"; Command::new("bash") .arg("script.sh") .stdin(input) .assert() .success() .stdout_matches("[..]"); ``` -------------------------------- ### Test Command with Standard Output Equality Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Tests a command that produces a specific standard output. Uses `stdout_eq` for exact matching. Requires the 'cmd' feature. ```rust use snapbox::cmd::Command; #[test] #[cfg(feature = "cmd")] fn test_echo() { Command::new("echo") .arg("hello world") .assert() .success() .stdout_eq("hello world\n"); } ``` -------------------------------- ### Test with JSON Lines Format-Specific Snapshot Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Creates a snapshot file with a .jsonl extension for JSON Lines data. Requires the 'json' feature and the SNAPSHOTS environment variable for updates. ```rust use snapbox::Assert; use snapbox::data::DataFormat; #[test] #[cfg(feature = "json")] fn test_jsonlines_snapshot() { let output = stream_json_objects(); Assert::new() .action_env("SNAPSHOTS") .eq(output, snapbox::file![_: JsonLines]); // Creates .jsonl file } // Creates: tests/snapshots/test_jsonlines_snapshot.jsonl ``` -------------------------------- ### Command::stdin Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/snapbox-api-reference.md Provides standard input (stdin) to the command. This is useful for commands that expect input from stdin. ```APIDOC ## Command::stdin ### Description Provide stdin input. ### Method `stdin` ### Parameters - `stream` (impl IntoData) - The data to be provided as stdin. ### Example ```rust Command::new("cat") .stdin("Hello from stdin") .assert() .stdout_eq("Hello from stdin"); ``` ``` -------------------------------- ### Test with JSON Format-Specific Snapshot Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/testing-patterns-and-examples.md Creates a snapshot file with a .json extension for JSON data. Requires the 'json' feature and the SNAPSHOTS environment variable for updates. ```rust use snapbox::Assert; use snapbox::data::DataFormat; #[test] #[cfg(feature = "json")] fn test_json_snapshot() { let output = get_json_data(); Assert::new() .action_env("SNAPSHOTS") .eq(output, snapbox::file![_: Json]); // Creates .json file } // Creates: tests/snapshots/test_json_snapshot.json ``` -------------------------------- ### Verifying Environment-Specific Command Output Source: https://github.com/assert-rs/snapbox/blob/main/_autodocs/command-and-directory-testing.md Test command output that might vary based on the environment, such as version strings. Use pattern matching to allow for minor variations. ```rust use snapbox::cmd::Command; let output = Command::new("rustc") .arg("--version") .assert() .success() .stdout_matches("rustc [..]"); // Works across different rustc versions/installations ```