Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for reporting to github #11

Merged
merged 3 commits into from
Jul 4, 2024
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
9 changes: 8 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ env:
VersionPrefix: 42.42.${{ github.run_number }}
VersionLabel: ${{ github.ref }}
GH_TOKEN: ${{ secrets.GH_TOKEN }}
Configuration: Release

defaults:
run:
Expand Down Expand Up @@ -68,7 +69,13 @@ jobs:
echo 'export PATH="/usr/local/opt/grep/libexec/gnubin:$PATH"' >> .bash_profile

- name: 🧪 test
uses: ./.github/workflows/test
# NOTE: we don't really want to fail since this just emits the trx. '
run: dotnet test -l trx src/Demo/ -v:q || echo Nevermind!

- name: 🧪 show
if: always()
run:
dotnet run --no-build --project ./src/dotnet-trx/ --output

- name: 🐛 logs
uses: actions/upload-artifact@v3
Expand Down
4 changes: 1 addition & 3 deletions .netconfig
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
weak
[file ".github/workflows/build.yml"]
url = https://github.com/devlooped/oss/blob/main/.github/workflows/build.yml
sha = 14deaea5cecc64df51781d29891a2f67caf8be16
etag = d9fa5d91dc601f10d19099abb55c86df065cd1c23b1f6fab98ad883cb443bf5c
weak
skip
[file ".github/workflows/changelog.config"]
url = https://github.com/devlooped/oss/blob/main/.github/workflows/changelog.config
sha = 055a8b7c94b74ae139cce919d60b83976d2a9942
Expand Down
16 changes: 11 additions & 5 deletions src/Demo/Tests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Threading.Tasks;
using Xunit.Abstractions;

Expand All @@ -7,10 +7,10 @@ namespace Demo;
public class Tests(ITestOutputHelper output)
{
[Fact]
public void ICanHasOutput() => output.WriteLine("Hello, world from xunit ITestOutputHelper!");
public void Test_With_Output() => output.WriteLine("Hello, world from xunit ITestOutputHelper!");

[Fact(Skip = "Shouldn't run for now :)")]
public void SampleSkipped() { }
public void Skipped_Test_Does_Not_Run() { }

[Theory]
[InlineData("en")]
Expand All @@ -22,10 +22,16 @@ public void SampleSkipped() { }
#pragma warning restore xUnit1026 // Theory methods should use all of their parameters

[Fact]
public void OhNoh() => Assert.Equal(42, 22);
public void Fails_With_Output()
{
output.WriteLine("It was going so well... ");
output.WriteLine("Yet you never know");
output.WriteLine("Which is why you sprinkle all these WriteLines :eyes:");
Assert.Equal(42, 22);
}

[Fact]
public void CleanStackTrace()
public void Fails_With_Complex_StackTrace()
{
Action runner = () => Run();

Expand Down
15 changes: 15 additions & 0 deletions src/dotnet-trx/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Text;

namespace Devlooped;

static class Extensions
{
public static StringBuilder AppendLineIndented(this StringBuilder builder, string value, string indent)
{
foreach (var line in value.ReplaceLineEndings().Split(Environment.NewLine))
builder.Append(indent).AppendLine(line);

return builder;
}
}
64 changes: 64 additions & 0 deletions src/dotnet-trx/Process.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Diagnostics;

namespace Devlooped;

static class Process
{
public static bool TryExecute(string program, string arguments, out string? output)
=> TryExecuteCore(program, arguments, null, out output);

public static bool TryExecute(string program, string arguments, string input, out string? output)
=> TryExecuteCore(program, arguments, input, out output);

static bool TryExecuteCore(string program, string arguments, string? input, out string? output)
{
var info = new ProcessStartInfo(program, arguments)
{
RedirectStandardOutput = true,
RedirectStandardError = true,
RedirectStandardInput = input != null
};

try
{
var proc = System.Diagnostics.Process.Start(info);
if (proc == null)
{
output = null;
return false;
}

var gotError = false;
proc.ErrorDataReceived += (_, __) => gotError = true;

if (input != null)
{
// Write the input to the standard input stream
proc.StandardInput.WriteLine(input);
proc.StandardInput.Close();
}

output = proc.StandardOutput.ReadToEnd();
if (!proc.WaitForExit(5000))
{
proc.Kill();
output = null;
return false;
}

var error = proc.StandardError.ReadToEnd();
gotError |= error.Length > 0;
output = output.Trim();
if (string.IsNullOrEmpty(output))
output = null;

return !gotError && proc.ExitCode == 0;
}
catch (Exception ex)
{
output = ex.Message;
return false;
}
}
}
2 changes: 1 addition & 1 deletion src/dotnet-trx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
args = args.Select(x => x == "-?" ? "-h" : x).ToArray();

if (args.Contains("--debug"))
Debugger.Break();
Debugger.Launch();

app.Configure(config => config.SetApplicationName(ThisAssembly.Project.ToolCommandName));

Expand Down
Loading