Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ baseline is available (next paragraph), other outside-body drift — existing-fi
initializers, attributes, and other declaration edits — is reported as a `Warnings`
entry as well (handled added members and reported removed members are excluded
from this generic warning); without a baseline it stays silent. Either way, use
`uloop compile` for such edits.
`uloop compile` for such edits. The comparison is against the source the loaded
assembly was compiled from, so an earlier edit outside method bodies keeps this
warning on every reload until `uloop compile`. Comment-only edits (line, block, and
XML documentation comments) do not count.

## Signature changes: return type, rename, parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ baseline is available (next paragraph), other outside-body drift — existing-fi
initializers, attributes, and other declaration edits — is reported as a `Warnings`
entry as well (handled added members and reported removed members are excluded
from this generic warning); without a baseline it stays silent. Either way, use
`uloop compile` for such edits.
`uloop compile` for such edits. The comparison is against the source the loaded
assembly was compiled from, so an earlier edit outside method bodies keeps this
warning on every reload until `uloop compile`. Comment-only edits (line, block, and
XML documentation comments) do not count.

## Signature changes: return type, rename, parameters

Expand Down
82 changes: 72 additions & 10 deletions Assets/Tests/Editor/HotReload/TransformWorkerAddedFieldTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class TransformWorkerAddedFieldTests
// Packages/src/Editor/FirstPartyTools/HotReload/TransformWorker~/OutsideMethodBodyDriftChecker.cs.
// That constant lives in the Unity-ignored worker process and is not visible here.
private const string OutsideMethodBodyDriftWarningFormat =
"Edits outside method bodies in {0} (fields, initializers, or attributes) are not applied by hot reload; run uloop compile to pick them up.";
"Edits outside method bodies in {0} (fields, initializers, or attributes) since the last compile are not applied by hot reload; run uloop compile to pick them up.";

private const string FieldKindChangeProjectRelativePath =
"Assets/Tests/Editor/HotReload/HotReloadAddedMemberHost.cs";
Expand Down Expand Up @@ -1470,7 +1470,7 @@ public async Task Drift_ExistingInitializerEditWithAddedField_StillWarns()
Assert.That(foundDrift, Is.True, "Existing field initializer edits must still warn.");
AssertHasDeclarationDriftWarning(
result,
"Edits outside method bodies in AddedFieldWithInitializerDrift.cs (field initializer: PublicSeed) are not applied by hot reload; run uloop compile to pick them up.");
"Edits outside method bodies in AddedFieldWithInitializerDrift.cs (field initializer: PublicSeed) since the last compile are not applied by hot reload; run uloop compile to pick them up.");
Assert.That(result.Output.hasAddedFieldRewrites, Is.True);
}

Expand All @@ -1496,7 +1496,7 @@ public async Task Drift_ExistingInitializerEdit_NamesDeclaration()
Is.EqualTo(
new[]
{
"Edits outside method bodies in NamedInitializerDrift.cs (field initializer: PublicSeed) are not applied by hot reload; run uloop compile to pick them up."
"Edits outside method bodies in NamedInitializerDrift.cs (field initializer: PublicSeed) since the last compile are not applied by hot reload; run uloop compile to pick them up."
}));
}

Expand Down Expand Up @@ -1525,7 +1525,7 @@ public async Task Drift_FieldDeclarationOrderSwap_EmitsFileOnlyWarning()
Is.EqualTo(
new[]
{
"Edits outside method bodies in FieldOrderSwapDrift.cs (fields, initializers, or attributes) are not applied by hot reload; run uloop compile to pick them up."
"Edits outside method bodies in FieldOrderSwapDrift.cs (fields, initializers, or attributes) since the last compile are not applied by hot reload; run uloop compile to pick them up."
}));
}

Expand All @@ -1552,7 +1552,7 @@ public async Task Drift_MultiDeclaratorAttributeEdit_NamesEverySibling()
Is.EqualTo(
new[]
{
"Edits outside method bodies in MultiDeclaratorAttributeDrift.cs (field attributes: PairAlpha, PairBeta) are not applied by hot reload; run uloop compile to pick them up."
"Edits outside method bodies in MultiDeclaratorAttributeDrift.cs (field attributes: PairAlpha, PairBeta) since the last compile are not applied by hot reload; run uloop compile to pick them up."
}));
}

Expand All @@ -1578,7 +1578,7 @@ public async Task Drift_MultiDeclaratorInitializerEdit_NamesOnlyChangedVariable(
Is.EqualTo(
new[]
{
"Edits outside method bodies in MultiDeclaratorInitializerDrift.cs (field initializer: PairAlpha) are not applied by hot reload; run uloop compile to pick them up."
"Edits outside method bodies in MultiDeclaratorInitializerDrift.cs (field initializer: PairAlpha) since the last compile are not applied by hot reload; run uloop compile to pick them up."
}));
}

Expand All @@ -1604,7 +1604,7 @@ public async Task Drift_MultiDeclaratorRegroup_FailsOpenToFileOnlyWarning()
Is.EqualTo(
new[]
{
"Edits outside method bodies in MultiDeclaratorRegroupDrift.cs (fields, initializers, or attributes) are not applied by hot reload; run uloop compile to pick them up."
"Edits outside method bodies in MultiDeclaratorRegroupDrift.cs (fields, initializers, or attributes) since the last compile are not applied by hot reload; run uloop compile to pick them up."
}));
}

