Repository navigation
Expand file tree
/
Copy pathPathShapeDiagnosticsTests.cs
More file actions
153 lines (128 loc) · 5.92 KB
/
Copy pathPathShapeDiagnosticsTests.cs
File metadata and controls
153 lines (128 loc) · 5.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System.IO;
using FolderDiffIL4DotNet.Common;
using Xunit;
namespace FolderDiffIL4DotNet.Tests.Common
{
/// <summary>
/// Unit tests for <see cref="PathShapeDiagnostics"/>. This helper is reused across many warning/error
/// messages (audit log, SBOM, report writers, cache layers, disassembler launcher, logger cleanup,
/// preflight validator, plugin loader, open-folder commands, IL text writer, etc.), so the edges it
/// exposes are load-bearing: a regression here silently weakens every downstream diagnostic.
/// <see cref="PathShapeDiagnostics"/> のユニットテスト。この helper は監査ログ、SBOM、レポート出力、
/// キャッシュ層、逆アセンブラ起動、logger cleanup、プリフライト、プラグインローダ、open-folder、
/// IL テキスト出力など多数の warning/error メッセージで再利用されるため、ここが退行すると下流の
/// 診断がまとめて弱くなる。境界条件を明示的に pin する。
/// </summary>
[Trait("Category", "Unit")]
public sealed class PathShapeDiagnosticsTests
{
// ── DescribeRootedState ──
[Fact]
public void DescribeRootedState_NullInput_ReturnsUnknown()
{
Assert.Equal("Unknown", PathShapeDiagnostics.DescribeRootedState(null));
}
[Fact]
public void DescribeRootedState_EmptyInput_ReturnsUnknown()
{
Assert.Equal("Unknown", PathShapeDiagnostics.DescribeRootedState(string.Empty));
}
[Fact]
public void DescribeRootedState_WhitespaceInput_ReturnsUnknown()
{
Assert.Equal("Unknown", PathShapeDiagnostics.DescribeRootedState(" "));
}
[Fact]
public void DescribeRootedState_EmbeddedNullByte_ReturnsUnknown()
{
// Embedded NUL must never reach Path.IsPathRooted (which would throw on some runtimes),
// and must not be reported as a legitimate rooted/relative path.
// 埋め込み NUL は Path.IsPathRooted に渡さない(ランタイムによっては例外)。
// また正規の rooted/relative パスとして報告してもいけない。
Assert.Equal("Unknown", PathShapeDiagnostics.DescribeRootedState("bad\0path"));
}
[Fact]
public void DescribeRootedState_RelativePath_ReturnsFalse()
{
Assert.Equal("False", PathShapeDiagnostics.DescribeRootedState("relative/path"));
}
[Fact]
public void DescribeRootedState_AbsolutePath_ReturnsTrue()
{
string absolute = Path.Combine(Path.GetTempPath(), "some", "path");
Assert.Equal("True", PathShapeDiagnostics.DescribeRootedState(absolute));
}
// ── LooksLikePath ──
[Fact]
public void LooksLikePath_NullInput_ReturnsFalse()
{
Assert.False(PathShapeDiagnostics.LooksLikePath(null));
}
[Fact]
public void LooksLikePath_EmptyInput_ReturnsFalse()
{
Assert.False(PathShapeDiagnostics.LooksLikePath(string.Empty));
}
[Fact]
public void LooksLikePath_EmbeddedNullByte_ReturnsFalse()
{
Assert.False(PathShapeDiagnostics.LooksLikePath("bad\0tool"));
}
[Fact]
public void LooksLikePath_PlainCommandName_ReturnsFalse()
{
// No directory separator and not rooted — treated as a bare command name, not a path.
// 区切り文字なし・rooted でもない → 裸のコマンド名扱い、path-like ではない。
Assert.False(PathShapeDiagnostics.LooksLikePath("dotnet-ildasm"));
}
[Fact]
public void LooksLikePath_ForwardSlashPath_ReturnsTrue()
{
Assert.True(PathShapeDiagnostics.LooksLikePath("foo/bar"));
}
[Fact]
public void LooksLikePath_PlatformDirectorySeparator_ReturnsTrue()
{
// Use the runtime's primary separator so the expectation holds on Windows and Unix alike.
// プラットフォームのプライマリ区切り文字を使い、Windows/Unix ともに期待値が成立するようにする。
string pathWithSeparator = $"foo{Path.DirectorySeparatorChar}bar";
Assert.True(PathShapeDiagnostics.LooksLikePath(pathWithSeparator));
}
[Fact]
public void LooksLikePath_AbsolutePath_ReturnsTrue()
{
string absolute = Path.Combine(Path.GetTempPath(), "foo");
Assert.True(PathShapeDiagnostics.LooksLikePath(absolute));
}
// ── DescribeState ──
[Fact]
public void DescribeState_UsesLabelPrefix()
{
string state = PathShapeDiagnostics.DescribeState("Foo", "relative/path");
Assert.Contains("FooIsPathRooted=False", state);
Assert.Contains("FooLooksPathLike=True", state);
}
[Fact]
public void DescribeState_NullInput_ReportsUnknownAndFalse()
{
string state = PathShapeDiagnostics.DescribeState("Target", null);
Assert.Contains("TargetIsPathRooted=Unknown", state);
Assert.Contains("TargetLooksPathLike=False", state);
}
[Fact]
public void DescribeState_EmbeddedNullByte_ReportsUnknownAndFalse()
{
string state = PathShapeDiagnostics.DescribeState("Cmd", "bad\0tool");
Assert.Contains("CmdIsPathRooted=Unknown", state);
Assert.Contains("CmdLooksPathLike=False", state);
}
[Fact]
public void DescribeState_AbsolutePath_ReportsTrueTrue()
{
string absolute = Path.Combine(Path.GetTempPath(), "x");
string state = PathShapeDiagnostics.DescribeState("Out", absolute);
Assert.Contains("OutIsPathRooted=True", state);
Assert.Contains("OutLooksPathLike=True", state);
}
}
}