diff --git a/GitHubIssueFormsParser/src/GitHubIssuesParserCli/GitHubIssuesParserCli.csproj b/GitHubIssueFormsParser/src/GitHubIssuesParserCli/GitHubIssuesParserCli.csproj index 09d6b1a..24cd972 100644 --- a/GitHubIssueFormsParser/src/GitHubIssuesParserCli/GitHubIssuesParserCli.csproj +++ b/GitHubIssueFormsParser/src/GitHubIssuesParserCli/GitHubIssuesParserCli.csproj @@ -1,4 +1,4 @@ - + Exe @@ -6,7 +6,7 @@ - + diff --git a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/NormalizedLineEndingsFileReader.cs b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/LineEndings.cs similarity index 74% rename from GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/NormalizedLineEndingsFileReader.cs rename to GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/LineEndings.cs index b7301c4..ee5d0a6 100644 --- a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/NormalizedLineEndingsFileReader.cs +++ b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/LineEndings.cs @@ -1,15 +1,14 @@ namespace GitHubIssuesParserCli.Tests.Auxiliary; -internal static class NormalizedLineEndingsFileReader +internal static class LineEndings { /// - /// Opens a text file, reads all text and then closes the file. + /// Updates a string so that the line endings match the OS expected line endings. /// - /// The file to open for reading. - /// A string containing all the text of the file with line endings matching the OS. - public static string ReadAllText(string path) + /// String to update. + /// A string containing line endings matching the OS expected line endings. + public static string NormalizeLineEndings(this string original) { - var original = File.ReadAllText(path); if (Environment.OSVersion.Platform == PlatformID.Win32NT && original.Contains(CR + LF, StringComparison.Ordinal)) { // if it's a Windows OS and contains Windows line endings then do nothing diff --git a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/OsDependantOutput.cs b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/OsDependantOutput.cs index c6925b3..1f6c50e 100644 --- a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/OsDependantOutput.cs +++ b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/OsDependantOutput.cs @@ -1,11 +1,11 @@ -namespace GitHubIssuesParserCli.Tests.Auxiliary; +namespace GitHubIssuesParserCli.Tests.Auxiliary; internal static class OsDependantOutput { public static string ReadAllText(string filepath) { return Environment.OSVersion.Platform == PlatformID.Unix - ? NormalizedLineEndingsFileReader.ReadAllText($"{filepath}-unix.txt") - : NormalizedLineEndingsFileReader.ReadAllText($"{filepath}-windows.txt"); + ? File.ReadAllText($"{filepath}-unix.txt").NormalizeLineEndings() + : File.ReadAllText($"{filepath}-windows.txt").NormalizeLineEndings(); } } diff --git a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/ShouldlyExtensions.cs b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/ShouldlyExtensions.cs new file mode 100644 index 0000000..c719617 --- /dev/null +++ b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/Auxiliary/ShouldlyExtensions.cs @@ -0,0 +1,11 @@ +namespace GitHubIssuesParserCli.Tests.Auxiliary; + +internal static class ShouldlyExtensions +{ + public static void ShouldBeWithNormalizedNewlines(this string actual, string expected) + { + var normalizedActual = actual.NormalizeLineEndings(); + var normalizedExpected = expected.NormalizeLineEndings(); + normalizedActual.ShouldBe(normalizedExpected); + } +} diff --git a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandTests.cs b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandTests.cs index 5829136..c4f1728 100644 --- a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandTests.cs +++ b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandTests.cs @@ -15,7 +15,7 @@ public async Task ParseIssueFormCommandTest1() using var console = new FakeInMemoryConsole(); var command = new ParseIssueFormCommand { - IssueFormBody = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/IssueBody.md"), + IssueFormBody = File.ReadAllText("./TestFiles/IssueBody.md").NormalizeLineEndings(), TemplateFilepath = "./TestFiles/Template.yml", }; await command.ExecuteAsync(console); diff --git a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandValidationTests.cs b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandValidationTests.cs index bea161c..31087d0 100644 --- a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandValidationTests.cs +++ b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliCommands/ParseIssueFormCommandValidationTests.cs @@ -140,7 +140,7 @@ public async Task InvalidIssueFormBody2() using var console = new FakeInMemoryConsole(); var command = new ParseIssueFormCommand { - IssueFormBody = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/IssueBodyWithOutOfOrderH3Headers.md"), + IssueFormBody = File.ReadAllText("./TestFiles/IssueBodyWithOutOfOrderH3Headers.md").NormalizeLineEndings(), TemplateFilepath = "./TestFiles/Template.yml", }; var exception = await Should.ThrowAsync(() => command.ExecuteAsync(console).AsTask()); @@ -163,7 +163,7 @@ public async Task InvalidIssueFormBody3() using var console = new FakeInMemoryConsole(); var command = new ParseIssueFormCommand { - IssueFormBody = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/IssueBodyWithMangledCheckbox.md"), + IssueFormBody = File.ReadAllText("./TestFiles/IssueBodyWithMangledCheckbox.md").NormalizeLineEndings(), TemplateFilepath = "./TestFiles/Template.yml", }; var exception = await Should.ThrowAsync(() => command.ExecuteAsync(console).AsTask()); diff --git a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliIntegration/CliIntegrationTests.cs b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliIntegration/CliIntegrationTests.cs index 51237b4..1d758de 100644 --- a/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliIntegration/CliIntegrationTests.cs +++ b/GitHubIssueFormsParser/tests/GitHubIssuesParserCli.Tests/CliIntegration/CliIntegrationTests.cs @@ -72,8 +72,9 @@ public async Task IssueBodyOptionValidation(string issueBody) var args = new[] { "parse-issue-form", "--issue-body", issueBody, "--template-filepath", "some filepath" }; await app.RunAsync(args); var error = console.ReadErrorString(); - var expectedError = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/CliErrorIssueBodyValidation.txt"); - error.ShouldBe(expectedError); + + var expectedError = File.ReadAllText("./TestFiles/CliErrorIssueBodyValidation.txt"); + error.ShouldBeWithNormalizedNewlines(expectedError); } /// @@ -92,8 +93,8 @@ public async Task TemplateFilepathOptionValidation(string templateFilepath) var args = new[] { "parse-issue-form", "--issue-body", "some body", "--template-filepath", templateFilepath }; await app.RunAsync(args); var error = console.ReadErrorString(); - var expectedError = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/CliErrorTemplateFilepathValidation.txt"); - error.ShouldBe(expectedError); + var expectedError = File.ReadAllText("./TestFiles/CliErrorTemplateFilepathValidation.txt"); + error.ShouldBeWithNormalizedNewlines(expectedError); } /// @@ -110,8 +111,8 @@ public async Task TemplateFilepathOptionValidation2() var args = new[] { "parse-issue-form", "--issue-body", "some body", "--template-filepath", "non-existent-file.txt" }; await app.RunAsync(args); var error = console.ReadErrorString(); - var expectedError = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/CliErrorTemplateFilepathValidation2.txt"); - error.ShouldBe(expectedError); + var expectedError = File.ReadAllText("./TestFiles/CliErrorTemplateFilepathValidation2.txt"); + error.ShouldBeWithNormalizedNewlines(expectedError); } /// @@ -126,7 +127,9 @@ public async Task ExpectedUsage(string issueFormOptionName, string templateFilep var app = new IssuesParserCli(); app.CliApplicationBuilder.UseConsole(console); - var issueFormBody = NormalizedLineEndingsFileReader.ReadAllText("./TestFiles/IssueBody.md"); + var issueFormBody = File + .ReadAllText("./TestFiles/IssueBody.md") + .NormalizeLineEndings(); const string templateFilepath = "./TestFiles/Template.yml"; var args = new[] { "parse-issue-form", issueFormOptionName, issueFormBody, templateFilepathOptionName, templateFilepath }; await app.RunAsync(args); diff --git a/docs/dev-notes/README.md b/docs/dev-notes/README.md index 7166154..d750460 100644 --- a/docs/dev-notes/README.md +++ b/docs/dev-notes/README.md @@ -37,7 +37,7 @@ 1) Clone the repo and open the **GitHubIssueFormsParser.sln** solution file at `/GitHubIssueFormsParser`. 2) Go to the test explorer in Visual Studio and run tests. -**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). +**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). ### Run tests with dotnet CLI @@ -127,9 +127,9 @@ To understand better how the action builds and executes the Docker container loo ### As of writing this, the log for building the docker action looks as follows ``` -/usr/bin/docker build --t 2bcf09:d996dfb6f4ec40c1a59c1e244bdd3374 --f "/home/runner/work/_actions/edumserrano/github-issue-forms-parser/v1/Dockerfile" +/usr/bin/docker build +-t 2bcf09:d996dfb6f4ec40c1a59c1e244bdd3374 +-f "/home/runner/work/_actions/edumserrano/github-issue-forms-parser/v1/Dockerfile" "/home/runner/work/_actions/edumserrano/github-issue-forms-parser/v1" ``` @@ -146,30 +146,30 @@ This way it can successfully build the Dockerfile for this action which would ot ### As of writing this, the log for running the docker action looks as follows ``` -/usr/bin/docker run ---name bcf09d996dfb6f4ec40c1a59c1e244bdd3374_381201 ---label 2bcf09 ---workdir /github/workspace ---rm --e INPUT_TEMPLATE-FILEPATH -e INPUT_ISSUE-FORM-BODY -e HOME --e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA --e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID --e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT --e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF --e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL --e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME --e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE --e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY --e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV --e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH --e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP --e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN --e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true --v "/var/run/docker.sock":"/var/run/docker.sock" --v "/home/runner/work/_temp/_github_home":"/github/home" --v "/home/runner/work/_temp/_github_workflow":"/github/workflow" --v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" --v "/home/runner/work/github-issue-forms-parser/github-issue-forms-parser":"/github/workspace" +/usr/bin/docker run +--name bcf09d996dfb6f4ec40c1a59c1e244bdd3374_381201 +--label 2bcf09 +--workdir /github/workspace +--rm +-e INPUT_TEMPLATE-FILEPATH -e INPUT_ISSUE-FORM-BODY -e HOME +-e GITHUB_JOB -e GITHUB_REF -e GITHUB_SHA +-e GITHUB_REPOSITORY -e GITHUB_REPOSITORY_OWNER -e GITHUB_RUN_ID +-e GITHUB_RUN_NUMBER -e GITHUB_RETENTION_DAYS -e GITHUB_RUN_ATTEMPT +-e GITHUB_ACTOR -e GITHUB_WORKFLOW -e GITHUB_HEAD_REF +-e GITHUB_BASE_REF -e GITHUB_EVENT_NAME -e GITHUB_SERVER_URL +-e GITHUB_API_URL -e GITHUB_GRAPHQL_URL -e GITHUB_REF_NAME +-e GITHUB_REF_PROTECTED -e GITHUB_REF_TYPE -e GITHUB_WORKSPACE +-e GITHUB_ACTION -e GITHUB_EVENT_PATH -e GITHUB_ACTION_REPOSITORY +-e GITHUB_ACTION_REF -e GITHUB_PATH -e GITHUB_ENV +-e GITHUB_STEP_SUMMARY -e RUNNER_OS -e RUNNER_ARCH +-e RUNNER_NAME -e RUNNER_TOOL_CACHE -e RUNNER_TEMP +-e RUNNER_WORKSPACE -e ACTIONS_RUNTIME_URL -e ACTIONS_RUNTIME_TOKEN +-e ACTIONS_CACHE_URL -e GITHUB_ACTIONS=true -e CI=true +-v "/var/run/docker.sock":"/var/run/docker.sock" +-v "/home/runner/work/_temp/_github_home":"/github/home" +-v "/home/runner/work/_temp/_github_workflow":"/github/workflow" +-v "/home/runner/work/_temp/_runner_file_commands":"/github/file_commands" +-v "/home/runner/work/github-issue-forms-parser/github-issue-forms-parser":"/github/workspace" 2bcf09:d996dfb6f4ec40c1a59c1e244bdd3374 ```