lunarmodules/busted

busted --list not working

gennaro-tedesco opened this issue · 8 comments

Description

It is unclear how busted lists the available tests in a working directory, and in particular it seems the option -l does not do. As per documentation

-l, --list list the names of all tests instead of running them

How to reproduce

mkdir test
cd test && mkdir spec
cd spec && touch test_spec.lua

giving raise to

test
└── spec
   └── test_spec.lua

Issuing busted -l anywhere in such a path does not give any output. I have tried to explicitly force busted -C test/spec -l but I still get no output.

Issue

  1. how to list all available tests in a certain working directory?
  2. (optional) how to list all available tags for tests in a certain working directory?

if you add an actual test in that file does it get listed?

It seems that tests are detected only if you are in the directory where /spec is a direct child (not nested). If you are in /spec already or if you are in a parent directory the listing does not work.

I suspect it is just a matter of passing the correct directory path to look into recursively. I would expect something along the lines of

busted -l -R

to work, but it does not.

that is expected behavior. If you were to tell busted where the specs were located by passing it the path it would find them.

like busted path/spec

Well, but if one already knows where the tests are located what is the point of listing them? :p

The use case I have in mind is that in a large project, starting from the project root, I would like to output where the tests are located (together with their tags or names or so), because one may have different subdirectories each of which containing their own test folders. If one has to navigate to each sub-folder containing the tests, then this would defy the purpose of listing the tests in the first place, or did I misunderstand how this works?

I cannot reproduce this.

I have a Lua module in a folder binaryheap.lua, inside that repo, the tests are within spec.

These commands list all tests in that repo:

  • busted -l binaryheap.lua/
  • busted -l binaryheap.lua/spec/
  • cd binaryheap.lua && busted -l
  • cd binaryheap.lua && busted -l spec/

The problem with the reproduction steps is that it defines a test file, but no tests.

This should work:

mkdir test
cd test && mkdir spec
echo "it('my-test', function() end)" > spec/mytest_spec.lua
busted -l

@gennaro-tedesco your use-case seems to be about finding files, where the -l options lists actual tests.

When looking for tests, Busted will actually parse all files. In my basic testing I quickly ran into issues because the parser fails to load a bunch of files simply because they refer to relative file paths that simply aren't available from the root directory. Only from where they are supposed to be ran.

The --pattern option defaults to _spec to find test files. So imo your best option is to use a unix command to scan a tree for files matching that pattern. Once you have those files, you can try and use the -l option on those files (though as mentioned, that might still cause issues).

I see, thank you very much for clarifying the use of the command, I will do as you recommend!