-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend Templates testing framework to test through API #5677
Conversation
UniqueFor = UniqueForOption.Architecture, | ||
} | ||
.WithInstantiationThroughTemplateCreatorApi(new Dictionary<string, string?>() { { "paramB", "true" } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YuliiaKovalova this can be inspiration how the imported sample templates might be tested (only templateName
, TemplatePath
and WithInstantiationThroughTemplateCreatorApi
will be needed - rest is here to unit test the actual testing functionality)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider using IDE.Bootstrapper
or full e2e via Edge
for installing, loading and running the template.
The current logic likely deviates too much from regular experience, also doesn't support all the cases.
...IntegrationTests/Microsoft.TemplateEngine.Authoring.TemplateVerifier.IntegrationTests.csproj
Outdated
Show resolved
Hide resolved
src/Microsoft.TemplateEngine.Orchestrator.RunnableProjects/Global.cs
Outdated
Show resolved
Hide resolved
@@ -18,7 +19,10 @@ public sealed class DefaultEnvironment : IEnvironment | |||
private const int DefaultBufferWidth = 160; | |||
private readonly IReadOnlyDictionary<string, string> _environmentVariables; | |||
|
|||
public DefaultEnvironment() | |||
public DefaultEnvironment() : this(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a thought - would it be better to do own implementation? Maybe something as ExtendedEnvironment
?
another thought: https://github.com/dotnet/sdk/blob/main/src/Cli/Microsoft.TemplateEngine.Cli/CliEnvironment.cs we can get rid of this custom implementation with this class now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There were few options:
- Unseal the
DefaultEnvironment
and extend. - Copy paste
DefaultEnvironment
logic and add custom logic - Add the logic into
DefaultEnvironment
The last one felt as the one with least dept incured. Though I might miss some obvious reason why it might not be an optional choice - so I'm open to alternative thoughts :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference is the first one, just to intentionally keep it separate, so it is not misused, however I don't insist.
/// <summary> | ||
/// Exit code of the action (e.g. exit code of the dotnet new command). | ||
/// 0 indicates successful action. Nonzero otherwise. | ||
/// </summary> | ||
int ExitCode { get; } | ||
|
||
/// <summary> | ||
/// Standard output stream content for the instantiation action. | ||
/// </summary> | ||
string StdOut { get; } | ||
|
||
/// <summary> | ||
/// Standard error stream content for the instantiation action. | ||
/// </summary> | ||
string StdErr { get; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a thought - does it make sense to be in an a separate interface?
IInstantiationResult
ICLIInstantiationResult
: IInstantiationResult
.../Microsoft.TemplateEngine.Authoring.TemplateApiVerifier/TemplateVerifierOptionsExtensions.cs
Outdated
Show resolved
Hide resolved
Example using templating/test/Microsoft.TemplateEngine.IDE.IntegrationTests/End2EndTests.cs Lines 19 to 26 in 301c232
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Half way through, left some comments in, mostly typos.
/// <returns><see cref="ITemplateCreationResult"/> containing information on created template or error occurred.</returns> | ||
#pragma warning disable RS0027 // Public API with optional parameter(s) should have the most parameters amongst its public overloads | ||
#pragma warning disable RS0026 // Do not add multiple public overloads with optional parameters | ||
public Task<ITemplateCreationResult> CreateAsync( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a thought - should we make other one obsolete?
also we are hardly using baselines, not sure if we should keep it and leave the warning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other CreateAsync
(with params as dictionary) has legitimate use for quick testing with set of params - I'd keep it as is
@@ -18,7 +19,10 @@ public sealed class DefaultEnvironment : IEnvironment | |||
private const int DefaultBufferWidth = 160; | |||
private readonly IReadOnlyDictionary<string, string> _environmentVariables; | |||
|
|||
public DefaultEnvironment() | |||
public DefaultEnvironment() : this(null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference is the first one, just to intentionally keep it separate, so it is not misused, however I don't insist.
tools/Microsoft.TemplateEngine.Authoring.TemplateApiVerifier/LocalizableStrings.resx
Outdated
Show resolved
Hide resolved
tools/Microsoft.TemplateEngine.Authoring.TemplateApiVerifier/LocalizableStrings.resx
Outdated
Show resolved
Hide resolved
tools/Microsoft.TemplateEngine.Authoring.TemplateApiVerifier/LocalizableStrings.resx
Outdated
Show resolved
Hide resolved
tools/Microsoft.TemplateEngine.Authoring.TemplateApiVerifier/LocalizableStrings.resx
Outdated
Show resolved
Hide resolved
tools/Microsoft.TemplateEngine.Authoring.TemplateApiVerifier/LocalizableStrings.resx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completed review - looks good, couple of minor comments and maybe some possible improvements for future.
.../Microsoft.TemplateEngine.Authoring.TemplateApiVerifier/TemplateVerifierOptionsExtensions.cs
Outdated
Show resolved
Hide resolved
result.Status == CreationResultStatus.Success ? string.Format(LocalizableStrings.CreateSuccessful, result.TemplateFullName) : string.Empty, | ||
result.ErrorMessage ?? string.Empty, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible improvement: redirect logging here (info - output, error + warning - error).
/backport to release/7.0.2xx |
Started backporting to release/7.0.2xx: https://github.com/dotnet/templating/actions/runs/3686675295 |
@JanKrivanek backporting to release/7.0.2xx failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Extend Templates testing framework to test through API
Applying: Reuse bootstrapper class
Applying: Bugfix after merge
error: sha1 information is lacking or useless (src/Microsoft.TemplateEngine.Edge/PublicAPI.Unshipped.txt).
error: could not build fake ancestor
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0003 Bugfix after merge
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@JanKrivanek an error occurred while backporting to release/7.0.2xx, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
* Extend Templates testing framework to test through API * Reuse bootstrapper class * Bugfix after merge * Reflect PR comments * Add forgotten changes
/backport to release/7.0.2xx |
Started backporting to release/7.0.2xx: https://github.com/dotnet/templating/actions/runs/3697375728 |
@JanKrivanek backporting to release/7.0.2xx failed, the patch most likely resulted in conflicts: $ git am --3way --ignore-whitespace --keep-non-patch changes.patch
Applying: Extend Templates testing framework to test through API
.git/rebase-apply/patch:296: trailing whitespace.
.git/rebase-apply/patch:297: trailing whitespace.
.git/rebase-apply/patch:309: trailing whitespace.
.git/rebase-apply/patch:311: trailing whitespace.
.git/rebase-apply/patch:313: trailing whitespace.
warning: squelched 36 whitespace errors
warning: 41 lines add whitespace errors.
Using index info to reconstruct a base tree...
M tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/TemplateVerifierOptions.cs
M tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs
Falling back to patching base and 3-way merge...
Auto-merging tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs
CONFLICT (content): Merge conflict in tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/VerificationEngine.cs
Auto-merging tools/Microsoft.TemplateEngine.Authoring.TemplateVerifier/TemplateVerifierOptions.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Extend Templates testing framework to test through API
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128 Please backport manually! |
@JanKrivanek an error occurred while backporting to release/7.0.2xx, please check the run log for details! Error: git am failed, most likely due to a merge conflict. |
* Extend Templates testing framework to test through API * Reuse bootstrapper class * Bugfix after merge * Reflect PR comments * Add forgotten changes
Problem
We are missing ability to leverage Templates Testing Tooling from within the Template Engine repository
This might be needed during moving samples: #2522
Solution
Extend
TemplateVerifier
to allow for custom instantiation callbackAdd separate extension implementation performing instantiation through
TemplateCreator
API (not included withinTemplateVerifier
project to minimize dependecy pull for external scenarios)Checks:
#nullable enable
to all the modified files ?