mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-12-02 15:01:42 -05:00
test: resolve nightly launches in the socket tests without installing the profile
cargo test runs the pdfcraft binary's unit tests in one process. The single-instance socket tests called launch_profile::prepare, which installs the nightly profile in craft_nightly's process-wide OnceLock, so tests that ran after them saw a nightly launch: the window icon test compared the nightly icon with the stable one, and stable_defaults_and_nightly_version_line found is_nightly() true. The FreeBSD workflow runs plain cargo test and failed this way. The socket tests now parse and validate the launch the same way, without installing it.
This commit is contained in:
@@ -67,6 +67,19 @@ mod tests {
|
||||
args(&["--launch-profile", NIGHTLY_V1_CONTRACT, "--profile-root", absolute(), "--"])
|
||||
}
|
||||
|
||||
/// What [`super::prepare`] returns for `argv`, without installing the profile process-wide.
|
||||
/// `cargo test` runs every unit test of the binary in one process, and an installed nightly
|
||||
/// profile would make the stable icon, app id and title tests that run after it see nightly.
|
||||
#[cfg(any(windows, all(unix, not(target_os = "macos"))))]
|
||||
fn prepare_without_installing(argv: Vec<OsString>) -> Result<craft_nightly::Launch, ProfileError> {
|
||||
let spec = profile_root::spec();
|
||||
let mut launch = parse_startup(BuildFlavor::NightlyV1, &spec, argv, &StartupOptions::new())?;
|
||||
if let Profile::NightlyV1(root) = &launch.profile {
|
||||
launch.profile = Profile::NightlyV1(craft_nightly::validate_and_prepare_root(root, &spec)?);
|
||||
}
|
||||
Ok(launch)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stable_arguments_and_directory_policy_are_unchanged() {
|
||||
let spec = profile_root::spec();
|
||||
@@ -158,14 +171,14 @@ mod tests {
|
||||
let listener = UnixListener::bind(&sock_path).unwrap();
|
||||
|
||||
// Live listener socket already present inside <profile>/single-instance/.
|
||||
let live_launch = super::prepare(BuildFlavor::NightlyV1, launch_arguments(&profile, &args(&["doc.pdf"]))).unwrap();
|
||||
let live_launch = prepare_without_installing(launch_arguments(&profile, &args(&["doc.pdf"]))).unwrap();
|
||||
assert_eq!(live_launch.profile, Profile::NightlyV1(expected_root.clone()));
|
||||
assert_eq!(live_launch.passthrough_args, args(&["doc.pdf"]));
|
||||
|
||||
// Leftover/stale socket remaining after the previous instance exits.
|
||||
drop(listener);
|
||||
assert!(std::fs::symlink_metadata(&sock_path).is_ok(), "stale socket remains on disk");
|
||||
let stale_launch = super::prepare(BuildFlavor::NightlyV1, launch_arguments(&profile, &args(&["after-exit.pdf"]))).unwrap();
|
||||
let stale_launch = prepare_without_installing(launch_arguments(&profile, &args(&["after-exit.pdf"]))).unwrap();
|
||||
assert_eq!(stale_launch.profile, Profile::NightlyV1(expected_root));
|
||||
assert_eq!(stale_launch.passthrough_args, args(&["after-exit.pdf"]));
|
||||
}
|
||||
@@ -183,14 +196,14 @@ mod tests {
|
||||
let listener = uds_windows::UnixListener::bind(&sock_path).unwrap();
|
||||
|
||||
// Live AF_UNIX listener socket already present inside <profile>\single-instance\.
|
||||
let live_launch = super::prepare(BuildFlavor::NightlyV1, launch_arguments(&profile, &args(&["doc.pdf"]))).unwrap();
|
||||
let live_launch = prepare_without_installing(launch_arguments(&profile, &args(&["doc.pdf"]))).unwrap();
|
||||
assert_eq!(live_launch.profile, Profile::NightlyV1(expected_root.clone()));
|
||||
assert_eq!(live_launch.passthrough_args, args(&["doc.pdf"]));
|
||||
|
||||
// Leftover/stale socket remaining after the previous instance exits.
|
||||
drop(listener);
|
||||
assert!(std::fs::symlink_metadata(&sock_path).is_ok(), "stale socket remains on disk");
|
||||
let stale_launch = super::prepare(BuildFlavor::NightlyV1, launch_arguments(&profile, &args(&["after-exit.pdf"]))).unwrap();
|
||||
let stale_launch = prepare_without_installing(launch_arguments(&profile, &args(&["after-exit.pdf"]))).unwrap();
|
||||
assert_eq!(stale_launch.profile, Profile::NightlyV1(expected_root));
|
||||
assert_eq!(stale_launch.passthrough_args, args(&["after-exit.pdf"]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user