In this repro, the two test files contain a total of three identical tests which execute a simple function that returns a string value. Nothing exotic in either the function or tests. For some reason, a non-test file in another folder blows up the mojo test command when a struct is defined using a parameter. It makes no sense why Mojo’s test command is even looking inside that file because its name doesn’t start with test_, the file doesn’t contain any tests, nor is the file crash_mojo_test.mojoused anywhere.
While trying to understand the cause of bug #1, I discovered that pointing to the test folder while using a wildcard executes only the last test file found (bug #2). That was also unexpected. Using mojo test ./tests runs all the tests in each test file. Should I open a bug report for either or both of these? If yes, two separate bug reports or combined into one? Thanks!
I think a bug report is appropriate. To me it looks as if the issue is with identifying the test files - not all required, yet some undesired files are executed. The struct issue is already known for files that are executed by test. So I would suggest opening a single issue and linking the test issue with the structs.
Now as I have had a second look, I do not think that prefixing a file with test_ has ever been a requirement for mojo test. Only the functions in there need the prefix. As #5050 is independent on whether there is any test function, the behaviour you see with the segfault is a direct consequence of #5050 if the file matches the wildcard pattern.
With the “not all files are seen”, this might be a second issue.
The standard naming convention for Python test files is to prefix files with `test_` or use the suffix`_test.py`.This allows test discovery tools like pytest and unittest to automatically find and run test cases in those files.
My expectation was for Mojo test to follow the same file naming convention as Python, but it sounds like this is not a valid assumption. This should raise the priority for fixing #5050 to avoid crashing a functioning test suite while emitting an opaque error message. I’ve spent well over a day tracking down the cause of this crash which you documented over two months ago in #5050.
I placed a symlink to src in my tests folder so I can run individual test files in the VS Code IDE during development. The command mojo test tests follows the symlink and still finds the file `crash_mojo_test.mojo` which causes the seg fault due to #5050.
I see no way to run all of the tests at one go using a single Mojo command.
The short answer is imports from the src folder of modules to be tested. See the file PROJECT_STRUCTURE.md in Github project mojo_test for the folder structure.
Below is a sample test file from the repro.