Daily Usage Issues

Can I add my own clickable file paths to the test failure output?

Started by dylanbeattie on 1,716 views

Hey. First up: NCrunch continues to be awesome and one of my absolute must-have programming tools. Yay. Thank you.

My latest .NET project is an interpreter for the Rockstar programming language, and frequently when a test fails, it's because of an error in the .rock program I'm running, not an error in my .cs code.

Is there any way I can prepend a clickable file path the NCrunch test output which I can click to jump to the file/line that contained the error?

I've tried outputting the full file path, both the _AppData\Local\NCrunch version and the D:\Projects\Rockstar\ version, but the UI doesn't render it as a clickable link.

I'm assuming the links in NCrunch's test output are based on the exception stack trace or something... I've tried messing around with the exception stack trace using reflection but didn't make much headway. Is there any easy way to add/prepend my own links to the output?

[img=https://ursatile.s3.eu-west-2.amazonaws.com/ncrunch-clickable-link-image.jpg]A screenshot of the NCrunch test output with a highlighted file path[/img]

Thanks,

Dylan

Edited

Hi Dylan, thanks for posting, and for liking NCrunch so much :)

NCrunch internally replaces file paths with links when they point to files that are in the foreground solution (i.e. source files in your codebase). It actually doesn't matter what kind of source file they are, since we try to be as source agnostic as possible. The key thing is that they must be part of a project in your solution.

The file that isn't clickable here is pathed inside the NCrunch workspace rather than your solution itself. As such, it's in a temporary location used by NCrunch to build the project and run tests.

In the past we've tried to make it hard to open paths inside workspaces by making them clickable, because it then becomes extremely easy to mistake them for solution files and edit them unintentionally. When files in workspaces get changed, test and build results get desynced from the foreground solution and everything kind of falls apart.

Unless you have a way to make this file be a part of your foreground solution and have the link reference it there, I can't suggest a way to make this work for you.

Perhaps we could examine other options. Why do you need to examine this file? If you're generating it yourself, would it perhaps be worth writing its output to the test trace output? You could perhaps rig the test to automatically open an editor on the generated files when it gets run with a debugger attached (this is a trick I've used often myself).
Hey - that's what I thought; the first thing I tried was to Console.WriteLine the full path to a file that's part of my solution, but that doesn't turn it into a hyperlink. Here's an example where I've copied the exact same file path that's linked in the stack trace and Console.WriteLine()d it to see if NCrunch makes it clickable, but no:

External image

(The files I'm linking to are .rock files; they *are* part of my test project, and I'm linking to them so I can jump straight from the test failure to the point in my Rockstar program where the parser failed to see the Rockstar code which caused the failure.)

Given in this example I'm using the exact same file path in two places and only one of them's getting hyperlinked, I'm guessing it's not the file path or format that's the problem, so what's the logic that identifies the text fragment which gets hyperlinked? Does it have to be in the exception stack trace or can it be anywhere in the test output?


Thanks!

This might feel a bit messy, but could you try it with an ' at ' prefix and an ' in ' keyword so that it looks the same as an exception line?

Edited

Ah - that pointed me in the right direction. The linking is only triggered if there is a line of output which exactly matches /^ at .*in (path):line \d+\w$/

Exactly three spaces, "at", one space followed by any number of any character, the full file path, ":line", one or more spaces, one or more decimal digits, any amount of whitespace, linebreak.

Thanks!

Edited

Post a reply

Log in to reply.