apjanke / octave-testify

New BIST (Built-In Self Test) functions for GNU Octave
GNU General Public License v3.0
4 stars 2 forks source link

feature request: option to strip root directory from file names #87

Open mtmiller opened 5 years ago

mtmiller commented 5 years ago

Current output

>> runtests2 .
  /home/mike/src/octave/testpkg/inst/foo.m .................... PASS      1/1

Summary:

  GNU Octave Version: 5.1.0 (hg id: d05d6eebde10)
  Tests run on galago.mtmxr.com (Unix) at 17-May-2019 14:24:30
  Test execution time: 00:00:00

  PASS                                1
  FAIL                                0

It would be nice to have an option to strip a common prefix from all file names. This would only be for the console output, the full output in the optional log file can keep the full file name. Or it can apply the filter to both if it's preferable to be consistent.

Example desired output

>> runtests2 ('-prefix', pwd, '.')
  inst/foo.m .................................................. PASS      1/1

Summary:

  GNU Octave Version: 5.1.0 (hg id: d05d6eebde10)
  Tests run on galago.mtmxr.com (Unix) at 17-May-2019 14:24:30
  Test execution time: 00:00:00

  PASS                                1
  FAIL                                0

Option name ideas include base, elide, prefix, root, strip, or some combination of those. GNU utilities like patch and tar refer to it as "stripping" file name "components", git archive adds a "prefix" to relative file names, gcc also uses the term "prefix".

apjanke commented 5 years ago

This should be doable. I'm already abbreviating the paths for files that are discovered under the Octave installation or under installed pkg packages. I could extend that for user-supplied paths.

I'd even say this should maybe be the default behavior, and not require an explicit -prefix option from the user?

Runtests2 accepts multiple paths as arguments. It could do some combination of the following:

a) When only a single path argument is given, display all the file paths as relative to that directory, like in your inst/foo.m..... example. b) If multiple path arguments are given, find some common prefix and use that? Or include just the last element of the path in each argument, instead of the full path? c) Check the filesystem and see if the test files exist under a pkg-structured Octave package layout (based on a DESCRIPTION file and inst directory); if so, display them relative to that package directory, using the package name as the abbreviation for it.

This gets more complicated when:

mtmiller commented 5 years ago

I'd even say this should maybe be the default behavior, and not require an explicit -prefix option from the user?

Sure, that would be easiest on the user.

You might even want to have a format similar to doctest, which prints indented recursive output that looks like this by default

>> doctest .

inst/
  func1.m .............................................. PASS    1/1
  func2.m .............................................. PASS    1/1
...
src/
  defun1.oct ........................................... PASS    1/1
  defun2.oct ........................................... PASS    1/1
...

>> doctest /path/to/proj

/path/to/proj/
  inst/
    func1.m ............................................ PASS    1/1
    func2.m ............................................ PASS    1/1
...
  src/
    defun1.oct ......................................... PASS    1/1
    defun2.oct ......................................... PASS    1/1
...

I could see the argument for showing a path relative to the package top-level directory even if you're in a subdirectory. Similar to how git diff shows the file name relative to the project root I suppose.

But for me the most important thing is removing the root directory, and whether that's done relative to the working dir, the argument dir, the package top dir, or an extra argument is details.