How to refer to the filepath of test data in test sourcecode?

61 Views Asked by At

I'm using Make (Automake) to compile and execute unit tests. However these tests need to read and write test data. If I just specify a path, the tests only work from a specific directory. This is a problem, as first the test executables may be executed from a directory different than at compiletime by make, and secondly they should be executable even manually or in VPATH-builds, which currently brakes make distcheck

Even using srcdir, via config.h, isn't particularly useful, because it is of course evaluated at compiletime rather than at runtime. What would be nice is, if the builddir would get passed at runtime instead. What I think is necessary, is a way to get the srcdir relative to the builddir into the executable. This needs to be done/adjusted at runtime, due to the reasons written earlier. While this wouldn't solve the problem of being executed outside of the builddir, I don't think, that this is a particular problem, because, who would do that?

But would it be better to specify them via the command arguments or via the environment? And is it "better" to specify individual files or a generic directory? I would consider a PATH-like search behaviour overkill for just a test, or would that be recommended?

Or should I just give up and specify a absolute path? But I think, that would break VPATH-builds.

So the question is, how would I specify the path to a test file best, in terms of portability, interoperability, maintainability and common sense?

0

There are 0 best solutions below