Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions .codetesting/AnalysisReport_20251009_233646_119.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Test Failures due possible code bugs

## SourceGen.UnitTests.csproj - GetWarningDisable_NullXmlDocument_ThrowsArgumentNullException
- **Confidence**: High
- **Test File**: src/Controls/tests/SourceGen.UnitTests/CodeBehindCodeWriterTests.cs
- **Bug Location**: src/Controls/src/SourceGen/CodeBehindCodeWriter.cs@379

### Analysis
The test correctly expects ArgumentNullException when a null XmlDocument is passed to GetWarningDisable method. However, the production code doesn't validate the parameter and instead throws NullReferenceException when trying to call SelectNodes on the null xmlDoc parameter. The method should include proper parameter validation.

### Suggested Fix
The GetWarningDisable method needs parameter validation added at the beginning. Add this code at the start of the method (line 377): `if (xmlDoc == null) throw new ArgumentNullException(nameof(xmlDoc));`. This will ensure that the method throws the expected ArgumentNullException instead of allowing a NullReferenceException to occur later.

## SourceGen.UnitTests.csproj - GetWarningDisable_WhitespaceWarningDisableValue_PreservesWhitespace
- **Confidence**: High
- **Test File**: src/Controls/tests/SourceGen.UnitTests/CodeBehindCodeWriterTests.cs
- **Bug Location**: src/Controls/src/SourceGen/CodeBehindCodeWriter.cs@384

### Analysis
The production code has a bug in the parsing logic. The GetWarningDisable method splits the processing instruction data on both spaces and equals signs, which fails when the warning-disable value contains spaces (like whitespace-only values). When parsing 'warning-disable=" "', it splits into ['warning-disable', '"', '', '"'] and returns an empty string after trimming quotes, instead of preserving the two spaces inside the quotes. The parsing logic needs to be improved to handle quoted values that contain spaces.

### Suggested Fix
The GetWarningDisable method needs to be rewritten to properly parse attribute-value pairs in processing instructions. Instead of splitting on both spaces and equals signs, it should use a more sophisticated parsing approach that respects quoted values. One approach would be to use regular expressions to match 'warning-disable="value"' or 'warning-disable='value'' patterns, or implement a proper attribute parser that handles quoted strings correctly. The current implementation at line 384 `var parts = xpi.Data.Split(' ', '=');` should be replaced with logic that can parse `key="value"` pairs while preserving the content inside quotes.

## SourceGen.UnitTests.csproj - GetHashCode_NullCompilation_ThrowsArgumentNullException
- **Confidence**: High
- **Test File**: src/Controls/tests/SourceGen.UnitTests/CompilationReferencesComparerTests.cs
- **Bug Location**: src/Controls/src/SourceGen/CompilationReferencesComparer.cs@20

### Analysis
The test correctly expects ArgumentNullException when GetHashCode is called with a null Compilation parameter. However, the production code at line 20 directly accesses obj.References without null checking, causing a NullReferenceException instead. The GetHashCode method should validate its parameter and throw ArgumentNullException for null inputs, which is standard .NET practice.

### Suggested Fix
The GetHashCode method needs null parameter validation. Change line 20 from `public int GetHashCode(Compilation obj) => obj.References.GetHashCode();` to `public int GetHashCode(Compilation obj) => obj?.References?.GetHashCode() ?? throw new ArgumentNullException(nameof(obj));` or add explicit null checking: `if (obj == null) throw new ArgumentNullException(nameof(obj)); return obj.References.GetHashCode();`

## SourceGen.UnitTests.csproj - CreateUniqueVariableName_NullContext_ThrowsArgumentNullException
- **Confidence**: High
- **Test File**: src/Controls/tests/SourceGen.UnitTests/NamingHelpersTests.cs
- **Bug Location**: src/Controls/src/SourceGen/NamingHelpers.cs@15

### Analysis
The test correctly expects that passing null for the context parameter should throw ArgumentNullException. However, the production code in CreateUniqueVariableName method doesn't validate the context parameter before using it. At line 15, it tries to access context.ParentContext without checking if context is null first, which causes a NullReferenceException instead of the expected ArgumentNullException. The production code should validate its parameters and throw ArgumentNullException for null arguments.

### Suggested Fix
The CreateUniqueVariableName method should validate its parameters at the beginning. Add parameter validation before accessing context.ParentContext:

```csharp
public static string CreateUniqueVariableName(SourceGenContext context, ISymbol symbol)
{
if (context == null)
throw new ArgumentNullException(nameof(context));
if (symbol == null)
throw new ArgumentNullException(nameof(symbol));

while (context.ParentContext != null)
context = context.ParentContext;

return CreateUniqueVariableNameImpl(context, symbol);
}
```

24 changes: 24 additions & 0 deletions .codetesting/AnalysisReport_20251010_135050_006.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Test Failures due possible code bugs

## SourceGen.UnitTests.csproj - GetWarningDisable_ComplexXmlStructure_ProcessesOnlyXamlCompInstructions
- **Confidence**: High
- **Test File**: src/Controls/tests/SourceGen.UnitTests/CodeBehindCodeWriterTests.cs
- **Bug Location**: src/Controls/src/SourceGen/CodeBehindCodeWriter.cs@379

### Analysis
The production code uses the XPath query 'processing-instruction('xaml-comp')' which only finds processing instructions at the document level, not those nested within elements. The test XML has two xaml-comp processing instructions: one at the document level and one inside the root element. The current XPath only finds the first one. The XPath should be '//processing-instruction('xaml-comp')' to find all xaml-comp processing instructions anywhere in the document.

### Suggested Fix
In the GetWarningDisable method at line 379, change the XPath query from 'processing-instruction('xaml-comp')' to '//processing-instruction('xaml-comp')' to find all xaml-comp processing instructions anywhere in the XML document, not just at the document root level.

## SourceGen.UnitTests.csproj - GetWarningDisable_WhitespaceOnlyAfterTrimming_PreservesWhitespace
- **Confidence**: High
- **Test File**: src/Controls/tests/SourceGen.UnitTests/CodeBehindCodeWriterTests.cs
- **Bug Location**: src/Controls/src/SourceGen/CodeBehindCodeWriter.cs@384

### Analysis
The production code has a bug in the parsing logic at line 384. When splitting the processing instruction data by both space and equals characters, it incorrectly breaks apart quoted values that contain spaces. For the input 'warning-disable=" "', the split operation produces ['warning-disable', '"', '', '', '"'] instead of preserving the quoted whitespace content. The code then takes the element after 'warning-disable' which is '"' and after trimming quotes becomes an empty string, when it should preserve the original ' ' (three spaces) content.

### Suggested Fix
The GetWarningDisable method needs to be fixed to properly parse quoted values containing spaces. The current split logic at line 384 `var parts = xpi.Data.Split(' ', '=');` should be replaced with more sophisticated parsing that respects quoted strings. A possible fix would be to use regular expressions or a proper key-value parser that handles quoted values. For example, use a pattern like `warning-disable\s*=\s*["']([^"']*)["']` to extract the quoted value directly, or implement a parser that doesn't split within quoted strings.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;


using Microsoft.CodeAnalysis;
using Microsoft.Maui.Controls.SourceGen;
using Moq;
using NUnit.Framework;

namespace Microsoft.Maui.Controls.SourceGen.UnitTests;



/// <summary>
/// Unit tests for the AttributeDataExtensions.IsInherited extension method.
/// </summary>
[TestFixture]
public class AttributeDataExtensionsTests
{
}
Loading
Loading