Hello! Would folks be against splitting rust unit ...
# development
r
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
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
What Daniel said, yea.
@hundreds-breakfast-49010, @enough-analyst-54434: any thoughts?
e
It would just be nice to hear why split them out at all.
a
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
The grep makes sense. I'm pretty sure intellij already groups usages by scope. It does for python / java / scala at any rate.
a
It doesn’t for rust 😞
e
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
Uhm. I thought
Copy code
❯ tree src
src
└── source
    ├── <http://mod.rs|mod.rs>
    └── <http://tests.rs|tests.rs>
was the idiomatic practice?
e
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
@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
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
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
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
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
yea.
a
(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
I'm in favor of splitting out tests, mostly because it makes some files less massive