use inquest::testcommand::TestCommand;
use std::io::Write;
use tempfile::TempDir;
#[test]
fn test_list_tests_parses_subunit_enumeration() {
let temp = TempDir::new().unwrap();
let base_path = temp.path();
let subunit_data: &[u8] = &[
0xb3, 0x29, 0x01, 0x1e, 0x15, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70,
0x6c, 0x65, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x6f, 0x6e, 0x65, 0x63, 0xe2, 0xa6, 0x82,
0xb3, 0x29, 0x01, 0x1e, 0x15, 0x74, 0x65, 0x73, 0x74, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70,
0x6c, 0x65, 0x2e, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x74, 0x77, 0x6f, 0x08, 0x44, 0xaa, 0x15,
];
let script_path = base_path.join("test_script.sh");
let mut script = std::fs::File::create(&script_path).unwrap();
writeln!(script, "#!/bin/bash").unwrap();
write!(script, "printf '").unwrap();
for byte in subunit_data {
write!(script, "\\x{:02x}", byte).unwrap();
}
writeln!(script, "'").unwrap();
drop(script);
#[cfg(unix)]
{
use std::os::unix::fs::PermissionsExt;
let mut perms = std::fs::metadata(&script_path).unwrap().permissions();
perms.set_mode(0o755);
std::fs::set_permissions(&script_path, perms).unwrap();
}
let config_path = base_path.join(".testr.conf");
let mut config = std::fs::File::create(&config_path).unwrap();
writeln!(
config,
"[DEFAULT]\ntest_command=bash test_script.sh\ntest_list_option=--list"
)
.unwrap();
let test_command = TestCommand::from_directory(base_path).unwrap();
let test_ids = test_command.list_tests().unwrap();
assert_eq!(test_ids.len(), 2, "Should parse 2 enumeration events");
assert_eq!(test_ids[0].to_string(), "test.example.test_one");
assert_eq!(test_ids[1].to_string(), "test.example.test_two");
}