Skip to content

Commit 594d923

Browse files
authored
Update CliFx and fix broken tests because of line endings changes (#18)
* Update CliFx and fix broken tests because of line endings changes * Update docs about required linux distro for remote test execution
1 parent a424b6a commit 594d923

File tree

8 files changed

+62
-49
lines changed

8 files changed

+62
-49
lines changed

GitHubIssueFormsParser/src/GitHubIssuesParserCli/GitHubIssuesParserCli.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net7.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="CliFx" Version="2.2.6" />
9+
<PackageReference Include="CliFx" Version="2.3.1" />
1010
<PackageReference Include="SlugGenerator" Version="2.0.2" />
1111
<PackageReference Include="YamlDotNet" Version="12.3.1" />
1212
</ItemGroup>

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/NormalizedLineEndingsFileReader.cs renamed to GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/LineEndings.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
namespace GitHubIssuesParserCli.Tests.Auxiliary;
22

3-
internal static class NormalizedLineEndingsFileReader
3+
internal static class LineEndings
44
{
55
/// <summary>
6-
/// Opens a text file, reads all text and then closes the file.
6+
/// Updates a string so that the line endings match the OS expected line endings.
77
/// </summary>
8-
/// <param name="path">The file to open for reading.</param>
9-
/// <returns>A string containing all the text of the file with line endings matching the OS.</returns>
10-
public static string ReadAllText(string path)
8+
/// <param name="path">String to update.</param>
9+
/// <returns>A string containing line endings matching the OS expected line endings.</returns>
10+
public static string NormalizeLineEndings(this string original)
1111
{
12-
var original = File.ReadAllText(path);
1312
if (Environment.OSVersion.Platform == PlatformID.Win32NT && original.Contains(CR + LF, StringComparison.Ordinal))
1413
{
1514
// if it's a Windows OS and contains Windows line endings then do nothing
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
namespace GitHubIssuesParserCli.Tests.Auxiliary;
1+
namespace GitHubIssuesParserCli.Tests.Auxiliary;
22

33
internal static class OsDependantOutput
44
{
55
public static string ReadAllText(string filepath)
66
{
77
return Environment.OSVersion.Platform == PlatformID.Unix
8-
? NormalizedLineEndingsFileReader.ReadAllText($"{filepath}-unix.txt")
9-
: NormalizedLineEndingsFileReader.ReadAllText($"{filepath}-windows.txt");
8+
? File.ReadAllText($"{filepath}-unix.txt").NormalizeLineEndings()
9+
: File.ReadAllText($"{filepath}-windows.txt").NormalizeLineEndings();
1010
}
1111
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace GitHubIssuesParserCli.Tests.Auxiliary;
2+
3+
internal static class ShouldlyExtensions
4+
{
5+
public static void ShouldBeWithNormalizedNewlines(this string actual, string expected)
6+
{
7+
var normalizedActual = actual.NormalizeLineEndings();
8+
var normalizedExpected = expected.NormalizeLineEndings();
9+
normalizedActual.ShouldBe(normalizedExpected);
10+
}
11+
}

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public async Task ParseIssueFormCommandTest1()
1515
using var console = new FakeInMemoryConsole();
1616
var command = new ParseIssueFormCommand
1717
{
18-
IssueFormBody = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/IssueBody.md"),
18+
IssueFormBody = File.ReadAllText("./TestFiles/IssueBody.md").NormalizeLineEndings(),
1919
TemplateFilepath = "./TestFiles/Template.yml",
2020
};
2121
await command.ExecuteAsync(console);

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandValidationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public async Task InvalidIssueFormBody2()
140140
using var console = new FakeInMemoryConsole();
141141
var command = new ParseIssueFormCommand
142142
{
143-
IssueFormBody = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/IssueBodyWithOutOfOrderH3Headers.md"),
143+
IssueFormBody = File.ReadAllText("./TestFiles/IssueBodyWithOutOfOrderH3Headers.md").NormalizeLineEndings(),
144144
TemplateFilepath = "./TestFiles/Template.yml",
145145
};
146146
var exception = await Should.ThrowAsync<CommandException>(() => command.ExecuteAsync(console).AsTask());
@@ -163,7 +163,7 @@ public async Task InvalidIssueFormBody3()
163163
using var console = new FakeInMemoryConsole();
164164
var command = new ParseIssueFormCommand
165165
{
166-
IssueFormBody = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/IssueBodyWithMangledCheckbox.md"),
166+
IssueFormBody = File.ReadAllText("./TestFiles/IssueBodyWithMangledCheckbox.md").NormalizeLineEndings(),
167167
TemplateFilepath = "./TestFiles/Template.yml",
168168
};
169169
var exception = await Should.ThrowAsync<CommandException>(() => command.ExecuteAsync(console).AsTask());

GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliIntegration/CliIntegrationTests.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ public async Task IssueBodyOptionValidation(string issueBody)
7272
var args = new[] { "parse-issue-form", "--issue-body", issueBody, "--template-filepath", "some filepath" };
7373
await app.RunAsync(args);
7474
var error = console.ReadErrorString();
75-
var expectedError = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/CliErrorIssueBodyValidation.txt");
76-
error.ShouldBe(expectedError);
75+
76+
var expectedError = File.ReadAllText("./TestFiles/CliErrorIssueBodyValidation.txt");
77+
error.ShouldBeWithNormalizedNewlines(expectedError);
7778
}
7879

7980
/// <summary>
@@ -92,8 +93,8 @@ public async Task TemplateFilepathOptionValidation(string templateFilepath)
9293
var args = new[] { "parse-issue-form", "--issue-body", "some body", "--template-filepath", templateFilepath };
9394
await app.RunAsync(args);
9495
var error = console.ReadErrorString();
95-
var expectedError = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/CliErrorTemplateFilepathValidation.txt");
96-
error.ShouldBe(expectedError);
96+
var expectedError = File.ReadAllText("./TestFiles/CliErrorTemplateFilepathValidation.txt");
97+
error.ShouldBeWithNormalizedNewlines(expectedError);
9798
}
9899

99100
/// <summary>
@@ -110,8 +111,8 @@ public async Task TemplateFilepathOptionValidation2()
110111
var args = new[] { "parse-issue-form", "--issue-body", "some body", "--template-filepath", "non-existent-file.txt" };
111112
await app.RunAsync(args);
112113
var error = console.ReadErrorString();
113-
var expectedError = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/CliErrorTemplateFilepathValidation2.txt");
114-
error.ShouldBe(expectedError);
114+
var expectedError = File.ReadAllText("./TestFiles/CliErrorTemplateFilepathValidation2.txt");
115+
error.ShouldBeWithNormalizedNewlines(expectedError);
115116
}
116117

117118
/// <summary>
@@ -126,7 +127,9 @@ public async Task ExpectedUsage(string issueFormOptionName, string templateFilep
126127
var app = new IssuesParserCli();
127128
app.CliApplicationBuilder.UseConsole(console);
128129

129-
var issueFormBody = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/IssueBody.md");
130+
var issueFormBody = File
131+
.ReadAllText("./TestFiles/IssueBody.md")
132+
.NormalizeLineEndings();
130133
const string templateFilepath = "./TestFiles/Template.yml";
131134
var args = new[] { "parse-issue-form", issueFormOptionName, issueFormBody, templateFilepathOptionName, templateFilepath };
132135
await app.RunAsync(args);

docs/dev-notes/README.md

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
1) Clone the repo and open the **GitHubIssueFormsParser.sln** solution file at `/GitHubIssueFormsParser`.
3838
2) Go to the test explorer in Visual Studio and run tests.
3939

40-
**Note:** [Remote testing](https://docs.microsoft.com/en-us/visualstudio/test/remote-testing?view=vs-2022) with WSL is configured on the solution which enables you to run the tests locally on Linux or on Windows. You can view the configuration file at [testenvironments.json](/GitHubIssueFormsParser/testenvironments.json). To run the tests on Linux you need to have at least `Visual Studio 2022` and the Linux distro `Ubuntu-20.04` installed on [WSL](https://docs.microsoft.com/en-us/windows/wsl/install).
40+
**Note:** [Remote testing](https://docs.microsoft.com/en-us/visualstudio/test/remote-testing?view=vs-2022) with WSL is configured on the solution which enables you to run the tests locally on Linux or on Windows. You can view the configuration file at [testenvironments.json](/GitHubIssueFormsParser/testenvironments.json). To run the tests on Linux you need to have at least `Visual Studio 2022` and the Linux distro `Ubuntu-22.04` installed on [WSL](https://docs.microsoft.com/en-us/windows/wsl/install).
4141

4242
### Run tests with dotnet CLI
4343

@@ -127,9 +127,9 @@ To understand better how the action builds and executes the Docker container loo
127127
### As of writing this, the log for building the docker action looks as follows
128128

129129
```
130-
/usr/bin/docker build
131-
-t 2bcf09:d996dfb6f4ec40c1a59c1e244bdd3374
132-
-f "/home/runner/work/_actions/edumserrano/github-issue-forms-parser/v1/Dockerfile"
130+
/usr/bin/docker build
131+
-t 2bcf09:d996dfb6f4ec40c1a59c1e244bdd3374
132+
-f "/home/runner/work/_actions/edumserrano/github-issue-forms-parser/v1/Dockerfile"
133133
"/home/runner/work/_actions/edumserrano/github-issue-forms-parser/v1"
134134
```
135135

@@ -146,30 +146,30 @@ This way it can successfully build the Dockerfile for this action which would ot
146146
### As of writing this, the log for running the docker action looks as follows
147147

148148
```
149-
/usr/bin/docker run
150-
--name bcf09d996dfb6f4ec40c1a59c1e244bdd3374_381201
151-
--label 2bcf09
152-
--workdir /github/workspace
153-
--rm
154-
-e INPUT_TEMPLATE-FILEPATH -e INPUT_ISSUE-FORM-BODY -e HOME
155-
-e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA
156-
-e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID
157-
-e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT
158-
-e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF
159-
-e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL
160-
-e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME
161-
-e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE
162-
-e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY
163-
-e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV
164-
-e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH
165-
-e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP
166-
-e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN
167-
-e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true
168-
-v "/var/run/docker.sock":"/var/run/docker.sock"
169-
-v "/home/runner/work/_temp/_github_home":"/github/home"
170-
-v "/home/runner/work/_temp/_github_workflow":"/github/workflow"
171-
-v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands"
172-
-v "/home/runner/work/github-issue-forms-parser/github-issue-forms-parser":"/github/workspace"
149+
/usr/bin/docker run
150+
--name bcf09d996dfb6f4ec40c1a59c1e244bdd3374_381201
151+
--label 2bcf09
152+
--workdir /github/workspace
153+
--rm
154+
-e INPUT_TEMPLATE-FILEPATH -e INPUT_ISSUE-FORM-BODY -e HOME
155+
-e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA
156+
-e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID
157+
-e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT
158+
-e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF
159+
-e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL
160+
-e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME
161+
-e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE
162+
-e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY
163+
-e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV
164+
-e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH
165+
-e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP
166+
-e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN
167+
-e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true
168+
-v "/var/run/docker.sock":"/var/run/docker.sock"
169+
-v "/home/runner/work/_temp/_github_home":"/github/home"
170+
-v "/home/runner/work/_temp/_github_workflow":"/github/workflow"
171+
-v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands"
172+
-v "/home/runner/work/github-issue-forms-parser/github-issue-forms-parser":"/github/workspace"
173173
2bcf09:d996dfb6f4ec40c1a59c1e244bdd3374 <template-file-path> <issue-form-body>
174174
```
175175

0 commit comments

Comments
 (0)