From b7c6a83830bc8c3f20592322161807630689ba37 Mon Sep 17 00:00:00 2001 From: Dennis Doomen Date: Sun, 26 Jul 2026 13:40:35 +0200 Subject: [PATCH 1/2] Add AbsolutePath.Temp for generating unique temp paths Returns a unique path under the OS temp directory without creating the file or directory, so tests and tools can build up a scratch location before deciding whether it's a file or directory. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- src/Fallout.Utilities/IO/AbsolutePath.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Fallout.Utilities/IO/AbsolutePath.cs b/src/Fallout.Utilities/IO/AbsolutePath.cs index 7eafd49e1..299f9cdf9 100644 --- a/src/Fallout.Utilities/IO/AbsolutePath.cs +++ b/src/Fallout.Utilities/IO/AbsolutePath.cs @@ -52,6 +52,17 @@ public static AbsolutePath Create(string path) return new AbsolutePath(path); } + /// + /// Returns a unique path within the OS temp directory, optionally prefixed with . + /// Does not create the file or directory. + /// + public static AbsolutePath Temp(string prefix = null) + { + var suffix = Guid.NewGuid().ToString("N").Substring(0, 8); + var name = string.IsNullOrEmpty(prefix) ? suffix : $"{prefix}-{suffix}"; + return Create(Path.GetTempPath()) / name; + } + private readonly string path; private AbsolutePath(string path) From d2d55b4cae943d756c91305a2924334d5c05a860 Mon Sep 17 00:00:00 2001 From: Dennis Doomen Date: Sun, 26 Jul 2026 13:40:40 +0200 Subject: [PATCH 2/2] Rewrite MigrationIntegrationSpecs to use AbsolutePath.Temp Replaces the hand-rolled CreateVanillaFixture/Directory.Delete pair with an IDisposable fixture built on AbsolutePath.Temp, and renames the test methods to describe behaviour. Also relaxes the ReSharper async-overload-highlighting rule for tests, where the async-suffix convention adds noise rather than value. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .editorconfig | 3 + .../MigrationIntegrationSpecs.cs | 304 ++++++++---------- 2 files changed, 146 insertions(+), 161 deletions(-) diff --git a/.editorconfig b/.editorconfig index bb5e284c3..8ac07ddf0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -176,3 +176,6 @@ dotnet_style_require_accessibility_modifiers = omit_if_default:silent [tests/**/*.cs] dotnet_naming_rule.private_fields_should_be_camel_case.severity = suggestion + +# In tests, using async isn't adding a lot of value other than noise +resharper_method_has_async_overload_highlighting = none \ No newline at end of file diff --git a/tests/Fallout.Migrate.Specs/MigrationIntegrationSpecs.cs b/tests/Fallout.Migrate.Specs/MigrationIntegrationSpecs.cs index 117c4234a..1bd7b6655 100644 --- a/tests/Fallout.Migrate.Specs/MigrationIntegrationSpecs.cs +++ b/tests/Fallout.Migrate.Specs/MigrationIntegrationSpecs.cs @@ -1,192 +1,174 @@ using System; using System.IO; -using System.Text; using System.Threading.Tasks; +using Fallout.Common.IO; using FluentAssertions; using Xunit; namespace Fallout.Migrate.Specs; -public class MigrationIntegrationSpecs +public class MigrationIntegrationSpecs : IDisposable { - [Fact] - public async Task MigratesVanillaConsumerRepo() + private readonly AbsolutePath tempDirectory; + + public MigrationIntegrationSpecs() + { + // Arrange + tempDirectory = AbsolutePath.Temp("fallout-migrate-test"); + (tempDirectory / "build").CreateDirectory(); + (tempDirectory / ".nuke").CreateDirectory(); + + (tempDirectory / "build" / "_build.csproj").WriteAllText( + """ + + + Exe + net10.0 + .\.. + 1 + + + + + + """); + + (tempDirectory / "build" / "Build.cs").WriteAllText( + """ + using Nuke.Common; + using Nuke.Common.Tools.DotNet; + + class Build : NukeBuild + { + public static int Main () => Execute(x => x.Compile); + + Target Compile => _ => _.Executes(() => { }); + } + """); + + (tempDirectory / "build.sh").WriteAllText( + """ + #!/usr/bin/env bash + export NUKE_TELEMETRY_OPTOUT=1 + TEMP_DIRECTORY="$SCRIPT_DIR/.nuke/temp" + dotnet nuke "$@" + """); + + (tempDirectory / ".nuke" / "parameters.json").WriteAllText("{}"); + } + + public void Dispose() { - var temp = CreateVanillaFixture(); - - try - { - var migration = new Migration(temp, dryRun: false, TextWriter.Null); - var summary = await migration.RunAsync(); - - // Build file rewritten end to end. - var buildCsproj = File.ReadAllText(Path.Combine(temp, "build", "_build.csproj")); - buildCsproj.Should().Contain(@"Include=""Fallout.Common"""); - buildCsproj.Should().Contain(""); - buildCsproj.Should().NotContain("Nuke.Common"); - buildCsproj.Should().NotContain(""); - - var buildCs = File.ReadAllText(Path.Combine(temp, "build", "Build.cs")); - buildCs.Should().Contain("using Fallout.Common"); - buildCs.Should().Contain(": FalloutBuild"); - buildCs.Should().NotContain("using Nuke."); - buildCs.Should().NotContain("NukeBuild"); - - var buildSh = File.ReadAllText(Path.Combine(temp, "build.sh")); - buildSh.Should().Contain("dotnet fallout"); - buildSh.Should().NotContain("TELEMETRY_OPTOUT"); // telemetry removed — opt-out stripped, not renamed (ADR-0010) - buildSh.Should().Contain(".fallout/temp"); - - // .nuke/ moved to .fallout/. - Directory.Exists(Path.Combine(temp, ".nuke")).Should().BeFalse(); - Directory.Exists(Path.Combine(temp, ".fallout")).Should().BeTrue(); - File.Exists(Path.Combine(temp, ".fallout", "parameters.json")).Should().BeTrue(); - - summary.FilesChanged.Should().BeGreaterThan(0); - summary.EditCount.Should().BeGreaterThan(0); - summary.DirectoriesRenamed.Should().Be(1); - summary.Warnings.Should().BeEmpty(); - } - finally - { - Directory.Delete(temp, recursive: true); - } + tempDirectory.DeleteDirectory(); } [Fact] - public async Task DryRunDoesNotWriteFiles() + public async Task A_vanilla_consumer_repo_is_migrated_end_to_end() { - var temp = CreateVanillaFixture(); - - try - { - var beforeCsproj = File.ReadAllText(Path.Combine(temp, "build", "_build.csproj")); - var beforeNukeDir = Directory.Exists(Path.Combine(temp, ".nuke")); - - var summary = await new Migration(temp, dryRun: true, TextWriter.Null).RunAsync(); - - File.ReadAllText(Path.Combine(temp, "build", "_build.csproj")).Should().Be(beforeCsproj); - Directory.Exists(Path.Combine(temp, ".nuke")).Should().Be(beforeNukeDir); - summary.FilesChanged.Should().BeGreaterThan(0); // counts intended edits - } - finally - { - Directory.Delete(temp, recursive: true); - } + // Act + var migration = new Migration(tempDirectory, dryRun: false, TextWriter.Null); + var summary = await migration.RunAsync(); + + // Assert + + // Build file rewritten end to end. + var buildCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText(); + buildCsproj.Should().Contain(@"Include=""Fallout.Common"""); + buildCsproj.Should().Contain(""); + buildCsproj.Should().NotContain("Nuke.Common"); + buildCsproj.Should().NotContain(""); + + var buildCs = (tempDirectory / "build" / "Build.cs").ReadAllText(); + buildCs.Should().Contain("using Fallout.Common"); + buildCs.Should().Contain(": FalloutBuild"); + buildCs.Should().NotContain("using Nuke."); + buildCs.Should().NotContain("NukeBuild"); + + var buildSh = (tempDirectory / "build.sh").ReadAllText(); + buildSh.Should().Contain("dotnet fallout"); + buildSh.Should().NotContain("TELEMETRY_OPTOUT"); // telemetry removed — opt-out stripped, not renamed (ADR-0010) + buildSh.Should().Contain(".fallout/temp"); + + // .nuke/ moved to .fallout/. + (tempDirectory / ".nuke").DirectoryExists().Should().BeFalse(); + (tempDirectory / ".fallout").DirectoryExists().Should().BeTrue(); + (tempDirectory / ".fallout" / "parameters.json").FileExists().Should().BeTrue(); + + summary.FilesChanged.Should().BeGreaterThan(0); + summary.EditCount.Should().BeGreaterThan(0); + summary.DirectoriesRenamed.Should().Be(1); + summary.Warnings.Should().BeEmpty(); } [Fact] - public async Task WarnsWhenBothNukeAndFalloutDirectoriesExist() + public async Task A_dry_run_does_not_write_any_files() { - var temp = CreateVanillaFixture(); - Directory.CreateDirectory(Path.Combine(temp, ".fallout")); - - try - { - var summary = await new Migration(temp, dryRun: false, TextWriter.Null).RunAsync(); - - summary.Warnings.Should().Contain(w => w.Contains(".nuke/") && w.Contains(".fallout/")); - summary.DirectoriesRenamed.Should().Be(0); - Directory.Exists(Path.Combine(temp, ".nuke")).Should().BeTrue(); - } - finally - { - Directory.Delete(temp, recursive: true); - } + // Arrange + var beforeCsproj = (tempDirectory / "build" / "_build.csproj").ReadAllText(); + var beforeNukeDir = (tempDirectory / ".nuke").DirectoryExists(); + + // Act + var summary = await new Migration(tempDirectory, dryRun: true, TextWriter.Null).RunAsync(); + + // Assert + (tempDirectory / "build" / "_build.csproj").ReadAllText().Should().Be(beforeCsproj); + (tempDirectory / ".nuke").DirectoryExists().Should().Be(beforeNukeDir); + summary.FilesChanged.Should().BeGreaterThan(0); // counts intended edits } [Fact] - public async Task WarnsWhenBuildProjectTargetsOlderThanNet10() + public async Task Nuke_and_fallout_directories_coexisting_produces_a_warning() { - var temp = CreateVanillaFixture(); - var buildCsprojPath = Path.Combine(temp, "build", "_build.csproj"); - File.WriteAllText(buildCsprojPath, File.ReadAllText(buildCsprojPath).Replace("net10.0", "net8.0")); - - try - { - var summary = await new Migration(temp, dryRun: false, TextWriter.Null).RunAsync(); - - summary.Warnings.Should().Contain(w => - w.Contains("net8.0") && w.Contains(".NET 10") && w.Contains("_build.csproj")); - } - finally - { - Directory.Delete(temp, recursive: true); - } + // Arrange + (tempDirectory / ".fallout").CreateDirectory(); + + // Act + var summary = await new Migration(tempDirectory, dryRun: false, TextWriter.Null).RunAsync(); + + // Assert + summary.Warnings.Should().Contain(w => w.Contains(".nuke/") && w.Contains(".fallout/")); + summary.DirectoriesRenamed.Should().Be(0); + (tempDirectory / ".nuke").DirectoryExists().Should().BeTrue(); } [Fact] - public async Task BumpsDotNetVersionAndSdk() + public async Task A_build_project_targeting_an_older_tfm_than_net10_produces_a_warning() { - var temp = CreateVanillaFixture(); - var buildCsprojPath = Path.Combine(temp, "build", "_build.csproj"); - File.WriteAllText(buildCsprojPath, File.ReadAllText(buildCsprojPath).Replace("net10.0", "net8.0")); - File.WriteAllText(Path.Combine(temp, "global.json"), """ - { - "sdk": { - "version": "8.0.100", - "rollForward": "latestMinor" - } - } - """); - - try - { - await new Migration(temp, dryRun: false, TextWriter.Null).RunAsync(); - - File.ReadAllText(buildCsprojPath).Should().Contain("net10.0"); - - var globalJson = File.ReadAllText(Path.Combine(temp, "global.json")); - globalJson.Should().Contain(@"""version"": ""10.0.100"""); - } - finally - { - Directory.Delete(temp, recursive: true); - } + // Arrange + var buildCsprojPath = tempDirectory / "build" / "_build.csproj"; + buildCsprojPath.UpdateText(text => text.Replace("net10.0", "net8.0")); + + // Act + var summary = await new Migration(tempDirectory, dryRun: false, TextWriter.Null).RunAsync(); + + // Assert + summary.Warnings.Should().Contain(w => + w.Contains("net8.0") && w.Contains(".NET 10") && w.Contains("_build.csproj")); } - private static string CreateVanillaFixture() + [Fact] + public async Task Migration_bumps_the_target_framework_and_global_json_sdk_version() { - var dir = Path.Combine(Path.GetTempPath(), "fallout-migrate-test-" + Guid.NewGuid().ToString("N")[..8]); - Directory.CreateDirectory(dir); - Directory.CreateDirectory(Path.Combine(dir, "build")); - Directory.CreateDirectory(Path.Combine(dir, ".nuke")); - - File.WriteAllText(Path.Combine(dir, "build", "_build.csproj"), """ - - - Exe - net10.0 - .\.. - 1 - - - - - - """); - - File.WriteAllText(Path.Combine(dir, "build", "Build.cs"), """ - using Nuke.Common; - using Nuke.Common.Tools.DotNet; - - class Build : NukeBuild - { - public static int Main () => Execute(x => x.Compile); - - Target Compile => _ => _.Executes(() => { }); - } - """); - - File.WriteAllText(Path.Combine(dir, "build.sh"), """ - #!/usr/bin/env bash - export NUKE_TELEMETRY_OPTOUT=1 - TEMP_DIRECTORY="$SCRIPT_DIR/.nuke/temp" - dotnet nuke "$@" - """, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); - - File.WriteAllText(Path.Combine(dir, ".nuke", "parameters.json"), "{}"); - - return dir; + // Arrange + var buildCsprojPath = tempDirectory / "build" / "_build.csproj"; + buildCsprojPath.UpdateText(text => text.Replace("net10.0", "net8.0")); + (tempDirectory / "global.json").WriteAllText( + """ + { + "sdk": { + "version": "8.0.100", + "rollForward": "latestMinor" + } + } + """); + + // Act + await new Migration(tempDirectory, dryRun: false, TextWriter.Null).RunAsync(); + + // Assert + buildCsprojPath.ReadAllText().Should().Contain("net10.0"); + + var globalJson = (tempDirectory / "global.json").ReadAllText(); + globalJson.Should().Contain(@"""version"": ""10.0.100"""); } }