5

I have a test file in my module's t/ directory that does a use on a TestUtils files which has some variables and routines:

use Test;
use TestUtils;

plan 4;
check_cmd_output('No arguments');
check_cmd_output('Successfully ingested', test_md_file);
check_cmd_output('Successfully ingested', test_md_file, 1);
check_cmd_output('Successfully ingested', vimwiki_arg_sim());

It works fine. However, Comma was complaining about TestUtils not being found "in the ecosystem" as well as throwing errors with identifiers from the TestUtils module that it was not loading:

enter image description here

I was able to stop Comma from complaining by:

  1. Exporting the identifiers in the TestUtils file
  2. Fully qualifying the identifiers in my test file with something like: TestUtils::check_cmd_output(...)
  3. Adding TestUtils to the provides hash in the META6.json file.

I'm thinking there is probably a better way. I tried doing stuff like use lib 't' and use lib '.' but that did not help. Thanks.

StevieD
  • 6,925
  • 2
  • 25
  • 45

1 Answers1

4

Comma doesn't handle this situation perfectly; it understands (following the IntelliJ platform naming conventions):

  • Source roots, which are used as roots for resolving use statements within the project (anything not resolved is assumed to be from the module ecosystem)
  • Test roots, where test files are found (used for, for example, being able to run tests in an xt directory)

These are, however, mutually exclusive. If the TestUtils module were to be placed in a lib directory inside of t, then that lib directory could be marked as a source root, and the symbols should be resolved.

Jonathan Worthington
  • 29,104
  • 2
  • 97
  • 136
  • I thought about putting in `lib` but decided against that that because it would break convention. So there's no way to tell Comma/IntelliJ to make `t` a "source root?" – StevieD Apr 11 '22 at 00:08
  • 1
    You can mark it as a source root, but I believe it then ceases to be a test root. So far as breaking convention goes, I've tended to put test support modules under a `t/lib`, but I've seen them go directly into `t` also, so I'm not sure there is a solid convention here. – Jonathan Worthington Apr 11 '22 at 13:07
  • Ah, I missed the "inside of t" bit in your OP. Thanks! I'll give that a shot. – StevieD Apr 11 '22 at 13:14
  • Hmm, can't seem to get it working. I added a t/lib directory and added TestUtils into it. Then I right clicked the `t/lib` directory in the "projects" pane, and marked it as a sources root (I tried both as a "test" root and plain "sources" root) and restarted IDE. I'm still getting red squiggles from Comma. Tests still run and work fine. – StevieD Apr 11 '22 at 14:32
  • I should specify that I'm not getting red squiggle on the `use TestUtils` line any more but I am getting it on the other identifiers. All identifiers in TestUtils are exported and global. Tests still run fine with no errors so they are getting found at run time. – StevieD Apr 11 '22 at 14:38