Skip to content

--where / SelectWhere: whitespace inside a quoted test == value is stripped in 3.22.0, so tests whose names contain a space are no longer selected #1927

Closed

Description

@stryczekk

Starting with NUnit Engine 3.22.0, the selection-expression parser removes whitespace that appears outside double quotes within a single-quoted value. The resulting filter no longer matches the test's full name, and the test is silently skipped. No error or warning is reported. 3.18.1 keeps the value verbatim.

This affects names NUnit generates itself. A ValueTuple argument is displayed as (A, B), with a space after the comma. Names set via SetName("{m} (Case 1)") are affected too. Spaces inside a string argument ("a b") are kept.

Repro (engine only)

using System;
using NUnit.Engine;

string[] wheres =
[
    "test == 'Repro.TupleOnly.Tuple((PROJECT, GLOBAL))'",
    "test == 'Repro.Shapes.StringArg(\"a b\")'",
    "test == 'Repro.Shapes.SpaceBeforeParen (Case 1)'",
];
using var engine = TestEngineActivator.CreateInstance();
var service = engine.Services.GetService<ITestFilterService>();
foreach (var where in wheres)
{
    var builder = service.GetTestFilterBuilder();
    builder.SelectWhere(where);
    Console.WriteLine($"{where}\n  -> {builder.GetFilter().Text}");
}

NUnit.Engine 3.18.1 (expected):

test == 'Repro.TupleOnly.Tuple((PROJECT, GLOBAL))'
  -> <filter><test>Repro.TupleOnly.Tuple((PROJECT, GLOBAL))</test></filter>
test == 'Repro.Shapes.StringArg("a b")'
  -> <filter><test>Repro.Shapes.StringArg(&quot;a b&quot;)</test></filter>
test == 'Repro.Shapes.SpaceBeforeParen (Case 1)'
  -> <filter><test>Repro.Shapes.SpaceBeforeParen (Case 1)</test></filter>

NUnit.Engine 3.22.0 (actual):

test == 'Repro.TupleOnly.Tuple((PROJECT, GLOBAL))'
  -> <filter><test>Repro.TupleOnly.Tuple((PROJECT,GLOBAL))</test></filter>
test == 'Repro.Shapes.StringArg("a b")'
  -> <filter><test>Repro.Shapes.StringArg(&quot;a b&quot;)</test></filter>
test == 'Repro.Shapes.SpaceBeforeParen (Case 1)'
  -> <filter><test>Repro.Shapes.SpaceBeforeParen(Case1)</test></filter>

End-to-end impact

NUnit3TestAdapter 6.x ships engine 3.22.0 and passes runsettings <NUnit><Where> through SelectWhere. With a <Where> listing such tests, adapter 5.1.0 (engine 3.18.1) runs all of them, while 6.3.1 and current main skip them. Swapping only the engine DLLs in a 5.1.0 output to 3.22.0 reproduces the skip, which points to the engine rather than the adapter.

Test 3.18.1 3.22.0
Tuple((PROJECT, GLOBAL)) (ValueTuple via TestCaseSource) runs skipped
SpaceBeforeParen (Case 1) (SetName) runs skipped
StringArg("a b") runs runs
TwoEnums(PROJECT,GLOBAL) runs runs

Environment: .NET 10, NUnit 4.6.1, macOS arm64. The repro also affects Linux CI.

Possibly related (adapter side, different code path): nunit/nunit3-vs-adapter#1490.

Activity

  1. CharliePoole commented on Oct 26, 2026

    @CharliePoole
    Member

    @nunit/engine-team @stryczekk The Needs Confirmation applies only to the current V4 build.

  2. added this to the 3.22.1 milestone on Oct 26, 2026
  3. oznetmaster commented on Oct 26, 2026

    @oznetmaster
    Collaborator

    @CharliePoole, @stryczekk, confirmed on the current v4 engine source at 3af18b3, under both Windows .NET 10 and .NET Framework 4.6.2. The production engine source used for this probe is unchanged from that upstream commit.

    Using the public ITestEngine / ITestFilterService path, SelectWhere produces the reported results:

    • Repro.TupleOnly.Tuple((PROJECT, GLOBAL)) becomes Repro.TupleOnly.Tuple((PROJECT,GLOBAL)).
    • Repro.Shapes.SpaceBeforeParen (Case 1) becomes Repro.Shapes.SpaceBeforeParen(Case1).
    • Repro.Shapes.StringArg("a b") retains its space.
    • A no-space TwoEnums(PROJECT,GLOBAL) control remains unchanged.

    Passing the same four names through AddTest preserves every name verbatim on both runtimes. This confirmation covers filter construction and the emitted XML, without involving an adapter or executing test assemblies.

    The source explains the difference: Tokenizer retains the quoted string, but TestSelectionParser.GetTestName then skips literal spaces outside nested double quotes in its TokenKind.String branch. That normalizes an already quoted literal before it is emitted as the test filter.

    https://github.com/nunit/nunit-console/blob/3af18b34bc32a349ce9dd649fbd09714dbc7ff4f/src/NUnitEngine/nunit.engine/Services/TestSelectionParser.cs

    I suggest regression cases at both the parser and public filter-builder boundary for tuple names and custom names containing spaces, while retaining the existing escaped-quote and unquoted-name compatibility cases.

    Prepared by Neil Colvin with assistance from OpenAI Codex.

  4. CharliePoole commented on Oct 26, 2026

    @CharliePoole
    Member

    Thanks @oznetmaster, confirmed now for both branches.

    @nunit/engine-team Looking for someone to take this on for 3.22.1. I didn't mark it critical (immediate release needed) but it does seem to be quite serious and is affecting the adapter as well. We'll want to migrate the fix to V4 as well.

  5. oznetmaster commented on Oct 26, 2026

    @oznetmaster
    Collaborator

    @CharliePoole, I can take this for 3.22.1, then port the fix to v4. I will keep it separate from the remote-provider work.

    I will add regressions at the parser and public filter-builder boundary for the reported tuple/custom names, preserve the existing escaped-quote and unquoted-name compatibility coverage, and verify the same expected filter values on both branches. The existing reproduction through the public API gives us a small starting point without an adapter-specific workaround.

    Prepared by Neil Colvin with assistance from OpenAI Codex.

  6. self-assigned this
    on Oct 26, 2026
  7. modified the milestones: 3.22.1, 3.23.0 on Nov 5, 2026
  8. CharliePoole commented on Nov 24, 2026

    @CharliePoole
    Member

    This issue has been resolved in version 3.23.0

    The release is available on:
    GitHub.
    NuGet packages are also available NuGet.org and
    Chocolatey Packages may be found at Chocolatey.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions