command_self_tests.rs (1189B)
1 #![forbid(unsafe_code)] 2 3 use std::process::{Command, Stdio}; 4 5 fn run_self_test(command: &str, expected_stdout: &[u8]) { 6 let directory = tempfile::tempdir().expect("isolated command working directory"); 7 let output = Command::new(env!("CARGO_BIN_EXE_xtask")) 8 .arg(command) 9 .current_dir(directory.path()) 10 .stdin(Stdio::null()) 11 .output() 12 .expect("start the actual xtask binary"); 13 assert!( 14 output.status.success(), 15 "{command} failed: {}", 16 String::from_utf8_lossy(&output.stderr) 17 ); 18 assert_eq!(output.stdout, expected_stdout); 19 assert!(output.stderr.is_empty()); 20 } 21 22 #[test] 23 fn advisory_command_executes_the_complete_offline_snapshot_and_process_suite() { 24 run_self_test("advisory-snapshot-self-test", b""); 25 } 26 27 #[test] 28 fn bounded_process_command_executes_deadline_tree_output_and_environment_faults() { 29 run_self_test( 30 "bounded-process-self-test", 31 b"bounded process self-test: ok\n", 32 ); 33 } 34 35 #[test] 36 fn artifact_command_executes_filesystem_archive_and_preflight_faults() { 37 run_self_test( 38 "safe-artifact-io-self-test", 39 b"safe artifact I/O self-test: ok\n", 40 ); 41 }