| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
use std::ffi::OsString; |
| 7 |
use uufuzz::{compare_result, generate_and_run_uumain, run_gnu_cmd}; |
| 8 |
|
| 9 |
// Mock echo implementation for demonstration |
| 10 |
fn mock_echo_main(args: std::vec::IntoIter<OsString>) -> i32 { |
| 11 |
let args: Vec<OsString> = args.collect(); |
| 12 |
|
| 13 |
// Skip the program name (first argument) |
| 14 |
for (i, arg) in args.iter().skip(1).enumerate() { |
| 15 |
if i > 0 { |
| 16 |
print!(" "); |
| 17 |
} |
| 18 |
print!("{}", arg.to_string_lossy()); |
| 19 |
} |
| 20 |
println!(); |
| 21 |
0 |
| 22 |
} |
| 23 |
|
| 24 |
fn main() { |
| 25 |
println!("=== Basic uufuzz Example ==="); |
| 26 |
|
| 27 |
// Test against GNU implementation |
| 28 |
let args = vec![ |
| 29 |
OsString::from("echo"), |
| 30 |
OsString::from("hello"), |
| 31 |
OsString::from("world"), |
| 32 |
]; |
| 33 |
|
| 34 |
println!("Running mock echo implementation..."); |
| 35 |
let rust_result = generate_and_run_uumain(&args, mock_echo_main, None); |
| 36 |
|
| 37 |
println!("Running GNU echo..."); |
| 38 |
match run_gnu_cmd("echo", &args[1..], false, None) { |
| 39 |
Ok(gnu_result) => { |
| 40 |
println!("Comparing results..."); |
| 41 |
compare_result( |
| 42 |
"echo", |
| 43 |
"hello world", |
| 44 |
None, |
| 45 |
&rust_result, |
| 46 |
&gnu_result, |
| 47 |
false, |
| 48 |
); |
| 49 |
} |
| 50 |
Err(error_result) => { |
| 51 |
println!("Failed to run GNU echo: {}", error_result.stderr); |
| 52 |
println!("This is expected if GNU coreutils is not installed"); |
| 53 |
|
| 54 |
// Show what our implementation produced |
| 55 |
println!("\nOur implementation result:"); |
| 56 |
println!("Stdout: '{}'", rust_result.stdout); |
| 57 |
println!("Stderr: '{}'", rust_result.stderr); |
| 58 |
println!("Exit code: {}", rust_result.exit_code); |
| 59 |
} |
| 60 |
} |
| 61 |
} |