From 49152131bc5baf57c9aeae52014929f9a8482287 Mon Sep 17 00:00:00 2001 From: Brady Fomegne Date: Sun, 14 Apr 2024 23:23:28 +0100 Subject: [PATCH 1/3] test: increase coverage test in `src/lib.rs` --- src/lib.rs | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 43a4812..0f19e06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -453,3 +453,76 @@ impl Frontend for Wish { self.predicates_widget.text(&texts.join("\n")); } } + +#[cfg(test)] +mod tests { + use crate::{Config, Wish}; + use afrim::frontend::Frontend; + use rstk::{self}; + use std::path::Path; + use std::thread; + use std::time::Duration; + + #[test] + fn test_api() { + let config = Config::from_file(Path::new("data/full_sample.toml")).unwrap(); + let mut afrim_wish = Wish::init(config); + afrim_wish.build(); + + // Test without data. + afrim_wish.clear_predicates(); + afrim_wish.next_predicate(); + afrim_wish.previous_predicate(); + assert!(afrim_wish.get_selected_predicate().is_none()); + afrim_wish.display(); + + // Test the adding of predicates. + afrim_wish.set_page_size(3); + afrim_wish.set_input("Test started!"); + afrim_wish.add_predicate("test", "123", "ok"); + afrim_wish.add_predicate("test1", "23", "ok"); + afrim_wish.add_predicate("test12", "1", "ok"); + afrim_wish.add_predicate("test123", "", "ok"); + afrim_wish.add_predicate("test1234", "", ""); + afrim_wish.display(); + + // Test the geometry. + (0..800).for_each(|i| { + if i % 100 != 0 { + return; + }; + let i = i as f64; + afrim_wish.update_position((i, i)); + thread::sleep(Duration::from_millis(100)); + }); + + // Test the navigation. + afrim_wish.previous_predicate(); + assert_eq!( + afrim_wish.get_selected_predicate(), + Some(&("test1234".to_owned(), "".to_owned(), "".to_owned())) + ); + afrim_wish.next_predicate(); + assert_eq!( + afrim_wish.get_selected_predicate(), + Some(&("test".to_owned(), "123".to_owned(), "ok".to_owned())) + ); + afrim_wish.display(); + + // Test error message. + { + let afrim_wish = afrim_wish.clone(); + rstk::after(300, move || { + afrim_wish.raise_error("Intentional error", "For testing purpose"); + }); + } + { + let afrim_wish = afrim_wish.clone(); + rstk::after(500, move || { + afrim_wish.destroy(); + }); + } + + afrim_wish.listen(); + } +} From e9f960c0482cd0fcd520b8a1802839e6162fb7cc Mon Sep 17 00:00:00 2001 From: Brady Fomegne Date: Mon, 15 Apr 2024 00:00:24 +0100 Subject: [PATCH 2/3] fix ci --- .github/workflows/rust.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8a90d20..d84d7f8 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,7 +21,9 @@ jobs: steps: - uses: actions/checkout@v3 - uses: Swatinem/rust-cache@v2 - + with: + # To only cache runs from `master` + save-if: ${{ github.ref == 'refs/heads/main' }} - if: matrix.os == 'ubuntu-latest' uses: awalsh128/cache-apt-pkgs-action@latest with: From 6bfe324db7b24a48e148c7a9e1a879b17ec14809 Mon Sep 17 00:00:00 2001 From: Brady Fomegne Date: Mon, 15 Apr 2024 00:12:07 +0100 Subject: [PATCH 3/3] fix --- .github/workflows/rust.yml | 8 ++++++++ src/lib.rs | 21 ++------------------- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index d84d7f8..2657a81 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,10 +13,15 @@ env: jobs: build: runs-on: ${{matrix.os}} + env: + DISPLAY: ':99' strategy: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] + include: + - os: ubuntu-latest + headless: Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & steps: - uses: actions/checkout@v3 @@ -30,6 +35,9 @@ jobs: packages: libxtst-dev libevdev-dev libxdo-dev version: 1.0 + - name: Setup headless environment + run: ${{matrix.headless}} + - name: Add components run: rustup component add clippy rustfmt diff --git a/src/lib.rs b/src/lib.rs index 0f19e06..0003e63 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -458,7 +458,6 @@ impl Frontend for Wish { mod tests { use crate::{Config, Wish}; use afrim::frontend::Frontend; - use rstk::{self}; use std::path::Path; use std::thread; use std::time::Duration; @@ -487,8 +486,8 @@ mod tests { afrim_wish.display(); // Test the geometry. - (0..800).for_each(|i| { - if i % 100 != 0 { + (0..100).for_each(|i| { + if i % 10 != 0 { return; }; let i = i as f64; @@ -508,21 +507,5 @@ mod tests { Some(&("test".to_owned(), "123".to_owned(), "ok".to_owned())) ); afrim_wish.display(); - - // Test error message. - { - let afrim_wish = afrim_wish.clone(); - rstk::after(300, move || { - afrim_wish.raise_error("Intentional error", "For testing purpose"); - }); - } - { - let afrim_wish = afrim_wish.clone(); - rstk::after(500, move || { - afrim_wish.destroy(); - }); - } - - afrim_wish.listen(); } }