Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsPropertyFromObservable.g.cs
//HintName: TestNs.TestVM.ObservableAsPropertyFromObservable.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsPropertyFromObservable.g.cs
//HintName: TestNs.TestVM.ObservableAsPropertyFromObservable.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsPropertyFromObservable.g.cs
//HintName: TestNs.TestVM.ObservableAsPropertyFromObservable.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsPropertyFromObservable.g.cs
//HintName: TestNs.TestVM.ObservableAsPropertyFromObservable.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsPropertyFromObservable.g.cs
//HintName: TestNs.TestVM.ObservableAsPropertyFromObservable.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsPropertyFromObservable.g.cs
//HintName: TestNs.TestVM.ObservableAsPropertyFromObservable.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsPropertyFromObservable.g.cs
//HintName: TestNs.TestVM.ObservableAsPropertyFromObservable.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsProperties.g.cs
//HintName: TestNs.TestVM.ObservableAsProperties.g.cs
// <auto-generated/>
#pragma warning disable
#nullable enable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsProperties.g.cs
//HintName: TestNs.TestVM.ObservableAsProperties.g.cs
// <auto-generated/>
#pragma warning disable
#nullable enable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.ObservableAsProperties.g.cs
//HintName: TestNs.TestVM.ObservableAsProperties.g.cs
// <auto-generated/>
#pragma warning disable
#nullable enable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.Properties.g.cs
//HintName: TestNs.TestVM.Properties.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.Properties.g.cs
//HintName: TestNs.TestVM.Properties.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.Properties.g.cs
//HintName: TestNs.TestVM.Properties.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//HintName: TestVM.Properties.g.cs
//HintName: TestNs.TestVM.Properties.g.cs
// <auto-generated/>
using ReactiveUI;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//HintName: ReactiveUI.SourceGenerators.AccessModifier.g.cs
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

// <auto-generated/>
#pragma warning disable
#nullable enable
namespace ReactiveUI.SourceGenerators;

/// <summary>
/// AccessModifier.
/// </summary>
internal enum AccessModifier
{
Public,
Protected,
Internal,
Private,
InternalProtected,
PrivateProtected,
}

/// <summary>
/// InheritanceModifier.
/// </summary>
internal enum InheritanceModifier
{
None,
Virtual,
Override,
New,
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//HintName: ReactiveUI.SourceGenerators.ReactiveAttribute.g.cs
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System;

// <auto-generated/>
#pragma warning disable
#nullable enable
namespace ReactiveUI.SourceGenerators;

/// <summary>
/// ReactiveAttribute.
/// </summary>
/// <seealso cref="Attribute" />
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
internal sealed class ReactiveAttribute : Attribute
{
/// <summary>
/// Gets the AccessModifier of the set property.
/// </summary>
/// <value>
/// The AccessModifier of the set property.
/// </value>
public AccessModifier SetModifier { get; init; }

/// <summary>
/// Gets the InheritanceModifier of the property.
/// </sumary>
public InheritanceModifier Inheritance { get; init; }
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//HintName: TestNs1.TestVM.Properties.g.cs
// <auto-generated/>
using ReactiveUI;

#pragma warning disable
#nullable enable

namespace TestNs1
{
/// <summary>
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
/// </summary>
public partial class TestVM
{
/// <inheritdoc cref="_name"/>
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Runtime.Serialization.DataMemberAttribute()]
[global::System.Text.Json.Serialization.JsonIncludeAttribute()]
public string? Name { get => _name; set => this.RaiseAndSetIfChanged(ref _name, value); }
}
}
#nullable restore
#pragma warning restore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//HintName: TestNs2.TestVM.Properties.g.cs
// <auto-generated/>
using ReactiveUI;

#pragma warning disable
#nullable enable

namespace TestNs2
{
/// <summary>
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
/// </summary>
public partial class TestVM
{
/// <inheritdoc cref="_name"/>
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
[global::System.Runtime.Serialization.DataMemberAttribute()]
[global::System.Text.Json.Serialization.JsonIncludeAttribute()]
public string? Name { get => _name; set => this.RaiseAndSetIfChanged(ref _name, value); }
}
}
#nullable restore
#pragma warning restore
24 changes: 13 additions & 11 deletions src/ReactiveUI.SourceGenerator.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ public string VerifiedFilePath()
var name = typeof(T).Name;
return name switch
{
nameof(ReactiveGenerator) => "..\\REACTIVE",
nameof(ReactiveCommandGenerator) => "..\\REACTIVECMD",
nameof(ObservableAsPropertyGenerator) => "..\\OAPH",
nameof(IViewForGenerator) => "..\\IVIEWFOR",
nameof(RoutedControlHostGenerator) => "..\\ROUTEDHOST",
nameof(ViewModelControlHostGenerator) => "..\\CONTROLHOST",
nameof(ReactiveGenerator) => "REACTIVE",
nameof(ReactiveCommandGenerator) => "REACTIVECMD",
nameof(ObservableAsPropertyGenerator) => "OAPH",
nameof(IViewForGenerator) => "IVIEWFOR",
nameof(RoutedControlHostGenerator) => "ROUTEDHOST",
nameof(ViewModelControlHostGenerator) => "CONTROLHOST",
_ => name,
};
}
Expand Down Expand Up @@ -127,7 +127,7 @@ public void TestFail(

var utility = new SourceGeneratorUtility(x => testOutput.WriteLine(x));

Assert.Throws<InvalidOperationException>(() => RunGeneratorAndCheck(source));
Assert.Throws<InvalidOperationException>(() => { RunGeneratorAndCheck(source); });
}

