Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions crates/xcl/tests/launcher_e2e.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::PathBuf;
use std::process::Command;
use std::process::{Command, Output};
use std::time::{SystemTime, UNIX_EPOCH};

struct TempDir(PathBuf);
Expand All @@ -22,6 +22,21 @@ impl Drop for TempDir {
}
}

/// `xcl run` on a game folder, with a data root of its own next to it: without one XCL makes the
/// title's data folder in the user's `%LOCALAPPDATA%\XCL`, where it stays after the test.
fn run_game_folder(game: &TempDir) -> Output {
let data = TempDir(game.0.with_extension("data"));
let output = Command::new(env!("CARGO_BIN_EXE_xcl"))
.arg("run")
.arg(&game.0)
.env("XCL_DATA_ROOT", &data.0)
.output()
.unwrap();
let title = data.0.join(game.0.file_name().unwrap());
assert!(title.join("xcl.toml").is_file(), "the title's data is not in the test's data root: {output:?}");
output
}

#[test]
fn launcher_missing_target_argument_exits_code_two() {
let output = Command::new(env!("CARGO_BIN_EXE_xcl"))
Expand Down Expand Up @@ -64,11 +79,7 @@ fn launcher_directory_without_executables_exits_code_two() {
let dir = TempDir::new("xcl-no-exe");
std::fs::write(dir.0.join("readme.txt"), b"no executables here").unwrap();

let output = Command::new(env!("CARGO_BIN_EXE_xcl"))
.arg("run")
.arg(&dir.0)
.output()
.unwrap();
let output = run_game_folder(&dir);
assert_eq!(output.status.code(), Some(2));
let err = String::from_utf8(output.stderr).unwrap();
assert!(err.contains("no game .exe file in"));
Expand All @@ -80,11 +91,7 @@ fn launcher_directory_with_ambiguous_executables_exits_code_two() {
std::fs::write(dir.0.join("game_a.exe"), b"executable a").unwrap();
std::fs::write(dir.0.join("game_b.exe"), b"executable b").unwrap();

let output = Command::new(env!("CARGO_BIN_EXE_xcl"))
.arg("run")
.arg(&dir.0)
.output()
.unwrap();
let output = run_game_folder(&dir);
assert_eq!(output.status.code(), Some(2));
let err = String::from_utf8(output.stderr).unwrap();
assert!(err.contains("several .exe files"));
Expand All @@ -98,11 +105,7 @@ fn launcher_directory_with_only_xcl_copy_warns_self() {
let dest_xcl = dir.0.join("xcl.exe");
std::fs::copy(self_exe, &dest_xcl).unwrap();

let output = Command::new(self_exe)
.arg("run")
.arg(&dir.0)
.output()
.unwrap();
let output = run_game_folder(&dir);
assert_eq!(output.status.code(), Some(2));
let err = String::from_utf8(output.stderr).unwrap();
assert!(err.contains("only xcl.exe – that is XCL itself; do not copy it into the game folder"));
Expand Down
Loading