question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hide test files in Golang repos

See original GitHub issue

Test URL: https://github.com/andersfylling/disgord/

First of, when I use the word hide I mean removing the table row which contains the test file. Not remove the possibility to access the test file, just reduce the number rows for Go projects.

Go test files and the feature

This feature regards Go only. Go has built-in unit testing such that most devs usually define a test file for several of their source files. Example:

As you can see, there are several _test files. The naming scheme is to simply add _test to any source file, and it indicates that there are unit tests specifically for that source file. However, when looking at the files on GitHub, there’s no real reason to use another row just for a dedicated test file.

Visually I would want this (before):

To look like this (after). Basically remove the extra rows. Example1 (purple/blue marks the space saved):

This saves a lot of extra rows in github repos with +10 test files. I know I only look at the file names to realize which features a repository holds, and get an idea of the structuring. As such, I’m not interested in seeing the filename duplicate just to show that it has tests.

That said, the visualization I show in example1 is just to showcase the space saved. I don’t think it would be pleasent UX to hide the row and not clearly display the test file. In my example you see the _test.go word is added, which every Go developer recognizes as a test file. I do want to still access the test files, and I think it should be clearly identified that the file is clickable. I’m just not sure how to design that.

Example2, showcase the file existence better than example1:

This displays that the file exists, has a different background color to make it easier to realize that there’s a new element in the row. The text also has a blue url color to it, to indicate it’s a url/clickable. Note that I also respect the paddings on either side, and that the column width is fixed for all.

I do not want to remove test files that are not designated to a source file however. (I don’t have a example image atm) so this collection:

  • a.go
  • b.go
  • feature_test.go

Should still show the file named feature_test.go as there are no files named feature.go.

Psuedo logic for filtering

Since GitHub sorts the files by name. It means that every test file should appear right below the source file it is designated for. With the assumption that all files are always sorted in this order, I can make the filter have a complexity of O(N), N for number of files. If the sorting differs or changes by a plugin or a change in the github UI, the complexity will be O((N-1) + N), yes I’m aware that we remove constants from the BigO, but since we’re not dealing with millions of entries, it seems defensible.

psuedo code for sorted files:

for (i=0; i < len(filenames) - 1; i++)
  file = filenames[i]
  if (!file.suffix(".go")) {
    continue
  }
  if (file.withoutExtension + "_test" != filenames[i + 1].withoutExtension) {
    continue
  }
  file.addTestLink(filenames[i + 1].url)
  filenames[i + 1].hide()

You can even speed this up by going from bottom up:

for (i=len(filenames) - 1; i > 0; i--)
  file = filenames[i]
  if (!file.suffix("_test.go")) {
    continue
  }
  if (file.withoutSuffix("_test.go") != filenames[i - 1].withoutExtension) {
    continue
  }
  file.hide()
  filenames[i - 1].addTestLink(file.url)

Before and after filtering

This looks horrible on phone. But on desktop they stack horizontally.

These images are missing the _test.go “button” for their respective files. It’s just to show a comparison of space use. This becomes even greater for projects that has a test file for every single source file. Which is not uncommon.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:6
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jeronecommented, Feb 27, 2019

I like the counter. We could combine that with indenting the combined files under the main file when they are expanded. Maybe with a collapsible arrow.

image

That does mean some reordering of files, based on a priority. See example above where FormAbout.cs is moved above FormAbout.Designer.cs.

1reaction
fregantecommented, Feb 26, 2019

At first sight it does look like you’re describing https://github.com/sindresorhus/hide-files-on-github, but you just want to make the list more compact by grouping related files.

If this can be applied to other languages I think it could make sense as part of RGH, otherwise no.

I think I’ve seen a similar practice in JS as well for .spec.js and .test.js files.

Maybe group-sibling-test-files?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hide test files in Golang repos · Issue #1813 - GitHub
First of, when I use the word hide I mean removing the table row which contains the test file. Not remove the possibility...
Read more >
In Goland, how can I hide test files underneath each non-test ...
1 Answer 1 · under the project view window · click on the cogwheel · select File Nesting... · click on the "Child...
Read more >
Specify what appears in Golang test coverage
Refining the coverage. As I was never going to test the generated files I decided to see if I could remove them from...
Read more >
Go Modules Reference - The Go Programming Language
Introduction. Modules are how Go manages dependencies. This document is a detailed reference manual for Go's module system. For an introduction to creating ......
Read more >
Excluding directories and files from the import process
When you import a repository to be tested by Snyk Code, you can exclude certain directories and files from the import by using...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found