{"id":23878313,"url":"https://github.com/jscarle/sourcegeneratortesthelpers","last_synced_at":"2025-09-09T04:32:42.103Z","repository":{"id":223706623,"uuid":"761303874","full_name":"jscarle/SourceGeneratorTestHelpers","owner":"jscarle","description":"Test helpers and extension methods to simplify testing of .NET source generators.","archived":false,"fork":false,"pushed_at":"2024-05-13T21:54:15.000Z","size":80,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-16T08:32:00.380Z","etag":null,"topics":["csharp","dotnet","source-generators","testing"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jscarle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"jscarle"}},"created_at":"2024-02-21T16:09:37.000Z","updated_at":"2024-07-30T03:32:03.820Z","dependencies_parsed_at":"2024-02-21T17:29:15.175Z","dependency_job_id":"ba188161-acd7-46dc-aaf4-579dfee642fa","html_url":"https://github.com/jscarle/SourceGeneratorTestHelpers","commit_stats":null,"previous_names":["jscarle/sourcegeneratortesthelpers"],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jscarle%2FSourceGeneratorTestHelpers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jscarle%2FSourceGeneratorTestHelpers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jscarle%2FSourceGeneratorTestHelpers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jscarle%2FSourceGeneratorTestHelpers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jscarle","download_url":"https://codeload.github.com/jscarle/SourceGeneratorTestHelpers/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232395327,"owners_count":18516611,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","source-generators","testing"],"created_at":"2025-01-03T21:19:27.677Z","updated_at":"2025-01-03T21:19:28.307Z","avatar_url":"https://github.com/jscarle.png","language":"C#","funding_links":["https://github.com/sponsors/jscarle"],"categories":[],"sub_categories":[],"readme":"# Source Generator Test Helpers\n\nTest helpers and extension methods to simplify testing of .NET source generators.\n\n[![main](https://img.shields.io/github/actions/workflow/status/jscarle/SourceGeneratorTestHelpers/main.yml?logo=github)](https://github.com/jscarle/SourceGeneratorTestHelpers)\n[![nuget](https://img.shields.io/nuget/v/SourceGeneratorTestHelpers)](https://www.nuget.org/packages/SourceGeneratorTestHelpers)\n[![downloads](https://img.shields.io/nuget/dt/SourceGeneratorTestHelpers)](https://www.nuget.org/packages/SourceGeneratorTestHelpers)\n\n## Testing a source generator\n\n```csharp\nvar result = SourceGenerator.Run\u003cYourSourceGenerator\u003e(\"your source\");\n```\n\n## Testing an incremental source generator\n\n```csharp\nvar result = IncrementalGenerator.Run\u003cYourSourceGenerator\u003e(\"your source\");\n```\n\n## Obtaining the generated source\n\n### Getting all generated sources\n\n```csharp\nvar generatedSources =  result.GetSources();\n```\n\n### A single source that ends with a specific file path\n\n```csharp\nvar generatedSource =  result.GetSource(\"TestId.g.cs\");\n```\n\n### Compare the generated source with the expected source\n\nYou can produce a diff between the generated source and the expected source. The result will contain a boolean `hasDifferences` and a line by line diff\nin `differences`.\n\n```csharp\nvar (hasDifferences, differences) = Diff.Compare(generatedSource, expectedSource);\n```\n\n## Assert the difference\n\nUsing one of the testing framework packages below, you can also assert the difference between the generated source and the expected source.\n\n[![XUnit](https://img.shields.io/nuget/dt/SourceGeneratorTestHelpers.XUnit?label=XUnit)](https://www.nuget.org/packages/SourceGeneratorTestHelpers.XUnit)\n[![NUnit](https://img.shields.io/nuget/dt/SourceGeneratorTestHelpers.NUnit?label=NUnit)](https://www.nuget.org/packages/SourceGeneratorTestHelpers.NUnit)\n[![MSTest](https://img.shields.io/nuget/dt/SourceGeneratorTestHelpers.MSTest?label=MSTest)](https://www.nuget.org/packages/SourceGeneratorTestHelpers.MSTest)\n\n```csharp\nvar result = IncrementalGenerator.Run\u003cYourSourceGenerator\u003e(\"your source\");\n\nresult.ShouldProduce(\"TestId.g.cs\", \"expected source\");\n```\n\n_Note: If you do not wish to assert on errors produced during diagnostics of the source generator run, you can simply disable them as such._\n\n```csharp\nvar result = IncrementalGenerator.Run\u003cYourSourceGenerator\u003e(\"your source\");\n\nresult.ShouldProduce(\"TestId.g.cs\", \"expected source\", false);\n```\n\n### Verify the difference\n\nSupport for [Verify](https://github.com/VerifyTests/Verify) is built-in using the `VerifyAsync` method.\n\n#### XUnit\n\n```cs\npublic class SourceGeneratorTests\n{\n    [Fact]\n    public Task ShouldProductTestId()\n    {\n        var result = IncrementalGenerator.Run\u003cYourSourceGenerator\u003e(\"your source\");\n        return result.VerifyAsync(\"TestId.g.cs\");\n    }\n}\n```\n\n#### NUnit\n\n```cs\n[TestFixture]\npublic class SourceGeneratorTests\n{\n    [Test]\n    public Task ShouldProductTestId()\n    {\n        var result = IncrementalGenerator.Run\u003cYourSourceGenerator\u003e(\"your source\");\n        return result.VerifyAsync(\"TestId.g.cs\");\n    }\n}\n```\n\n#### MSTest\n\n```cs\n[TestClass]\npublic class SourceGeneratorTests :\n    GeneratorDriverTestBase\n{\n    [TestMethod]\n    public Task ShouldProductTestId()\n    {\n        var result = IncrementalGenerator.Run\u003cYourSourceGenerator\u003e(\"your source\");\n        return VerifyAsync(\"TestId.g.cs\");\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjscarle%2Fsourcegeneratortesthelpers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjscarle%2Fsourcegeneratortesthelpers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjscarle%2Fsourcegeneratortesthelpers/lists"}