diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 520092a..8a69b00 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -42,6 +42,7 @@ jobs: # Determines if the cache should be saved even when the workflow has failed. # Default: "false" cache-on-failure: "" + - uses: coactions/setup-xvfb@v1 - name: Build run: cargo build --verbose - name: Run tests diff --git a/Cargo.lock b/Cargo.lock index a1fb88a..dfa0f09 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -79,6 +79,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "bitmaps" version = "3.2.0" @@ -103,7 +109,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab3603c4028a5e368d09b51c8b624b9a46edcd7c3778284077a6125af73c9f0a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cairo-sys-rs", "glib", "libc", @@ -164,6 +170,7 @@ dependencies = [ "parking_lot", "pretty_assertions", "roxmltree", + "rusty-fork", "send_wrapper", "take_mut", "tokio", @@ -216,6 +223,33 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "136526188508e25c6fef639d7927dfb3e0e3084488bf202267829cf7fc23dbdd" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "fastrand" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" + [[package]] name = "field-offset" version = "0.3.6" @@ -226,6 +260,12 @@ dependencies = [ "rustc_version", ] +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + [[package]] name = "futures" version = "0.3.28" @@ -321,7 +361,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "695d6bc846438c5708b07007537b9274d883373dd30858ca881d7d71b5540717" dependencies = [ - "bitflags", + "bitflags 1.3.2", "gdk-pixbuf-sys", "gio", "glib", @@ -348,7 +388,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c3abf96408a26e3eddf881a7f893a1e111767137136e347745e8ea6ed12731ff" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cairo-rs", "gdk-pixbuf", "gdk4-sys", @@ -387,7 +427,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6973e92937cf98689b6a054a9e56c657ed4ff76de925e36fc331a15f0c5d30a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "futures-channel", "futures-core", "futures-io", @@ -420,7 +460,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3fad45ba8d4d2cea612b432717e834f48031cd8853c8aaf43b2c79fec8d144b" dependencies = [ - "bitflags", + "bitflags 1.3.2", "futures-channel", "futures-core", "futures-executor", @@ -502,7 +542,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f01ef44fa7cac15e2da9978529383e6bee03e570ba5bf7036b4c10a15cc3a3c" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cairo-rs", "gdk4", "glib", @@ -534,7 +574,7 @@ version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b28a32a04cd75cef14a0983f8b0c669e0fe152a0a7725accdeb594e2c764c88b" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cairo-rs", "field-offset", "futures-channel", @@ -664,6 +704,12 @@ version = "0.2.147" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" +[[package]] +name = "linux-raw-sys" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a9bad9f94746442c783ca431b22403b519cd7fbeed0533fdd6328b2f2212128" + [[package]] name = "lock_api" version = "0.4.10" @@ -771,7 +817,7 @@ version = "0.17.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35be456fc620e61f62dff7ff70fbd54dcbaf0a4b920c0f16de1107c47d921d48" dependencies = [ - "bitflags", + "bitflags 1.3.2", "gio", "glib", "libc", @@ -885,6 +931,12 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quick-error" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" + [[package]] name = "quote" version = "1.0.31" @@ -915,7 +967,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -942,6 +994,31 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7db8590df6dfcd144d22afd1b83b36c21a18d7cbc1dc4bb5295a8712e9eb662" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "rusty-fork" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" +dependencies = [ + "fnv", + "quick-error", + "tempfile", + "wait-timeout", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -1065,6 +1142,19 @@ version = "0.12.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d2faeef5759ab89935255b1a4cd98e0baf99d1085e37d36599c625dac49ae8e" +[[package]] +name = "tempfile" +version = "3.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb94d2f3cc536af71caac6b6fcebf65860b347e7ce0cc9ebe8f70d3e521054ef" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys", +] + [[package]] name = "thiserror" version = "1.0.44" @@ -1242,6 +1332,15 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "wait-timeout" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6" +dependencies = [ + "libc", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index e6e93ba..29e9082 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,6 +33,7 @@ tracing-subscriber = "0.3.17" [dev-dependencies] pretty_assertions = "1.4.0" assert_matches = "1.5" +rusty-fork = "0.3.0" [[bin]] name = "gtk" diff --git a/src/view/hierarchy.rs b/src/view/hierarchy.rs index 80439f8..7028383 100644 --- a/src/view/hierarchy.rs +++ b/src/view/hierarchy.rs @@ -491,7 +491,8 @@ impl RootListModel { #[cfg(test)] mod tests { use super::*; - + use rusty_fork::rusty_fork_test; + fn assert_tlr_node_correct(document: &sync::Arc, node: &sync::Arc, iter: &mut impl std::iter::Iterator) { let tlr = iter.next().expect("tree list model ended early"); let item = tlr.item().unwrap().downcast::().unwrap(); @@ -519,39 +520,46 @@ mod tests { fn tree_list_node_items_iter(tlm: >k::TreeListModel) -> impl std::iter::Iterator + '_ { tlm.iter::().map(|tlr| tlr.unwrap().item().unwrap().downcast::().unwrap()) } - - #[test] - fn test_reexpand() { - gtk::init().unwrap(); - - let root = structure::Node::builder() - .name("root") - .size(0x40) - .child(0x0, |b| b - .name("container") - .size(0x40) - .child(0x0, |b| b - .name("child0") - .size(0x8)) - .child(0x8, |b| b - .name("child1") - .size(0x8))) - .build(); - - let document_host = sync::Arc::new(document::DocumentHost::new(document::Document::new_for_structure_test(root))); - let mut document = document_host.get(); - - let tlm = create_tree_list_model(document_host.clone(), document.clone(), true); - assert_tlm_correct(&document, &tlm); - document = document_host.change(document.delete_range(structure::SiblingRange::new(vec![0], 0, 0))).unwrap(); - tlm.model().downcast::().unwrap().update_document(&document); - assert_tlm_correct(&document, &tlm); + rusty_fork_test! { + #[test] + fn test_reexpand() { + gtk::init().unwrap(); + + let root = structure::Node::builder() + .name("root") + .size(0x40) + .child(0x0, |b| b + .name("container") + .size(0x40) + .child(0x0, |b| b + .name("child0") + .size(0x8)) + .child(0x8, |b| b + .name("child1") + .size(0x8))) + .build(); + + let document_host = sync::Arc::new(document::DocumentHost::new(document::Document::new_for_structure_test(root))); + let mut document = document_host.get(); + + let tlm = create_tree_list_model(document_host.clone(), document.clone(), true); + assert_tlm_correct(&document, &tlm); + + document = document_host.change(document.delete_range(structure::SiblingRange::new(vec![0], 0, 0))).unwrap(); + tlm.model().downcast::().unwrap().update_document(&document); + assert_tlm_correct(&document, &tlm); - tlm.item(1).unwrap().downcast::().unwrap().set_expanded(false); - assert_tlm_correct(&document, &tlm); + tlm.item(1).unwrap().downcast::().unwrap().set_expanded(false); + assert_tlm_correct(&document, &tlm); - tlm.item(1).unwrap().downcast::().unwrap().set_expanded(true); - assert_tlm_correct(&document, &tlm); + tlm.item(1).unwrap().downcast::().unwrap().set_expanded(true); + assert_tlm_correct(&document, &tlm); + } + + #[test] + fn test_another() { + gtk::init().unwrap(); + } } }