-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fail when #:project doesn't have any argument
#49711
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
Conversation
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.
Pull Request Overview
This PR ensures that the #:project directive fails when no argument is provided by updating the parsing logic and test coverage.
- Adds
"project"to the empty-name directive test to verify failure for project directives. - Extends
Project.Parsesignature to includedirectiveKind, checks for whitespace/empty names, and reports a missing-name error. - Updates the directive dispatch in
CSharpDirectiveto call the new overload ofProject.Parse.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs | Include "project" in Directives_EmptyName theory |
| src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs | Fix call site to use new Project.Parse overload and add check for empty directive name |
Comments suppressed due to low confidence (3)
test/dotnet.Tests/CommandTests/Project/Convert/DotnetProjectConvertTests.cs:813
- Consider adding an assertion that inspects the thrown error's message to verify the
MissingDirectiveNameformatting for theprojectdirective, ensuring the correct error text is emitted.
[CombinatorialValues("sdk", "property", "package", "project")] string directive,
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs:1216
- [nitpick] The
newmodifier hides a potentialParsemethod in the base class (Named). Verify whether the base class defines a staticParseand removenewif hiding is unintentional.
public static new Project? Parse(ImmutableArray<SimpleDiagnostic>.Builder? errors, SourceFile sourceFile, TextSpan span, string directiveKind, string directiveText)
src/Cli/dotnet/Commands/Run/VirtualProjectBuildingCommand.cs:1057
- Double-check that all other invocations of
Project.Parsehave been updated to the new four-parameter overload to prevent missing-method compilation errors elsewhere.
"project" => Project.Parse(errors, sourceFile, span, directiveKind, directiveText),
| [Theory, CombinatorialData] | ||
| public void Directives_EmptyName( | ||
| [CombinatorialValues("sdk", "property", "package")] string directive, | ||
| [CombinatorialValues("sdk", "property", "package", "project")] string directive, |
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.
A virtual project will still be produced in this case right? I guess we also do that for the empty name cases for the other directives listed here.
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.
In case of run-api, yes, that one collects all errors and produces the virtual project file (without directives that have errors), there are tests for that in general (Api_Diagnostic_*), albeit not this particular case. In case of other commands like run, the first error makes the whole command fail, so there is no virtual project produced.
Fixes #49670.