From d17497202953220317bba1efaf3236d86d37bee8 Mon Sep 17 00:00:00 2001 From: Sarah French <15078782+SarahFrench@users.noreply.github.com> Date: Fri, 15 May 2026 20:36:26 +0100 Subject: [PATCH] test: Show warning when a `-filter` flag has an invalid value (#38603) * test: Show warning when a test file filter is not valid * Add change file --- .changes/v1.16/BUG FIXES-20260515-201307.yaml | 5 +++++ internal/backend/local/test.go | 2 +- internal/command/test_test.go | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changes/v1.16/BUG FIXES-20260515-201307.yaml diff --git a/.changes/v1.16/BUG FIXES-20260515-201307.yaml b/.changes/v1.16/BUG FIXES-20260515-201307.yaml new file mode 100644 index 0000000000..77c0e25cc4 --- /dev/null +++ b/.changes/v1.16/BUG FIXES-20260515-201307.yaml @@ -0,0 +1,5 @@ +kind: BUG FIXES +body: 'test: Terraform will now raise a warning when a file referenced via `-filter` flag does not exist.' +time: 2026-05-15T20:13:07.430709+01:00 +custom: + Issue: "38603" diff --git a/internal/backend/local/test.go b/internal/backend/local/test.go index dbab3fb9bc..b61d3a8c60 100644 --- a/internal/backend/local/test.go +++ b/internal/backend/local/test.go @@ -180,7 +180,7 @@ func (runner *TestSuiteRunner) collectTests() (*moduletest.Suite, tfdiags.Diagno // If the filter is invalid, we'll simply skip this // entry and print a warning. But we could still execute // any other tests within the filter. - diags.Append(tfdiags.Sourceless( + diags = diags.Append(tfdiags.Sourceless( tfdiags.Warning, "Unknown test file", fmt.Sprintf("The specified test file, %s, could not be found.", name))) diff --git a/internal/command/test_test.go b/internal/command/test_test.go index 5ece6a0712..ae9f96f121 100644 --- a/internal/command/test_test.go +++ b/internal/command/test_test.go @@ -179,6 +179,15 @@ func TestTest_Runs(t *testing.T) { expectedOut: []string{"1 passed, 0 failed"}, code: 0, }, + "multiple_files_with_invalid_filter": { + override: "multiple_files", + args: []string{"-filter=nonexistent.tftest.hcl"}, + expectedOut: []string{ + "Success! 0 passed, 0 failed.", + "Warning: Unknown test file", + }, + code: 0, + }, "no_state": { expectedOut: []string{"0 passed, 1 failed"}, expectedErr: []string{"No value for required variable"},