Repository navigation
feat: support dependency projects with project references - #25
Merged
Merged
Conversation
Add a public DependencyProject type and a BaseTestFixtureConfig.DependencyProjects option. Each dependency becomes a source project in the test workspace (with a ProjectDefinition, which the SDK's project reference manager requires) and the test project gets a project reference to it, so analyzers can be tested against callees declared in another workspace project. Without dependency projects the workspace setup is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…settings Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
BaseTestFixtureConfig.DependencyProjectsand a publicDependencyProjecttype, so a test can declare source projects that the test project references as workspace project references (the multi-project workspace setup of the AL editor). Objects from a dependency project resolve as source symbols declared in another module: theirDeclaringSyntaxReferencepoints into a syntax tree that is not part of the test project's compilation. This is needed to regression-test ALCops/Analyzers#614 (PC0029 throwsArgumentExceptionon such callees).DependencyProject(name, code)with optionalPublisher,Version,AppId(defaults to a new GUID per instance)./*EOD*/splits the code into documents.CreateDocumentFromCoderegisters each dependency project in the sameAdhocWorkspacebeforeTestProject, with aProjectDefinitionset throughProjectInfo.WithProjectDefinition(the SDK'sProjectReferencesReferenceManagerkeys the referenced module by that definition and throws an NRE when it is null). Each gets the test project's compilation options, metadata references, parse options, package cache paths and ruleset path, thenSolution.AddProjectReference(TestProject, new ProjectReference(depId, "<name>/app.json")).ProjectInfoCustomizerstill applies to the test project only (documented on the option).ProjectSettings.ProjectInfoCustomizerhook afterProjectInfo.Create, so bothAdhocWorkspacebranches (netstandard2.1 static call, net8+ reflection) work unchanged; no newProjectInfo.Createparameter.Configurable*fixtures; README option row + example;fixture-wiring.mdtable row and quirk note; CLAUDE.md config/public API lists.Validation
dotnet pack src/RoslynTestKit/RoslynTestKit.csproj -c Release -o ./artifacts: all three TFMs build; nupkg containslib/netstandard2.1/RoslynTestKit.dll,lib/net8.0/…,lib/net10.0/….1.6.0-local.1) in Analyzers (Directory.Packages.propspointed at it,-p:RestoreAdditionalProjectSources=<RoslynTestKit>/artifacts), net10.0:main: fails withAnalyzer 'ALCops.PlatformCop.Analyzers.UseSequentialGuid' threw ... System.ArgumentException: SyntaxTree 'table 50100 MyTable ...' not found to remove (Parameter 'syntaxTree') at Microsoft.Dynamics.Nav.CodeAnalysis.Compilation.GetSemanticModel(SyntaxTree syntaxTree) at ALCops.PlatformCop.Analyzers.UseSequentialGuid.TraceParameter(...) UseSequentialGuid.cs:line 298.if (!compilation.ContainsSyntaxTree(syntax.SyntaxTree)) return null;beforeGetSemanticModelinTraceParameter: passes; fulldotnet test ALCops.slngreen on the local pack (2188 tests), so the no-dependency path is unaffected.Temporary test (for reuse in the Analyzers fix PR):
Dependency app (
Dependency.al):Test app (
App.al):Code review (
/code-review high, Sonnet, 2 rounds)Round 1 fixed: empty
AppIdnow throwsArgumentException; README states dependency projects reuse the test project's compilation options/ruleset (notProjectInfoCustomizer) and that their compile errors are not checked byThrowsWhenInputDocumentContainsError.Round 2 produced no new code changes; additionally verified the code-fix path with a dependency project (local pack, PC0029
SimpleCreateGuidfix test with aDependencyProjectsentry passes, soApplyChangesOperationhandles the multi-project solution).Justified, not changed:
ProjectInfoCustomizernot applied to dependency projects: deliberate, documented; it targets the code under test.ThrowsWhenInputDocumentContainsErrorscoped to the input document; documented.ProjectDefinition/WithProjectDefinitionbinding: public and unchanged since 12.0 (Analyzers tests already bind it statically); the reflection branch exists only for the driftingProjectInfo.Createsignature, which this change does not touch. Builds against 12.0, 16.0 and 16.10.AddDocumentsvs. the main document loop: the main loop reverses segments to keep the first segment as the asserted document; dependency documents have no main document, so natural order is used.AddProjectthen the same chain); only a null-forgiving!was added.ProjectDefinitiononTestProject, no duplicate-name/AppId checks, mutableDependencyProject: out of scope until a test needs them.ProjectInfoCustomizerexample already uses one.Not verified locally
ProjectReferencesReferenceManagerbehaviour on SDK 12.0 (netstandard2.0): the lib compiles against 12.0, but the repro ran only on net10.0. The Analyzers SDK test legs are the evidence.🤖 Generated with Claude Code