In the C world I sometimes do something similar: the C file with the test code simply #include's the actual source file and gets compiled into one executable (together with some mocks).
Not too dirty (ahem...) and allows you to test various internal parts. And I must admit I got the idea after looking into Rust :)