use fastshell::sdk::types::Config;
use fastshell::sdk::Fastshell;
fn setup() -> Fastshell {
let dir = std::env::temp_dir().join(format!("fs_sys_smoke_{}", std::process::id()));
let _ = std::fs::remove_dir_all(&dir);
let mut sdk = Fastshell::new();
sdk.init(Config {
sandbox_path: dir.to_string_lossy().to_string(),
python_enabled: false,
allow_subprocess: false,
network_ask_permission: false,
command_timeout_ms: 1_000,
..Default::default()
})
.unwrap();
sdk.write_file("a.txt", "alpha\nbeta\ngamma\n").unwrap();
sdk.write_file("crlf.txt", "x\r\ny\r\n").unwrap();
sdk
}
fn ok(sdk: &Fastshell, cmd: &str) -> String {
let r = sdk.execute(cmd);
assert!(
(0..=255).contains(&r.exit_code),
"cmd {cmd:?} bad exit {}: {}",
r.exit_code,
r.stderr
);
r.stdout
}
#[test]
#[ignore = "heavy: run explicitly or in CI (cargo test -- --ignored)"]
fn sys_info_smoke() {
let s = setup();
for c in [
"uname", "uname -s", "uname -m", "hostname", "whoami", "id", "id -u",
] {
ok(&s, c);
}
ok(&s, "pgrep definitely_not_a_real_process_xyz");
}
#[test]
#[ignore = "heavy: run explicitly or in CI (cargo test -- --ignored)"]
fn compress_and_calendar() {
let s = setup();
assert_eq!(
ok(&s, "bzip2 a.txt && bunzip2 a.txt.bz2 && cat a.txt").trim(),
"alpha\nbeta\ngamma".trim()
);
assert_eq!(
ok(&s, "xz a.txt && unxz a.txt.xz && cat a.txt").trim(),
"alpha\nbeta\ngamma".trim()
);
ok(&s, "bzip2 -k a.txt; zcat a.txt.bz2");
assert!(!ok(&s, "dos2unix crlf.txt && cat crlf.txt").contains('\r'));
ok(&s, "unix2dos crlf.txt");
assert!(ok(&s, "cal 1 2020").contains("January"));
}
#[test]
#[ignore = "heavy: run explicitly or in CI (cargo test -- --ignored)"]
fn hashsum_known_lengths() {
let s = setup();
assert_eq!(
ok(&s, "printf hi | md5sum")
.split_whitespace()
.next()
.unwrap()
.len(),
32
);
assert_eq!(
ok(&s, "printf hi | sha1sum")
.split_whitespace()
.next()
.unwrap()
.len(),
40
);
assert_eq!(
ok(&s, "printf hi | sha256sum")
.split_whitespace()
.next()
.unwrap()
.len(),
64
);
assert_eq!(
ok(&s, "printf hi | sha512sum")
.split_whitespace()
.next()
.unwrap()
.len(),
128
);
}