Skip to content

Commit 3235ee5

Browse files
committed
test: TestNoChangesMade, TestNoChangesMadeConfigPath, TestFragmentExists
1 parent 4bc76a7 commit 3235ee5

File tree

3 files changed

+74
-13
lines changed

3 files changed

+74
-13
lines changed

NF.Tool.ReleaseNoteMaker/NF.Tool.ReleaseNoteMaker.CLI/Commands/Command_Check.cs

+1-5
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ public override Task<int> ExecuteAsync(CommandContext context, Settings setting)
4040
return Task.FromResult(1);
4141
}
4242

43-
Console.WriteLine(baseDirectory);
44-
Console.WriteLine(config);
45-
46-
47-
(Exception? exOrNull, int exitCode, string stdOut, string stdErr) callResult = Cmd.Call2("git", $"diff --name-only {setting.CompareWith} ...");
43+
(Exception? exOrNull, int exitCode, string stdOut, string stdErr) callResult = Cmd.Call2("git", $"diff --name-only {setting.CompareWith}...");
4844
if (callResult.exOrNull != null)
4945
{
5046
AnsiConsole.WriteException(callResult.exOrNull);

NF.Tool.ReleaseNoteMaker/NF.Tool.ReleaseNoteMaker.Common/Fragments/FragmentFinder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public static (Exception? exOrNull, FragmentResult result) FindFragments(string
9797
}
9898
}
9999

100-
string fullFileName = Path.Combine(sectionDir, fileName);
100+
string fullFileName = Path.GetFullPath(Path.Combine(sectionDir, fileName));
101101
fragmentFiles.Add(new FragmentFile(fullFileName, fragmentBaseName.Category));
102102

103103
string data = File.ReadAllText(fullFileName);

NF.Tool.ReleaseNoteMaker/NF.Tool.ReleaseNoteMaker.Tests/TestCheck.cs

+72-7
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,27 @@ public void TestCleanup()
2828
Directory.SetCurrentDirectory(TestContext.DeploymentDirectory!);
2929
}
3030

31-
[TestMethod]
32-
public async Task TestGitFails()
31+
void Commit(string commitMessage)
32+
{
33+
Cmd.Call("git", "add .");
34+
Cmd.Call("git", $"commit -m \"{commitMessage}\"");
35+
}
36+
37+
void CreateProject(string initialBranch)
3338
{
34-
string branch = "main";
35-
Cmd.Call("git", $"init --initial-branch={branch}");
39+
Cmd.Call("git", $"init --initial-branch={initialBranch}");
3640
Cmd.Call("git", "config user.name user");
3741
Cmd.Call("git", "config user.email user@example.com");
38-
Cmd.Call("git", "add .");
39-
string message = "Initial Commit";
40-
Cmd.Call("git", $"commit -m {message}");
42+
Commit("Initial Commit");
4143
Cmd.Call("git", "checkout -b otherbranch");
44+
}
45+
46+
[TestMethod]
47+
[DeploymentItem("Template.tt")]
48+
[DeploymentItem("ReleaseNote.config.toml")]
49+
public async Task TestGitFails()
50+
{
51+
CreateProject(initialBranch: "main");
4252

4353
TestConsole c = new TestConsole();
4454
AnsiConsole.Console = c;
@@ -48,5 +58,60 @@ public async Task TestGitFails()
4858
Assert.IsTrue(c.Output.Contains("git produced output while failing"));
4959
Assert.IsTrue(c.Output.Contains("hblaugh"));
5060
}
61+
62+
[TestMethod]
63+
[DeploymentItem("Template.tt")]
64+
[DeploymentItem("ReleaseNote.config.toml")]
65+
public async Task TestNoChangesMade()
66+
{
67+
CreateProject(initialBranch: "main");
68+
69+
TestConsole c = new TestConsole();
70+
AnsiConsole.Console = c;
71+
string[] args = ["check", "--compare-with", "main"];
72+
int result = await Program.Main(args);
73+
Assert.AreEqual(0, result);
74+
Assert.AreEqual("On main branch, or no diffs, so no newsfragment required.\n", c.Output);
75+
}
76+
77+
[TestMethod]
78+
[DeploymentItem("Template.tt")]
79+
[DeploymentItem("ReleaseNote.config.toml")]
80+
public async Task TestNoChangesMadeConfigPath()
81+
{
82+
File.Move("ReleaseNote.config.toml", "not-pyproject.toml");
83+
CreateProject(initialBranch: "main");
84+
85+
TestConsole c = new TestConsole();
86+
AnsiConsole.Console = c;
87+
string[] args = ["check", "--compare-with", "main", "--config", "not-pyproject.toml"];
88+
int result = await Program.Main(args);
89+
Assert.AreEqual(0, result);
90+
Assert.AreEqual("On main branch, or no diffs, so no newsfragment required.\n", c.Output);
91+
}
92+
93+
[TestMethod]
94+
[DeploymentItem("Template.tt")]
95+
[DeploymentItem("ReleaseNote.config.toml")]
96+
public async Task TestFragmentExists()
97+
{
98+
CreateProject(initialBranch: "main");
99+
100+
File.WriteAllText("helloworld.txt", "hello world");
101+
Commit("add a file");
102+
103+
Directory.CreateDirectory("ChangeLog.d");
104+
string fpath = Path.GetFullPath("ChangeLog.d/1234.feature");
105+
File.WriteAllText(fpath, "Adds gravity back");
106+
Commit("add a newsfragment");
107+
108+
TestConsole c = new TestConsole();
109+
AnsiConsole.Console = c;
110+
AnsiConsole.Profile.Width = 255;
111+
string[] args = ["check", "--compare-with", "main"];
112+
int result = await Program.Main(args);
113+
Assert.AreEqual(0, result);
114+
Assert.IsTrue(c.Output.EndsWith($"Found:\n1. {fpath}\n"));
115+
}
51116
}
52117
}

0 commit comments

Comments
 (0)