Run without a clone: bare sausage creates ./world if needed and runs it
ci / check (push) Successful in 14m24s
ci / check (push) Successful in 14m24s
- 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). - flake: .#loop without a folder runs bare sausage. - README: nix run git+https://gitea.surma.technology/surma/sausage(#loop), clone only for working on Sausage.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
//! 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());
|
||||
}
|
||||
Reference in New Issue
Block a user