From cc33944072166db0882de6326bf84da8425def38 Mon Sep 17 00:00:00 2001 From: Stadnik Andrii Date: Fri, 6 Oct 2023 21:46:58 +0300 Subject: [PATCH 1/5] test: assert data is not empty --- core/tests/test_data.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/tests/test_data.rs b/core/tests/test_data.rs index 149179e0..1b7adff2 100644 --- a/core/tests/test_data.rs +++ b/core/tests/test_data.rs @@ -74,12 +74,12 @@ pre-formatted fixed-width code block written in the Python programming language } else { get_data_from_file("../table.csv")? }; + assert!(!data.is_empty()); data.iter() .for_each(|(lang, fs)| log::info!("Testing {lang} with {} nodes", fs.num_nodes())); for (lang, fs) in data.into_iter() { let n_nodes = fs.num_nodes(); test_fs(fs)?; - log::info!("All tests passed for {lang} with {n_nodes} nodes"); } Ok(()) From bf7aa0e78885d3c911e84a673b4272636f6f2517 Mon Sep 17 00:00:00 2001 From: Stadnik Andrii Date: Fri, 6 Oct 2023 21:51:56 +0300 Subject: [PATCH 2/5] refactor: Simplify test_data.rs code --- core/src/model/mod.rs | 2 +- core/tests/test_data.rs | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/core/src/model/mod.rs b/core/src/model/mod.rs index cc9dc894..d79a2987 100644 --- a/core/src/model/mod.rs +++ b/core/src/model/mod.rs @@ -59,7 +59,7 @@ pub fn get_data_from_file(filename: &str) -> anyhow::Result { } pub async fn get_data_from_web() -> anyhow::Result { - let sheet_id = env!("SHEET_ID"); + let sheet_id = option_env!("SHEET_ID").ok_or_else(|| anyhow!("SHEET_ID is not set"))?; assert!(Lang::iter().count() == 1, "Only one language is supported"); let lang = Lang::iter().next().unwrap(); let sheet_name = lang.name(); diff --git a/core/tests/test_data.rs b/core/tests/test_data.rs index 1b7adff2..d5bcd39d 100644 --- a/core/tests/test_data.rs +++ b/core/tests/test_data.rs @@ -75,12 +75,9 @@ pre-formatted fixed-width code block written in the Python programming language get_data_from_file("../table.csv")? }; assert!(!data.is_empty()); - data.iter() - .for_each(|(lang, fs)| log::info!("Testing {lang} with {} nodes", fs.num_nodes())); - for (lang, fs) in data.into_iter() { - let n_nodes = fs.num_nodes(); - test_fs(fs)?; - } + data.into_iter() + .inspect(|(lang, fs)| log::info!("Testing {lang} with {} nodes", fs.num_nodes())) + .try_for_each(|(_, fs)| test_fs(fs))?; Ok(()) } From eaeed71d75497342a20380fb491435c283cb8dc8 Mon Sep 17 00:00:00 2001 From: Stadnik Andrii Date: Fri, 6 Oct 2023 21:55:19 +0300 Subject: [PATCH 3/5] chore: Add RUST_LOG environment variable --- .github/workflows/build_and_test_bot.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_and_test_bot.yml b/.github/workflows/build_and_test_bot.yml index dcc379b9..f507c6bf 100644 --- a/.github/workflows/build_and_test_bot.yml +++ b/.github/workflows/build_and_test_bot.yml @@ -28,6 +28,7 @@ jobs: if: inputs.release env: SHEET_ID: ${{ env.SHEET_ID }} + RUST_LOG: info run: cargo test --release -- --nocapture && cargo build --release - name: Test and build debug From 2aebd73919bd599310ae35b886928cf5f3f3c014 Mon Sep 17 00:00:00 2001 From: Stadnik Andrii Date: Fri, 6 Oct 2023 21:57:32 +0300 Subject: [PATCH 4/5] chore: Add RUST_LOG environment variable --- .github/workflows/build_and_test_bot.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build_and_test_bot.yml b/.github/workflows/build_and_test_bot.yml index f507c6bf..06bbdd9c 100644 --- a/.github/workflows/build_and_test_bot.yml +++ b/.github/workflows/build_and_test_bot.yml @@ -35,6 +35,7 @@ jobs: if: ${{ !inputs.release }} env: SHEET_ID: ${{ env.SHEET_ID }} + RUST_LOG: info run: cargo test -- --nocapture && cargo build - name: Move binary From cfac4fc97124b35927f000586bfebdb517bb0950 Mon Sep 17 00:00:00 2001 From: Stadnik Andrii Date: Fri, 6 Oct 2023 22:07:38 +0300 Subject: [PATCH 5/5] test: Add assertion for non-empty data and multiple nodes --- .github/workflows/build_and_test_bot.yml | 4 ++-- core/src/model/mod.rs | 5 ++++- core/tests/test_data.rs | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_test_bot.yml b/.github/workflows/build_and_test_bot.yml index 06bbdd9c..5903a615 100644 --- a/.github/workflows/build_and_test_bot.yml +++ b/.github/workflows/build_and_test_bot.yml @@ -27,14 +27,14 @@ jobs: - name: Test and build release if: inputs.release env: - SHEET_ID: ${{ env.SHEET_ID }} + SHEET_ID: ${{ secrets.SHEET_ID }} RUST_LOG: info run: cargo test --release -- --nocapture && cargo build --release - name: Test and build debug if: ${{ !inputs.release }} env: - SHEET_ID: ${{ env.SHEET_ID }} + SHEET_ID: ${{ secrets.SHEET_ID }} RUST_LOG: info run: cargo test -- --nocapture && cargo build diff --git a/core/src/model/mod.rs b/core/src/model/mod.rs index d79a2987..f40c85a0 100644 --- a/core/src/model/mod.rs +++ b/core/src/model/mod.rs @@ -10,7 +10,7 @@ pub mod prelude { } use self::finite_state::{Fs, Row}; -use anyhow::{anyhow, Context}; +use anyhow::{anyhow, bail, Context}; use bytes::Buf; use csv::Reader; use finite_state::MultilangFs; @@ -42,6 +42,9 @@ fn get_finite_state(rdr: Reader, lang: Lang) -> anyhow::Result { .collect::, _>>() .context("Cannot parse csv")?; rows.retain(|record| !record.is_empty()); + if rows.is_empty() { + bail!("No data"); + } for r in rows.iter_mut() { r.key = r.key.trim().to_string(); r.question = r.question.trim().to_string(); diff --git a/core/tests/test_data.rs b/core/tests/test_data.rs index d5bcd39d..3573410a 100644 --- a/core/tests/test_data.rs +++ b/core/tests/test_data.rs @@ -75,6 +75,7 @@ pre-formatted fixed-width code block written in the Python programming language get_data_from_file("../table.csv")? }; assert!(!data.is_empty()); + assert!(data.iter().all(|(_, fs)| fs.num_nodes() > 1)); data.into_iter() .inspect(|(lang, fs)| log::info!("Testing {lang} with {} nodes", fs.num_nodes())) .try_for_each(|(_, fs)| test_fs(fs))?;