Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CliFx" Version="2.2.6" />
<PackageReference Include="CliFx" Version="2.3.1" />
<PackageReference Include="SlugGenerator" Version="2.0.2" />
<PackageReference Include="YamlDotNet" Version="12.3.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
namespace GitHubIssuesParserCli.Tests.Auxiliary;

internal static class NormalizedLineEndingsFileReader
internal static class LineEndings
{
/// <summary>
/// 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.
/// </summary>
/// <param name="path">The file to open for reading.</param>
/// <returns>A string containing all the text of the file with line endings matching the OS.</returns>
public static string ReadAllText(string path)
/// <param name="path">String to update.</param>
/// <returns>A string containing line endings matching the OS expected line endings.</returns>
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
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CommandException>(() => command.ExecuteAsync(console).AsTask());
Expand All @@ -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<CommandException>(() => command.ExecuteAsync(console).AsTask());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
}

/// <summary>
Expand All @@ -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);
Expand Down
56 changes: 28 additions & 28 deletions docs/dev-notes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"
```

Expand All @@ -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 <template-file-path> <issue-form-body>
```

Expand Down