add some manual osx rust tests

This commit is contained in:
caesay
2023-12-25 17:19:39 +00:00
parent cdd97debc2
commit 543d2dc3d6
5 changed files with 138 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
{
"rust-analyzer.cargo.features": ["windows"]
"rust-analyzer.showUnlinkedFileNotification": false
}

92
src/Rust/Cargo.lock generated
View File

@@ -256,6 +256,7 @@ dependencies = [
"native-dialog",
"native-tls",
"normpath",
"ntest",
"os_info",
"pretty-bytes-rust",
"rand",
@@ -473,6 +474,12 @@ dependencies = [
"syn 1.0.109",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "errno"
version = "0.3.8"
@@ -626,6 +633,12 @@ version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b"
[[package]]
name = "hashbrown"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "heck"
version = "0.4.1"
@@ -690,6 +703,16 @@ dependencies = [
"png",
]
[[package]]
name = "indexmap"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d530e1a18b1cb4c484e6e34556a0d948706958449fca0cab753d649f2bce3d1f"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "itertools"
version = "0.11.0"
@@ -866,6 +889,39 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "ntest"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da8ec6d2b73d45307e926f5af46809768581044384637af6b3f3fe7c3c88f512"
dependencies = [
"ntest_test_cases",
"ntest_timeout",
]
[[package]]
name = "ntest_test_cases"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be7d33be719c6f4d09e64e27c1ef4e73485dc4cc1f4d22201f89860a7fe22e22"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "ntest_timeout"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "066b468120587a402f0b47d8f80035c921f6a46f8209efd0632a89a16f5188a4"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "num-integer"
version = "0.1.45"
@@ -1045,6 +1101,16 @@ dependencies = [
"clap",
]
[[package]]
name = "proc-macro-crate"
version = "1.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919"
dependencies = [
"once_cell",
"toml_edit",
]
[[package]]
name = "proc-macro2"
version = "1.0.71"
@@ -1465,6 +1531,23 @@ dependencies = [
"serde",
]
[[package]]
name = "toml_datetime"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1"
[[package]]
name = "toml_edit"
version = "0.19.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421"
dependencies = [
"indexmap",
"toml_datetime",
"winnow",
]
[[package]]
name = "typenum"
version = "1.17.0"
@@ -1921,6 +2004,15 @@ version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04"
[[package]]
name = "winnow"
version = "0.5.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b5c3db89721d50d0e2a673f5043fc4722f76dcc352d7b1ab8b8288bed4ed2c5"
dependencies = [
"memchr",
]
[[package]]
name = "winres"
version = "0.1.12"

View File

@@ -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"

View File

@@ -31,6 +31,10 @@ 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;
@@ -38,6 +42,26 @@ pub fn show_ok_cancel(title: &str, header: Option<&str>, body: &str, ok_text: Op
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)
// }

View File

@@ -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());
}