From 50f55dec81abb30fbf17612a8df1410b5715ce84 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Tue, 3 Jan 2023 10:18:32 +0100 Subject: [PATCH] Remove workaround and use #[gtk:test] macro --- .github/workflows/ci_linux.yml | 2 +- .github/workflows/ci_macos.yml | 2 +- .github/workflows/ci_windows.yml | 2 +- .github/workflows/coverage.yml | 2 +- Makefile | 4 ++-- src/main.rs | 1 - src/test.rs | 12 ----------- src/ui/forms/entry.rs | 37 ++++++++------------------------ src/ui/forms/form.rs | 13 +++-------- src/ui/forms/multiline.rs | 13 +++-------- src/ui/password_editor/mod.rs | 13 +++-------- 11 files changed, 24 insertions(+), 77 deletions(-) delete mode 100644 src/test.rs diff --git a/.github/workflows/ci_linux.yml b/.github/workflows/ci_linux.yml index c28ff234..4c449257 100644 --- a/.github/workflows/ci_linux.yml +++ b/.github/workflows/ci_linux.yml @@ -16,6 +16,6 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: xvfb-run cargo test --verbose -- --nocapture --test-threads 1 + run: xvfb-run cargo test --verbose -- --nocapture env: RUST_BACKTRACE: 1 diff --git a/.github/workflows/ci_macos.yml b/.github/workflows/ci_macos.yml index 23a40624..070e0f45 100644 --- a/.github/workflows/ci_macos.yml +++ b/.github/workflows/ci_macos.yml @@ -13,6 +13,6 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose -- --nocapture --test-threads 1 + run: cargo test --verbose -- --nocapture env: RUST_BACKTRACE: 1 diff --git a/.github/workflows/ci_windows.yml b/.github/workflows/ci_windows.yml index d56974ed..a1786b0b 100644 --- a/.github/workflows/ci_windows.yml +++ b/.github/workflows/ci_windows.yml @@ -24,6 +24,6 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose -- --nocapture --test-threads 1 + run: cargo test --verbose -- --nocapture env: RUST_BACKTRACE: 1 diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 6b9b1453..e032b5c0 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -21,7 +21,7 @@ jobs: - name: Install cargo-llvm-cov uses: taiki-e/install-action@cargo-llvm-cov - name: Generate code coverage - run: RUST_TEST_THREADS=1 xvfb-run cargo llvm-cov --lcov --output-path lcov.info + run: xvfb-run cargo llvm-cov --lcov --output-path lcov.info - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 with: diff --git a/Makefile b/Makefile index 787796f3..e53b0617 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ test: - cargo test -- --nocapture --test-threads 1 + cargo test -- --nocapture coverage: - cargo tarpaulin --forward --timeout 5 --out Xml --verbose -- --nocapture --test-threads=1 + cargo tarpaulin --forward --timeout 5 --out Xml --verbose -- --nocapture flatpak: flatpak-builder build-dir --user --install-deps-from=flathub --force-clean build-flatpak/dev.andy128k.password-storage.yml diff --git a/src/main.rs b/src/main.rs index 840c0a40..03e50cda 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,7 +15,6 @@ mod markup_builder; mod model; mod password; mod slot; -mod test; mod ui; mod utils; mod version; diff --git a/src/test.rs b/src/test.rs deleted file mode 100644 index a5173b9c..00000000 --- a/src/test.rs +++ /dev/null @@ -1,12 +0,0 @@ -#![cfg(test)] - -use crate::gtk_prelude::*; - -pub fn test_gtk_init() { - use std::sync::Once; - - static START: Once = Once::new(); - START.call_once(|| { - gtk::init().unwrap(); - }); -} diff --git a/src/ui/forms/entry.rs b/src/ui/forms/entry.rs index fe8b7d5e..18dce756 100644 --- a/src/ui/forms/entry.rs +++ b/src/ui/forms/entry.rs @@ -70,22 +70,17 @@ fn get_value(entry: >k::Entry) -> Option { #[cfg(test)] mod test { use super::*; - use crate::test::test_gtk_init; use std::cell::RefCell; use std::rc::Rc; - #[test] + #[gtk::test] fn test_text() { - test_gtk_init(); - let w = Text::new(); w.get_widget(); // ensure get_widget doesn't panic } - #[test] + #[gtk::test] fn test_text_value() { - test_gtk_init(); - let w = Text::new(); assert_eq!(w.get_value(), None); @@ -97,10 +92,8 @@ mod test { assert_eq!(w.get_value(), None); } - #[test] + #[gtk::test] fn test_text_event() { - test_gtk_init(); - let value = Rc::new(RefCell::new(None)); let mut w = Text::new(); @@ -112,18 +105,14 @@ mod test { assert_eq!(*value.borrow(), Some(new_value)); } - #[test] + #[gtk::test] fn test_name() { - test_gtk_init(); - let w = Text::new().with_completion(&[]); w.get_widget(); // ensure get_widget doesn't panic } - #[test] + #[gtk::test] fn test_name_value() { - test_gtk_init(); - let w = Text::new().with_completion(&[]); assert_eq!(w.get_value(), None); @@ -135,10 +124,8 @@ mod test { assert_eq!(w.get_value(), None); } - #[test] + #[gtk::test] fn test_name_event() { - test_gtk_init(); - let value = Rc::new(RefCell::new(None)); let mut w = Text::new().with_completion(&[]); @@ -150,18 +137,14 @@ mod test { assert_eq!(*value.borrow(), Some(new_value)); } - #[test] + #[gtk::test] fn test_password() { - test_gtk_init(); - let w = Text::new().for_password(); w.get_widget(); // ensure get_widget doesn't panic } - #[test] + #[gtk::test] fn test_password_value() { - test_gtk_init(); - let w = Text::new().for_password(); assert_eq!(w.get_value(), None); @@ -173,10 +156,8 @@ mod test { assert_eq!(w.get_value(), None); } - #[test] + #[gtk::test] fn test_password_event() { - test_gtk_init(); - let value = Rc::new(RefCell::new(None)); let mut w = Text::new().for_password(); diff --git a/src/ui/forms/form.rs b/src/ui/forms/form.rs index a11f0354..e9009c77 100644 --- a/src/ui/forms/form.rs +++ b/src/ui/forms/form.rs @@ -181,7 +181,6 @@ impl FormWidget for Form { #[cfg(test)] mod test { use super::*; - use crate::test::test_gtk_init; use crate::ui::forms::entry::Text; use std::cell::RefCell; use std::rc::Rc; @@ -193,18 +192,14 @@ mod test { form } - #[test] + #[gtk::test] fn test_multiline() { - test_gtk_init(); - let w = new_form(); w.get_widget(); // ensure get_widget doesn't panic } - #[test] + #[gtk::test] fn test_multiline_value() { - test_gtk_init(); - let w = new_form(); assert_eq!(w.get_value(), Some(vec!["".to_string(), "".to_string()])); @@ -216,10 +211,8 @@ mod test { assert_eq!(w.get_value(), Some(vec!["".to_string(), "".to_string()])); } - #[test] + #[gtk::test] fn test_multiline_event() { - test_gtk_init(); - let value = Rc::new(RefCell::new(None)); let mut w = new_form(); diff --git a/src/ui/forms/multiline.rs b/src/ui/forms/multiline.rs index 6702bf18..de8734a8 100644 --- a/src/ui/forms/multiline.rs +++ b/src/ui/forms/multiline.rs @@ -70,22 +70,17 @@ impl FormWidget for MultiLine { #[cfg(test)] mod test { use super::*; - use crate::test::test_gtk_init; use std::cell::RefCell; use std::rc::Rc; - #[test] + #[gtk::test] fn test_multiline() { - test_gtk_init(); - let w = MultiLine::new(); w.get_widget(); // ensure get_widget doesn't panic } - #[test] + #[gtk::test] fn test_multiline_value() { - test_gtk_init(); - let w = MultiLine::new(); assert_eq!(w.get_value(), None); @@ -97,10 +92,8 @@ mod test { assert_eq!(w.get_value(), None); } - #[test] + #[gtk::test] fn test_multiline_event() { - test_gtk_init(); - let value = Rc::new(RefCell::new(None)); let mut w = MultiLine::new(); diff --git a/src/ui/password_editor/mod.rs b/src/ui/password_editor/mod.rs index 29030765..c50211ae 100644 --- a/src/ui/password_editor/mod.rs +++ b/src/ui/password_editor/mod.rs @@ -117,22 +117,17 @@ fn square(widget: impl IsA) -> gtk::Widget { #[cfg(test)] mod test { use super::*; - use crate::test::test_gtk_init; use std::cell::RefCell; use std::rc::Rc; - #[test] + #[gtk::test] fn test_open_password() { - test_gtk_init(); - let w = PasswordEditor::new(); w.get_widget(); // ensure get_widget doesn't panic } - #[test] + #[gtk::test] fn test_open_password_value() { - test_gtk_init(); - let w = PasswordEditor::new(); assert_eq!(w.get_value(), None); @@ -144,10 +139,8 @@ mod test { assert_eq!(w.get_value(), None); } - #[test] + #[gtk::test] fn test_open_password_event() { - test_gtk_init(); - let value = Rc::new(RefCell::new(None)); let mut w = PasswordEditor::new();