Skip to content

Commit 9f0d10b

Browse files
committed
Merge branch 'release/9.0.3xx' of https://github.com/dotnet/templating into merge/release/9.0.2xx-to-release/9.0.3xx
2 parents 6220a41 + 26a9018 commit 9f0d10b

File tree

6 files changed

+96
-4
lines changed
  • eng
  • src/Microsoft.TemplateEngine.Orchestrator.RunnableProjects
  • test
    • Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests
      • Approvals/TestSelectionForMultiChoicesWhenThereAreMultiplePartialMatchesAndOnePreciseMatch._.verified/TestAssets.TemplateWithMultipleChoicesAndPartialMatches
    • Microsoft.TemplateEngine.TestTemplates/test_templates/TemplateWithMultipleChoicesAndPartialMatches

6 files changed

+96
-4
lines changed

eng/Versions.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<VersionPrefix>9.0.205</VersionPrefix>
3+
<VersionPrefix>9.0.301</VersionPrefix>
44
<!-- When StabilizePackageVersion is set to 'true', this branch will produce stable outputs for 'Shipping' packages -->
55
<StabilizePackageVersion Condition="'$(StabilizePackageVersion)' == ''">true</StabilizePackageVersion>
66
<DotNetFinalVersionKind Condition="'$(StabilizePackageVersion)' == 'true'">release</DotNetFinalVersionKind>

src/Microsoft.TemplateEngine.Orchestrator.RunnableProjects/ParameterConverter.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ private static bool TryResolveChoiceValue(string? literal, ITemplateParameter pa
188188
}
189189

190190
string? partialMatch = null;
191+
bool multiplePartialMatches = false;
191192

192193
foreach (string choiceValue in param.Choices.Keys)
193194
{
@@ -205,13 +206,19 @@ private static bool TryResolveChoiceValue(string? literal, ITemplateParameter pa
205206
}
206207
else
207208
{
208-
// multiple partial matches, can't take one.
209-
match = null;
210-
return false;
209+
// Multiple partial matches, keep searching for exact match, fail if we don't find one
210+
// because we don't know which partial match we should select.
211+
multiplePartialMatches = true;
211212
}
212213
}
213214
}
214215

216+
if (multiplePartialMatches)
217+
{
218+
match = null;
219+
return false;
220+
}
221+
215222
match = partialMatch;
216223
return match != null;
217224
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ConsoleApp
2+
{
3+
internal class Program
4+
{
5+
static void Main(string[] args)
6+
{
7+
Console.WriteLine("User's choice is: aa.");
8+
}
9+
}
10+
}

test/Microsoft.TemplateEngine.Orchestrator.RunnableProjects.UnitTests/SnapshotTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,35 @@ public Task TestTemplateWithCircleDependencyInMacros()
273273
VerificationEngine engine = new VerificationEngine(_log);
274274
return engine.Execute(options);
275275
}
276+
277+
[Fact]
278+
public Task TestSelectionForMultiChoicesWhenThereAreMultiplePartialMatchesAndOnePreciseMatch()
279+
{
280+
string templateLocation = GetTestTemplateLocation("TemplateWithMultipleChoicesAndPartialMatches");
281+
var templateParams = new Dictionary<string, string?>()
282+
{
283+
// There are multiple choices for the parameter that overlap: "aab", "aac", "aa".
284+
// We want to ensure that "aa" can be selected, because it is a precise match,
285+
// even if there are more than one choices that start with "aa", and even if "aa",
286+
// is not listed first in the list of choices.
287+
{ "tests", "aa" }
288+
};
289+
string workingDir = TestUtils.CreateTemporaryFolder();
290+
291+
TemplateVerifierOptions options =
292+
new TemplateVerifierOptions(templateName: "TestAssets.TemplateWithMultipleChoicesAndPartialMatches")
293+
{
294+
TemplatePath = templateLocation,
295+
OutputDirectory = workingDir,
296+
DoNotAppendTemplateArgsToScenarioName = true,
297+
DoNotPrependTemplateNameToScenarioName = true,
298+
SnapshotsDirectory = "Approvals"
299+
}
300+
.WithInstantiationThroughTemplateCreatorApi(templateParams);
301+
302+
VerificationEngine engine = new VerificationEngine(_log);
303+
return engine.Execute(options);
304+
}
276305
}
277306
}
278307

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"$schema": "https://json.schemastore.org/template.json",
3+
"author": "Test Asset",
4+
"classifications": [ "Test Asset" ],
5+
"name": "TemplateWithMultipleChoicesAndPartialMatches",
6+
"tags": { "type": "project" },
7+
"generatorVersions": "[1.0.0.0-*)",
8+
"groupIdentity": "TestAssets.TemplateWithMultipleChoicesAndPartialMatches",
9+
"precedence": "100",
10+
"identity": "TestAssets.TemplateWithMultipleChoicesAndPartialMatches",
11+
"shortName": "TestAssets.TemplateWithMultipleChoicesAndPartialMatches",
12+
"symbols": {
13+
"tests": {
14+
"displayName": "Tests",
15+
"type": "parameter",
16+
"datatype": "choice",
17+
"replaces": "user_selectedtests",
18+
"allowMultipleValues": true,
19+
"enableQuotelessLiterals": true,
20+
"choices": [
21+
{
22+
"choice": "aab",
23+
"displayName": "aab"
24+
},
25+
{
26+
"choice": "aaa",
27+
"displayName": "aaa"
28+
},
29+
{
30+
"choice": "aa",
31+
"displayName": "aa"
32+
}
33+
]
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace ConsoleApp
2+
{
3+
internal class Program
4+
{
5+
static void Main(string[] args)
6+
{
7+
Console.WriteLine("User's choice is: user_selectedtests.");
8+
}
9+
}
10+
}

0 commit comments

Comments
 (0)