/// <summary>
Expand All @@ -140,7 +140,7 @@ public void TestFail(
/// </returns>
/// <exception cref="InvalidOperationException">Must have valid compiler instance.</exception>
/// <exception cref="ArgumentNullException">callerType.</exception>
public GeneratorDriver TestPass(
public SettingsTask TestPass(
string source,
bool withPreDiagnosics = false)
{
Expand All @@ -165,7 +165,7 @@ public GeneratorDriver TestPass(
/// The generator driver used to run the generator.
/// </returns>
/// <exception cref="InvalidOperationException">Thrown if the compiler instance is not valid or if the compilation fails.</exception>
public GeneratorDriver RunGeneratorAndCheck(
public SettingsTask RunGeneratorAndCheck(
string code,
bool withPreDiagnosics = false,
bool rerunCompilation = true)
Expand Down Expand Up @@ -224,10 +224,12 @@ public GeneratorDriver RunGeneratorAndCheck(
throw new InvalidOperationException("Compilation failed due to the above diagnostics.");
}

return rerunDriver;
return VerifyGenerator(rerunDriver);
}

// If rerun is not needed, simply run the generator.
return driver.RunGenerators(compilation);
return VerifyGenerator(driver.RunGenerators(compilation));
}

private SettingsTask VerifyGenerator(GeneratorDriver driver) => Verify(driver).UseDirectory(VerifiedFilePath()).ScrubLinesContaining("[global::System.CodeDom.Compiler.GeneratedCode(\"");
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using Microsoft.CodeAnalysis;
using ReactiveUI.SourceGenerators;
using Xunit.Abstractions;

Expand Down Expand Up @@ -38,11 +37,8 @@ public partial class TestVM : ReactiveObject
}
""";

// Act: Initialize the helper and run the generator.
var driver = TestHelper.TestPass(sourceCode);

// Assert: Verify the generated code.
return VerifyGenerator(driver);
// Act: Initialize the helper and run the generator. Assert: Verify the generated code.
return TestHelper.TestPass(sourceCode);
}

/// <summary>
Expand All @@ -68,11 +64,8 @@ public partial class TestVM : ReactiveObject
}
""";

// Act: Initialize the helper and run the generator.
var driver = TestHelper.TestPass(sourceCode);

// Assert: Verify the generated code.
return VerifyGenerator(driver);
// Act: Initialize the helper and run the generator. Assert: Verify the generated code.
return TestHelper.TestPass(sourceCode);
}

/// <summary>
Expand All @@ -98,11 +91,8 @@ public partial class TestVM : ReactiveObject
}
""";

// Act: Initialize the helper and run the generator.
var driver = TestHelper.TestPass(sourceCode);

// Assert: Verify the generated code.
return VerifyGenerator(driver);
// Act: Initialize the helper and run the generator. Assert: Verify the generated code.
return TestHelper.TestPass(sourceCode);
}

/// <summary>
Expand All @@ -128,11 +118,8 @@ public partial class TestVM : ReactiveObject
}
""";

// Act: Initialize the helper and run the generator.
var driver = TestHelper.TestPass(sourceCode);

// Assert: Verify the generated code.
return VerifyGenerator(driver);
// Act: Initialize the helper and run the generator. Assert: Verify the generated code.
return TestHelper.TestPass(sourceCode);
}

/// <summary>
Expand Down Expand Up @@ -162,11 +149,8 @@ public partial class TestVM : ReactiveObject
}
""";

// Act: Initialize the helper and run the generator.
var driver = TestHelper.TestPass(sourceCode);

// Assert: Verify the generated code.
return VerifyGenerator(driver);
// Act: Initialize the helper and run the generator. Assert: Verify the generated code.
return TestHelper.TestPass(sourceCode);
}

/// <summary>
Expand Down Expand Up @@ -196,11 +180,8 @@ public partial class TestVM : ReactiveObject
}
""";

// Act: Initialize the helper and run the generator.
var driver = TestHelper.TestPass(sourceCode);

// Assert: Verify the generated code.
return VerifyGenerator(driver);
// Act: Initialize the helper and run the generator. Assert: Verify the generated code.
return TestHelper.TestPass(sourceCode);
}

/// <summary>
Expand Down Expand Up @@ -230,12 +211,7 @@ public partial class TestVM : ReactiveObject
}
""";

// Act: Initialize the helper and run the generator.
var driver = TestHelper.TestPass(sourceCode);

// Assert: Verify the generated code.
return VerifyGenerator(driver);
// Act: Initialize the helper and run the generator. Assert: Verify the generated code.
return TestHelper.TestPass(sourceCode);
}

private SettingsTask VerifyGenerator(GeneratorDriver driver) => Verify(driver).UseDirectory(TestHelper.VerifiedFilePath()).ScrubLinesContaining("[global::System.CodeDom.Compiler.GeneratedCode(\"");
}
Loading