From 18e976b38cd4961fb5a6d035efc312eeb2ae28b1 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Thu, 4 Jul 2024 02:11:08 -0300 Subject: [PATCH] Improve base path via normalization We need to normalize to the fully qualified directory in order for relative paths to work properly. --- .github/workflows/build.yml | 2 +- src/dotnet-trx/Program.cs | 2 +- src/dotnet-trx/TrxCommand.cs | 15 ++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f8ee85e..f3514c6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: - name: ๐Ÿงช test run: | dotnet test -l trx src/Demo/ -v:q || echo Nevermind! - dotnet run --no-build --project ./src/dotnet-trx/ --path ${{ github.workspace }} --output + dotnet run --no-build --project ./src/dotnet-trx/ --output - name: ๐Ÿ› logs uses: actions/upload-artifact@v3 diff --git a/src/dotnet-trx/Program.cs b/src/dotnet-trx/Program.cs index c9e29c9..15e99a0 100644 --- a/src/dotnet-trx/Program.cs +++ b/src/dotnet-trx/Program.cs @@ -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)); diff --git a/src/dotnet-trx/TrxCommand.cs b/src/dotnet-trx/TrxCommand.cs index fafa38a..dde899c 100644 --- a/src/dotnet-trx/TrxCommand.cs +++ b/src/dotnet-trx/TrxCommand.cs @@ -8,8 +8,6 @@ using System.Xml.Linq; using Devlooped.Web; using Humanizer; -using Newtonsoft.Json.Linq; -using NuGet.Protocol.Plugins; using Spectre.Console; using Spectre.Console.Cli; using static Devlooped.Process; @@ -51,6 +49,14 @@ public class TrxSettings : CommandSettings public override int Execute(CommandContext context, TrxSettings settings) { var path = settings.Path ?? Directory.GetCurrentDirectory(); + if (!Path.IsPathFullyQualified(path)) + path = Path.Combine(Directory.GetCurrentDirectory(), path); + + if (File.Exists(path)) + path = new FileInfo(path).DirectoryName; + else + path = Path.GetFullPath(path); + var search = settings.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; var testIds = new HashSet(); var passed = 0; @@ -275,7 +281,10 @@ void WriteError(string baseDir, List failures, XElement result, StringBu var file = match.Groups["file"].Value; var pos = match.Groups["line"].Value; - var relative = Path.GetRelativePath(baseDir, file); + var relative = file; + if (Path.IsPathRooted(file) && file.StartsWith(baseDir)) + relative = file[baseDir.Length..].TrimStart(Path.DirectorySeparatorChar); + // NOTE: we replace whichever was last, since we want the annotation on the // last one with a filename, which will be the test itself (see previous skip from last found). failed = new Failed(testName, message, relative, int.Parse(pos));