Skip to content

Commit

Permalink
allow running a target with a name that another target name starts with
Browse files Browse the repository at this point in the history
  • Loading branch information
adamralph committed Oct 22, 2022
1 parent 6bbb266 commit 19a7ace
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Bullseye/Internal/TargetCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,13 @@ private static IEnumerable<string> Expand(this TargetCollection targets, IEnumer

foreach (var name in names)
{
var match = targets.SingleOrDefault(target => target.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
if (match != null)
{
yield return name;
continue;
}

var matches = targets.Where(target => target.Name.StartsWith(name, StringComparison.OrdinalIgnoreCase)).ToList();

if (matches.Count > 1)
Expand Down
20 changes: 20 additions & 0 deletions BullseyeTests/RunningTargets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ public static async Task TargetNameAbbreviation()
Assert.False(bar);
}

[Fact]
public static async Task TargetNameAbbreviationWithTargetMatchingAbbreviation()
{
// arrange
var (foo, foo1) = (false, false);

var targets = new TargetCollection
{
CreateTarget(nameof(foo), () => foo = true),
CreateTarget(nameof(foo1), () => foo1 = true),
};

// act
await targets.RunAsync(new List<string> { nameof(foo), }, _ => false, () => "", Console.Out, Console.Error, false);

// assert
Assert.True(foo);
Assert.False(foo1);
}

[Fact]
public static async Task AmbiguousTargetNameAbbreviation()
{
Expand Down

0 comments on commit 19a7ace

Please sign in to comment.