Skip to content

Commit

Permalink
Remove workaround and use #[gtk:test] macro
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Jan 8, 2023
1 parent 9921fe9 commit 50f55de
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/ci_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ mod markup_builder;
mod model;
mod password;
mod slot;
mod test;
mod ui;
mod utils;
mod version;
Expand Down
12 changes: 0 additions & 12 deletions src/test.rs

This file was deleted.

37 changes: 9 additions & 28 deletions src/ui/forms/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,17 @@ fn get_value(entry: &gtk::Entry) -> Option<String> {
#[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);

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

Expand All @@ -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(&[]);
Expand All @@ -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);

Expand All @@ -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();
Expand Down
13 changes: 3 additions & 10 deletions src/ui/forms/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ impl FormWidget<FormData> 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;
Expand All @@ -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()]));

Expand All @@ -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();
Expand Down
13 changes: 3 additions & 10 deletions src/ui/forms/multiline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,17 @@ impl FormWidget<String> 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);

Expand All @@ -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();
Expand Down
13 changes: 3 additions & 10 deletions src/ui/password_editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,17 @@ fn square(widget: impl IsA<gtk::Widget>) -> 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);

Expand All @@ -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();
Expand Down

0 comments on commit 50f55de

Please sign in to comment.