ci / check (push) Successful in 5s
- cli: the subcommand is optional; without one, sausage runs ./world and runs init first when ./world is not a world yet (test: cli/tests/cli.rs). So `nix run git+https://gitea.surma.technology/surma/sausage` works. - flake: .#loop without a folder runs bare sausage. - README: mention the bare command and the bare loop.
42 lines
1.6 KiB
Rust
42 lines
1.6 KiB
Rust
//! Tests of the `sausage` command line.
|
|
|
|
use std::path::PathBuf;
|
|
use std::process::{Command, Stdio};
|
|
use std::time::{SystemTime, UNIX_EPOCH};
|
|
|
|
fn empty_dir(label: &str) -> PathBuf {
|
|
let nonce = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos();
|
|
let dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.parent()
|
|
.unwrap()
|
|
.join("target/test-cli")
|
|
.join(format!("{label}-{}-{nonce}", std::process::id()));
|
|
std::fs::create_dir_all(&dir).unwrap();
|
|
dir
|
|
}
|
|
|
|
/// Bare `sausage` (as in `nix run <flake>`) without a world starts `init`
|
|
/// for ./world instead of printing a usage error.
|
|
#[test]
|
|
fn bare_command_without_a_world_starts_init() {
|
|
let dir = empty_dir("bare");
|
|
let output = Command::new(env!("CARGO_BIN_EXE_sausage"))
|
|
.current_dir(&dir)
|
|
.env_remove("SAUSAGE_API")
|
|
.env_remove("SAUSAGE_BASE_URL")
|
|
.env_remove("SAUSAGE_MODEL")
|
|
.env_remove("SAUSAGE_API_TOKEN")
|
|
.stdin(Stdio::null())
|
|
.output()
|
|
.unwrap();
|
|
let stdout = String::from_utf8_lossy(&output.stdout);
|
|
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
// With no answers on stdin, init stops at the first required value.
|
|
assert!(!output.status.success(), "stdout:\n{stdout}\nstderr:\n{stderr}");
|
|
assert!(stdout.contains("No world in ./world yet"), "stdout:\n{stdout}\nstderr:\n{stderr}");
|
|
assert!(stderr.contains("SAUSAGE_BASE_URL"), "stdout:\n{stdout}\nstderr:\n{stderr}");
|
|
assert!(!stderr.contains("Usage:"), "stderr:\n{stderr}");
|
|
// It asks before it creates anything.
|
|
assert!(!dir.join("world").exists());
|
|
}
|