dotnet-format unit tests are not running in CI — 3 pre-existing failures discovered
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
## Summary
The `dotnet-format.UnitTests` project was excluded from Helix CI runs via `test/UnitTests.proj`:
```xml
```
However, the "DOTNET_FORMAT pipeline section" (`eng/dotnet-format/`) only ran **integration tests** (cloning external repos and running `dotnet format` against them). The unit tests were never actually executed in CI.
When trying to enable the tests, 3 pre-existing failures were discovered across all platforms.
## Failing Tests
### 1. `CodeStyleAnalyzerFormatterTests.TestUseVarCodeStyle_AppliesWhenNotUsingVar`
**Platforms:** All (Linux, Windows, macOS x64, macOS arm64, Windows FullFramework)
The test configures `csharp_style_var_for_built_in_types`, `csharp_style_var_when_type_is_apparent`, and `csharp_style_var_elsewhere` all to `true:error` with `IDE0007` severity set to `error`. It expects all 3 variable declarations to be converted to `var`:
```csharp
// Input
object obj = new object();
List list = new List();
int count = 5;
// Expected (all converted to var)
var obj = new object();
var list = new List();
var count = 5;
```
**Actual behavior:** Only `object obj` is converted to `var obj`. `List list` and `int count` are left unchanged. This indicates Roslyn's IDE0007 code fix behavior has changed — it no longer applies `var` to all cases in a single formatting pass despite the editorconfig settings.
**Assertion failure:**
```
Assert.Equal() Failure: Strings differ
↓ (pos 105)
Expected: ···" = new object();\n var list = new List list = new L"···
```
### 2. `CodeFormatterTests.FSharpProjectsDoNotCreateException`
**Platforms:** All (Linux, Windows, macOS x64, macOS arm64, Windows FullFramework)
The test formats an F# project and expects exit code `1` (error) since F# is unsupported. The formatter logs `"Format currently supports only C# and Visual Basic projects"` as expected, but now returns exit code `0` (success) instead of `1`.
**Assertion failure:**
```
Assert.Equal() Failure: Values differ
Expected: 1
Actual: 0
```
The formatter's behavior changed — it now treats unsupported F# projects as a non-error condition. See also: https://github.com/dotnet/sdk/issues/53258
### 3. `MSBuildWorkspaceLoaderTests.CSharpTemplateProject_LoadWithNoDiagnostics(templateName: "blazorwasm")`
**Platforms:** Linux, Windows (both TestBuild and FullFramework)
The test generates a `blazorwasm` template project, loads it via `MSBuildWorkspaceLoader`, and asserts zero compiler diagnostics above `Hidden` severity. The workspace load produces a CS0012 error:
```
CS0012: The type 'IServiceCollection' is defined in an assembly that is not referenced.
You must add a reference to assembly 'Microsoft.Extensions.DependencyInjection.Abstractions,
Version=11.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
```
This indicates the `blazorwasm` template generates a project that references `IServiceCollection` but the `MSBuildWorkspaceLoader` doesn't resolve `Microsoft.Extensions.DependencyInjection.Abstractions` v11.0.0.0 correctly during compilation.
## Build Reference
- [Build 1413969](https://dev.azure.com/dnceng-public/public/_build/results?buildId=1413969&view=results) (PR #54231)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.