Skip to content

Commit 892254e

Browse files
committed
Add tests for --clear-cache redirected stdin rejection and help output
Two new tests following the existing --wizard pattern: - ClearCacheFlag_WithRedirectedStdin_ExitsWithInvalidArguments - HelpFlag_OutputContainsClearCacheOption https://claude.ai/code/session_01JypMFAJfi2G2u5rpr8azna
1 parent 7631522 commit 892254e

2 files changed

Lines changed: 59 additions & 2 deletions

File tree

FolderDiffIL4DotNet.Tests/ProgramRunnerTests.HelpVersion.cs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,29 @@ public async Task RunAsync_HelpFlag_OutputContainsDryRunOption()
7070
}
7171
}
7272

73+
[Fact]
74+
public async Task RunAsync_HelpFlag_OutputContainsClearCacheOption()
75+
{
76+
var logger = new TestLogger(logFileAbsolutePath: "test.log");
77+
var runner = new ProgramRunner(logger, new ConfigService());
78+
var origOut = Console.Out;
79+
using var sw = new System.IO.StringWriter();
80+
Console.SetOut(sw);
81+
82+
try
83+
{
84+
var exitCode = await runner.RunAsync(new[] { "--help" });
85+
86+
Assert.Equal(0, exitCode);
87+
var output = sw.ToString();
88+
Assert.Contains("--clear-cache", output, StringComparison.Ordinal);
89+
}
90+
finally
91+
{
92+
Console.SetOut(origOut);
93+
}
94+
}
95+
7396
[Fact]
7497
public async Task RunAsync_DryRunFlag_ExitsZeroWithPreviewOutput()
7598
{
@@ -435,6 +458,40 @@ public async Task RunAsync_WizardFlag_WithRedirectedStdin_ExitsWithInvalidArgume
435458
}
436459
}
437460

461+
// -----------------------------------------------------------------------
462+
// --clear-cache with redirected stdin -> exit code 2
463+
// --clear-cache でリダイレクト stdin → 終了コード 2
464+
// -----------------------------------------------------------------------
465+
466+
[Fact]
467+
public async Task RunAsync_ClearCacheFlag_WithRedirectedStdin_ExitsWithInvalidArguments()
468+
{
469+
var logger = new TestLogger(logFileAbsolutePath: "test.log");
470+
var runner = new ProgramRunner(logger, new ConfigService());
471+
var origOut = Console.Out;
472+
var origErr = Console.Error;
473+
using var swOut = new System.IO.StringWriter();
474+
using var swErr = new System.IO.StringWriter();
475+
Console.SetOut(swOut);
476+
Console.SetError(swErr);
477+
478+
try
479+
{
480+
// In test environment, stdin is always redirected, so --clear-cache should refuse to run.
481+
// テスト環境では stdin は常にリダイレクトされているため、--clear-cache は実行を拒否する。
482+
var exitCode = await runner.RunAsync(new[] { "--clear-cache" });
483+
484+
Assert.Equal(2, exitCode);
485+
var errOutput = swErr.ToString();
486+
Assert.Contains("--clear-cache requires an interactive terminal", errOutput, StringComparison.Ordinal);
487+
}
488+
finally
489+
{
490+
Console.SetOut(origOut);
491+
Console.SetError(origErr);
492+
}
493+
}
494+
438495
// -----------------------------------------------------------------------
439496
// Unknown flag -> exit code 2 (InvalidArguments)
440497
// 不明フラグ -> 終了コード 2(InvalidArguments)

0 commit comments

Comments
 (0)