[pbs-devel] [PATCH proxmox-backup 03/23] maintenance: add 'Unpplugged' maintenance type

Lukas Wagner l.wagner at proxmox.com
Thu Sep 21 10:16:32 CEST 2023

On 9/21/23 09:41, Hannes Laimer wrote:
>> It's always advisable to have tests in separate submodule:
>> #[cfg(test)]
>> mod tests {
>>      use super::*;
>>      #[test]
>>      fn test_check() {
>>         ...
>>      }
>> }
>> This makes sure that the test(s) is/are not compiled during a normal 
>> build :)
> Correct me if I'm wrong but, AFAIK `#[test]` does that, and since this
> is the only and very simple test a whole mod thing seemed a bit
> overkill, so I stuck with just `#[test]`.

I stand corrected, you are indeed right. To quote [1]:
   The test attribute marks a function to be executed as a test. These
   functions are only compiled when in test mode.

Maybe I misremember some edge case where this was not the case, or maybe 
it was the way I described some time ago and they changed it. TIL.

Anyway, I still think it is good practice to put tests in a separate 
module, as it cleanly separates test code from production code. For a 
single function this does not make much difference, but maybe somebody 
else will add some more tests, extract common test setup code into 
helpers, etc. - then they would need to touch the existing code anyway 
and move it in a module. In other words, I think it's good to do it the 
'clean' way right from the start. :)

[1] https://doc.rust-lang.org/reference/attributes/testing.html

- Lukas

More information about the pbs-devel mailing list