From a2e7aaf2d316c6f8895418d88299969278dae2f6 Mon Sep 17 00:00:00 2001 From: Tom Laird-McConnell Date: Thu, 10 Sep 2026 17:55:17 -0700 Subject: [PATCH] Exec tests: leave the temp folder before deleting it A CShell's CurrentFolder setter assigns Environment.CurrentDirectory, which is process-wide, so the three Exec tests that start a shell in the temp folder left the whole test run standing in it. Cleanup then deleted it. On Linux the delete succeeds, and every later `new CShell()` throws FileNotFoundException from getcwd() on a directory that is no longer there -- four tests down, which is what red-lit the build on main. On Windows the OS refuses to delete a directory that is someone's cwd, the bare catch swallowed it, and the folders piled up in %TEMP% instead. Same bug, two symptoms, and only one of them visible where the tests are usually run. Restore the starting directory before deleting. Verified both ways: the failure reproduces on Ubuntu 24.04 (4 failed) and passes with this change (315/315), and on Windows the temp folders are now actually cleaned up. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01Vga8G5aDrA2qYn8BSCgTsd --- Tests/CShell.Tests/Exec.Tests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Tests/CShell.Tests/Exec.Tests.cs b/Tests/CShell.Tests/Exec.Tests.cs index f413e56..b50dddc 100644 --- a/Tests/CShell.Tests/Exec.Tests.cs +++ b/Tests/CShell.Tests/Exec.Tests.cs @@ -24,10 +24,12 @@ public class ExecTests private static string ShellFlag => IsWindows ? "/c" : "-c"; private string tempFolder; + private string originalFolder; [TestInitialize] public void Init() { + this.originalFolder = Environment.CurrentDirectory; this.tempFolder = Path.Combine(Path.GetTempPath(), "cshell-exec-" + Guid.NewGuid().ToString("N")); Directory.CreateDirectory(this.tempFolder); } @@ -35,6 +37,13 @@ public void Init() [TestCleanup] public void Cleanup() { + // A CShell's CurrentFolder is the PROCESS's current directory, so a test that started + // one in the temp folder left the whole test run standing in it. Step out before + // deleting: on Linux the delete otherwise succeeds and every later `new CShell()` + // throws from getcwd() on a directory that is no longer there, and on Windows the + // delete fails instead and the folders pile up. + Environment.CurrentDirectory = this.originalFolder; + try { Directory.Delete(this.tempFolder, true);