Expand Down Expand Up @@ -1634,10 +1634,72 @@ public async Task Drift_DuplicateFieldSyntaxKey_FailsOpenToFileOnlyWarning()
Is.EqualTo(
new[]
{
"Edits outside method bodies in DupFieldKeyFailOpen.cs (fields, initializers, or attributes) are not applied by hot reload; run uloop compile to pick them up."
"Edits outside method bodies in DupFieldKeyFailOpen.cs (fields, initializers, or attributes) since the last compile are not applied by hot reload; run uloop compile to pick them up."
}));
}

/// <summary>
/// What: when a duplicate field syntax key sends the drift check to the whole-tree
/// fail-open compare, an edit that only adds a comment still emits no warning.
/// </summary>
[Test]
public async Task Drift_DuplicateFieldSyntaxKeyWithCommentOnlyEdit_DoesNotWarn()
{
string onDisk = File.ReadAllText(ResolveHostPath());
// Why the duplicate repeats a compiled field: a name the compiled type lacks counts as
// an added field of the edited source and is stripped from that tree only, so the
// compare would warn without any comment.
string snapshotSource = onDisk.Replace(
" public int PublicSeed = 3;",
" public int PublicSeed = 3;\n public int PublicSeed = 3;",
StringComparison.Ordinal);
string edited = snapshotSource.Replace(
" public int PublicSeed = 3;\n public int PublicSeed = 3;",
" // comment added by the test\n public int PublicSeed = 3;\n public int PublicSeed = 3;",
StringComparison.Ordinal);
Assert.That(edited, Is.Not.EqualTo(snapshotSource), "Precondition: the edit must add the comment.");
TransformWorkerClientResult result = await RunWorkerOnSourceAsync(
WriteEdited("DupFieldKeyCommentOnly.cs", edited),
HostProjectRelativePath,
snapshotSource: snapshotSource);
Assert.That(result.Success, Is.True, result.ErrorMessage);
Assert.That(
result.Output.files[0].declarationDriftWarnings,
Is.Empty,
string.Join("\n", result.Output.files[0].declarationDriftWarnings ?? Array.Empty<string>()));
}

/// <summary>
/// What: adding only a line comment above the attribute list of an existing field emits no
/// outside-method-body warning.
/// </summary>
[Test]
public async Task Drift_LineCommentOnlyEditAboveAFieldAttribute_DoesNotWarn()
{
string onDisk = File.ReadAllText(ResolveHostPath());
// Why the snapshot carries the attribute too: no field of the compiled host has one, and
// the comment must be the only difference between the snapshot and the edited source.
string snapshotSource = onDisk.Replace(
" public int PublicSeed = 3;",
" [SerializeField]\n public int PublicSeed = 3;",
StringComparison.Ordinal);
string edited = snapshotSource.Replace(
" [SerializeField]\n public int PublicSeed = 3;",
" // comment added by the test\n [SerializeField]\n public int PublicSeed = 3;",
StringComparison.Ordinal);
Assert.That(snapshotSource, Is.Not.EqualTo(onDisk), "Precondition: the snapshot must add the attribute.");
Assert.That(edited, Is.Not.EqualTo(snapshotSource), "Precondition: the edit must add the comment.");
TransformWorkerClientResult result = await RunWorkerOnSourceAsync(
WriteEdited("FieldAttributeCommentOnly.cs", edited),
HostProjectRelativePath,
snapshotSource: snapshotSource);
Assert.That(result.Success, Is.True, result.ErrorMessage);
Assert.That(
result.Output.files[0].declarationDriftWarnings,
Is.Empty,
string.Join("\n", result.Output.files[0].declarationDriftWarnings ?? Array.Empty<string>()));
}

/// <summary>
/// What: a readonly added field can still be read through GetOrInit.
/// </summary>
Expand Down Expand Up @@ -1922,7 +1984,7 @@ public async Task Drift_PropertyKindChangeWithInitializerEdit_StillEmitsNamedOut
new[]
{
"Compiled property 'io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload.HotReloadFieldKindChangeFixture.Hp' was removed or redeclared as a different member kind in the edited source; the compiled member stays until 'uloop compile'.",
"Edits outside method bodies in PropertyKindChangeWithInitializer.cs (field initializer: PublicSeed) are not applied by hot reload; run uloop compile to pick them up."
"Edits outside method bodies in PropertyKindChangeWithInitializer.cs (field initializer: PublicSeed) since the last compile are not applied by hot reload; run uloop compile to pick them up."
}));
}

Expand Down Expand Up @@ -1953,7 +2015,7 @@ public async Task Drift_EventKindChangeWithInitializerEdit_StillEmitsNamedOutsid
new[]
{
"Compiled event 'io.github.hatayama.UnityCliLoop.Tests.Editor.HotReload.HotReloadFieldKindChangeFixture.ScoreChanged' was removed or redeclared as a different member kind in the edited source; the compiled member stays until 'uloop compile'.",
"Edits outside method bodies in EventKindChangeWithInitializer.cs (field initializer: PublicSeed) are not applied by hot reload; run uloop compile to pick them up."
"Edits outside method bodies in EventKindChangeWithInitializer.cs (field initializer: PublicSeed) since the last compile are not applied by hot reload; run uloop compile to pick them up."
}));
}

Expand Down
Loading
Loading