https://pantsbuild.org/ logo
#development
Title
# development
r

red-balloon-89377

09/26/2019, 2:20 PM
Hello! Would folks be against splitting rust unit tests into their own separate files? The structure I have in mind (to invisibly keep all the imports and stuff working) is to transform a source file into a module:
Copy code
❯ tree src
src
└── <http://source.rs|source.rs>
Would turn into:
Copy code
❯ tree src
src
└── source
    ├── <http://lib.rs|lib.rs>
    └── <http://tests.rs|tests.rs>
a

average-vr-56795

09/26/2019, 2:44 PM
I’d probably prefer to just start creating
<http://source_tests.rs|source_tests.rs>
for each file, as tests don’t tend to be imported between too much?
w

witty-crayon-22786

09/26/2019, 2:52 PM
What Daniel said, yea.
@hundreds-breakfast-49010, @enough-analyst-54434: any thoughts?
e

enough-analyst-54434

09/26/2019, 3:06 PM
It would just be nice to hear why split them out at all.
a

average-vr-56795

09/26/2019, 3:08 PM
There was a message at some point but I can’t remember where… Basically, ease of filtering in grep and intellij’s find usages, IIRC
e

enough-analyst-54434

09/26/2019, 3:10 PM
The grep makes sense. I'm pretty sure intellij already groups usages by scope. It does for python / java / scala at any rate.
a

average-vr-56795

09/26/2019, 3:10 PM
It doesn’t for rust 😞
e

enough-analyst-54434

09/26/2019, 3:11 PM
Ok
I'm not invested either way, I just wonder how the rest of the world gets by. Are we being the odd rust project here or is this a widespread pain in the community?
f

fancy-motherboard-24956

09/26/2019, 3:30 PM
Uhm. I thought
Copy code
❯ tree src
src
└── source
    ├── <http://mod.rs|mod.rs>
    └── <http://tests.rs|tests.rs>
was the idiomatic practice?
e

enough-analyst-54434

09/26/2019, 3:53 PM
It doesn’t for rust 😞
Ah yes, as it so happens yesterday this was filed: https://github.com/intellij-rust/intellij-rust/issues/4436
r

red-balloon-89377

09/26/2019, 4:42 PM
@fancy-motherboard-24956 Yeah, sorry. calling it
<http://mod.rs|mod.rs>
would be the way to do it.
I think I’ll start with splitting things into
<http://_test.rs|_test.rs>
files
a

aloof-angle-91616

09/26/2019, 5:28 PM
when are you searching for things and don’t want results in tests? i saw the intellij issue, but i don’t understand what distinction is being made or why you wouldn’t want to pull in search results from test modules?
a

average-vr-56795

09/26/2019, 5:30 PM
I frequently want to find a real example caller. My main use case I think is wanting to find out how many actual callers a thing has to know whether it’s worth re-using/renaming/changing/…, but I can’t remember off the top of my head. I just know that 90% of the time I find-usages of a symbol I want to be able to filter by prod/test…
1
a

aloof-angle-91616

09/26/2019, 5:31 PM
ok, thanks!
my search tool displays results in order by file so i think if i’ve ended up wanting that i’ve been able to work around not having an explicit split because tests are always at the bottom of the file, so i don’t interact with them unless i want to, which is why i haven’t perceived this as an issue before. thank you for describing the use case!
a

average-vr-56795

09/26/2019, 5:33 PM
We have modules where there are tests in multiple places in the file, with prod code interspersed between them… At least we did before I extracted the
store
crate, we may not any more
(That was probably an anti-pattern, and a sign that we should’ve pulled out multiple files earlier, but…)
w

witty-crayon-22786

09/26/2019, 5:36 PM
yea.
a

average-vr-56795

09/26/2019, 5:37 PM
(But also, if a thing is used in tests in a bunch of files, and non-tests in one file, getting to the right file is still a challenge)
h

hundreds-breakfast-49010

09/26/2019, 5:48 PM
I'm in favor of splitting out tests, mostly because it makes some files less massive