Skip to content

feat: support dependency projects with project references - #25

Merged
Arthurvdv merged 2 commits into
masterfrom
feat/dependency-projects
Nov 16, 2026
Merged

Arthurvdv merged 2 commits into
masterfrom
feat/dependency-projects

Conversation

@Arthurvdv

@Arthurvdv Arthurvdv commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds BaseTestFixtureConfig.DependencyProjects and a public DependencyProject type, 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: their DeclaringSyntaxReference points into a syntax tree that is not part of the test project's compilation. This is needed to regression-test ALCops/Analyzers#614 (PC0029 throws ArgumentException on such callees).

  • DependencyProject(name, code) with optional Publisher, Version, AppId (defaults to a new GUID per instance). /*EOD*/ splits the code into documents.
  • CreateDocumentFromCode registers each dependency project in the same AdhocWorkspace before TestProject, with a ProjectDefinition set through ProjectInfo.WithProjectDefinition (the SDK's ProjectReferencesReferenceManager keys 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, then Solution.AddProjectReference(TestProject, new ProjectReference(depId, "<name>/app.json")).
  • ProjectInfoCustomizer still applies to the test project only (documented on the option).
  • The definition is applied through the existing ProjectSettings.ProjectInfoCustomizer hook after ProjectInfo.Create, so both AdhocWorkspace branches (netstandard2.1 static call, net8+ reflection) work unchanged; no new ProjectInfo.Create parameter.
  • Wired in all four Configurable* fixtures; README option row + example; fixture-wiring.md table row and quirk note; CLAUDE.md config/public API lists.
  • No dependency projects: same single-project workspace setup as before. No new static state.

Validation

  • dotnet pack src/RoslynTestKit/RoslynTestKit.csproj -c Release -o ./artifacts: all three TFMs build; nupkg contains lib/netstandard2.1/RoslynTestKit.dll, lib/net8.0/…, lib/net10.0/….
  • End to end with a local pack (1.6.0-local.1) in Analyzers (Directory.Packages.props pointed at it, -p:RestoreAdditionalProjectSources=<RoslynTestKit>/artifacts), net10.0:
    • Temporary PC0029 test below on unchanged Analyzers main: fails with
      Analyzer '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.
    • With if (!compilation.ContainsSyntaxTree(syntax.SyntaxTree)) return null; before GetSemanticModel in TraceParameter: passes; full dotnet test ALCops.sln green on the local pack (2188 tests), so the no-dependency path is unaffected.
    • All Analyzers changes reverted afterwards.

Temporary test (for reuse in the Analyzers fix PR):

using RoslynTestKit;

namespace ALCops.PlatformCop.Test
{
    public class UseSequentialGuidCrossProjectTmp : NavCodeAnalysisBase
    {
        [Test]
        public async Task CrossProjectCallee()
        {
            RequireMinimumVersion("16.0", "Available with runtime version 16.0.");

            var path = Path.Combine(
                Directory.GetParent(Environment.CurrentDirectory)!.Parent!.Parent!.FullName,
                "Rules", "UseSequentialGuid", "CrossProjectTmp");
            var dependencyCode = await File.ReadAllTextAsync(Path.Combine(path, "Dependency.al")).ConfigureAwait(false);
            var code = await File.ReadAllTextAsync(Path.Combine(path, "App.al")).ConfigureAwait(false);

            var fixture = RoslynFixtureFactory.Create<Analyzers.UseSequentialGuid>(
                new AnalyzerTestFixtureConfig
                {
                    DependencyProjects = [new DependencyProject("DependencyApp", dependencyCode)]
                });

            fixture.NoException(code);
        }
    }
}

Dependency app (Dependency.al):

table 50100 MyTable
{
    fields
    {
        field(1; "Run Id"; Guid) { }
    }

    keys
    {
        key(PK; "Run Id") { }
    }
}

codeunit 50100 MyWorker
{
    procedure Build(RunId: Guid)
    var
        MyTable: Record MyTable;
    begin
        MyTable."Run Id" := RunId;
        MyTable.Insert();
    end;
}

Test app (App.al):

codeunit 50110 MyCaller
{
    procedure Execute()
    var
        Worker: Codeunit MyWorker;
        RunId: Guid;
    begin
        RunId := CreateGuid();
        Worker.Build(RunId);
    end;
}

Code review (/code-review high, Sonnet, 2 rounds)

Round 1 fixed: empty AppId now throws ArgumentException; README states dependency projects reuse the test project's compilation options/ruleset (not ProjectInfoCustomizer) and that their compile errors are not checked by ThrowsWhenInputDocumentContainsError.

Round 2 produced no new code changes; additionally verified the code-fix path with a dependency project (local pack, PC0029 SimpleCreateGuid fix test with a DependencyProjects entry passes, so ApplyChangesOperation handles the multi-project solution).

Justified, not changed:

  • ProjectInfoCustomizer not applied to dependency projects: deliberate, documented; it targets the code under test.
  • Dependency compile errors not reported: consistent with ThrowsWhenInputDocumentContainsError scoped to the input document; documented.
  • Static ProjectDefinition / WithProjectDefinition binding: public and unchanged since 12.0 (Analyzers tests already bind it statically); the reflection branch exists only for the drifting ProjectInfo.Create signature, which this change does not touch. Builds against 12.0, 16.0 and 16.10.
  • AddDocuments vs. 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.
  • Multi-pass setup / "path unchanged": with no dependency projects the calls are identical (AddProject then the same chain); only a null-forgiving ! was added.
  • No dependency-to-dependency references, no ProjectDefinition on TestProject, no duplicate-name/AppId checks, mutable DependencyProject: out of scope until a test needs them.
  • C# 12 collection expression in the README example: the existing ProjectInfoCustomizer example already uses one.

Not verified locally

ProjectReferencesReferenceManager behaviour 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

Arthurvdv and others added 2 commits November 16, 2026 17:58
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>
@Arthurvdv
Arthurvdv merged commit 35fe5ba into master Nov 16, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant