From decbd0f0c019844cd2b235e7804d2f6ba7b23897 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Rodr=C3=ADguez?= Date: Tue, 19 Dec 2023 09:36:35 +0000 Subject: [PATCH] fix: Don't fail if no tests and the user didn't provide a pattern (#3864) # Description Workspaces typically contain some crates with no tests (especially binary crates that are only entry points). Running tests without specifying a test name on a crate won't fail with this PR if that crate has no tests. ## Problem\* Possible approach to #3863 ## Summary\* ## Additional Context ## Documentation\* Check one: - [ ] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[Exceptional Case]** Documentation to be submitted in a separate PR. # PR Checklist\* - [x] I have tested the changes locally. - [x] I have formatted the changes with [Prettier](https://prettier.io/) and/or `cargo fmt` on default settings. --- tooling/nargo_cli/src/cli/test_cmd.rs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tooling/nargo_cli/src/cli/test_cmd.rs b/tooling/nargo_cli/src/cli/test_cmd.rs index 43cfecd17e9..fcad4d4ee9f 100644 --- a/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/tooling/nargo_cli/src/cli/test_cmd.rs @@ -98,18 +98,21 @@ fn run_tests( let test_functions = context.get_all_test_functions_in_crate_matching(&crate_id, fn_name); let count_all = test_functions.len(); if count_all == 0 { - return match &fn_name { - FunctionNameMatch::Anything => { - Err(CliError::Generic(format!("[{}] Found 0 tests.", package.name))) + match &fn_name { + FunctionNameMatch::Exact(pattern) => { + return Err(CliError::Generic(format!( + "[{}] Found 0 tests matching input '{pattern}'.", + package.name + ))) } - FunctionNameMatch::Exact(pattern) => Err(CliError::Generic(format!( - "[{}] Found 0 tests matching input '{pattern}'.", - package.name - ))), - FunctionNameMatch::Contains(pattern) => Err(CliError::Generic(format!( - "[{}] Found 0 tests containing '{pattern}'.", - package.name - ))), + FunctionNameMatch::Contains(pattern) => { + return Err(CliError::Generic(format!( + "[{}] Found 0 tests containing '{pattern}'.", + package.name + ))) + } + // If we are running all tests in a crate, having none is not an error + FunctionNameMatch::Anything => {} }; }