Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
add some manual osx rust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
caesay committed Dec 25, 2023
1 parent cdd97de commit 543d2dc
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Rust/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"rust-analyzer.cargo.features": ["windows"]
"rust-analyzer.showUnlinkedFileNotification": false
}
92 changes: 92 additions & 0 deletions src/Rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum-flags = "0.3"
remove_dir_all = { git = "https://github.com/caesay/remove_dir_all.git", features = [
"log",
] }
ntest = "0.9.0"

[target.'cfg(target_os = "macos")'.dependencies]
native-dialog = "0.7"
Expand Down
24 changes: 24 additions & 0 deletions src/Rust/src/shared/dialogs_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,37 @@ pub fn show_info(title: &str, header: Option<&str>, body: &str) {
}

pub fn show_ok_cancel(title: &str, header: Option<&str>, body: &str, ok_text: Option<&str>) -> bool {
if get_silent() {
return false;
}

let mut btns = DialogButton::Cancel;
if ok_text.is_none() {
btns |= DialogButton::Ok;
}
generate_confirm(title, header, body, ok_text, btns, DialogIcon::Warning).map(|dlg_id| dlg_id == DialogResult::Ok).unwrap_or(false)
}

#[test]
#[ntest::timeout(2000)]
fn test_no_dialogs_show_if_silent() {
set_silent(true);
show_error("Error", None, "This is an error.");
show_warn("Warning", None, "This is a warning.");
show_info("Information", None, "This is information.");
assert!(!show_ok_cancel("Ok/Cancel", None, "This is a question.", None));
}

#[test]
#[ignore]
fn test_show_all_dialogs() {
show_error("Error", None, "This is an error.");
show_warn("Warning", None, "This is a warning.");
show_info("Information", None, "This is information.");
assert!(show_ok_cancel("Ok/Cancel", None, "This is a question.", None));
assert!(!show_ok_cancel("Ok/Cancel", None, "This is a question.", Some("Ok")));
}

// pub fn yes_no(title: &str, header: Option<&str>, body: &str) -> Result<bool> {
// generate(title, header, body, None, co::TDCBF::YES | co::TDCBF::NO, co::TD_ICON::WARNING).map(|dlg_id| dlg_id == co::DLGID::YES)
// }
Expand Down
21 changes: 20 additions & 1 deletion src/Rust/src/shared/util_osx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,26 @@ pub fn start_package<P: AsRef<Path>>(_app: &Manifest, root_dir: P, exe_args: Opt
}

#[test]
#[ignore]
fn test_start_and_stop_package()
{
assert!(false);
let mani = Manifest::default();
let root_dir = "/Applications/Calcbot.app";
let _ = force_stop_package(root_dir);

fn is_running() -> bool {
let output = Process::new("pgrep").arg("-f").arg("Calcbot.app").output().unwrap();
output.stdout.len() > 0
}

std::thread::sleep(Duration::from_secs(1));
assert!(!is_running());
std::thread::sleep(Duration::from_secs(1));
start_package(&mani, root_dir, None).unwrap();
std::thread::sleep(Duration::from_secs(1));
assert!(is_running());
std::thread::sleep(Duration::from_secs(1));
force_stop_package(root_dir).unwrap();
std::thread::sleep(Duration::from_secs(1));
assert!(!is_running());
}

0 comments on commit 543d2dc

Please sign in to comment.