Skip to content

Commit

Permalink
Improve base path via normalization
Browse files Browse the repository at this point in the history
We need to normalize to the fully qualified directory in order for relative paths to work properly.
  • Loading branch information
kzu committed Jul 4, 2024
1 parent 7e8a512 commit f54a541
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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
15 changes: 12 additions & 3 deletions src/dotnet-trx/TrxCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<string>();
var passed = 0;
Expand Down Expand Up @@ -275,7 +281,10 @@ void WriteError(string baseDir, List<Failed> 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));
Expand Down

0 comments on commit f54a541

Please sign in to comment.