Question

I am using rebar, and I need to set the mnesia directory for my Erlang eunit tests (which you can usually do by doing erl -mnesia dir DIRECTORY at the cmdline). How do I run eunit tests with a special mnesia dir with rebar?

I do not think that the erl_opts section of the rebar.conf file will help because the mnesia directory is an emulator argument and I don't think it can be set through erlang. Also, I think these are options for when rebar compiles your code, not when it runs eunit tests. However, even if it did work, it will not work for me because I need to be able to set the directory dynamically (I am writing a Makefile where different targets have different db dirs).

Was it helpful?

Solution

What you actually are setting for Mnesia using erl -mnesia dir DIR is setting the environment variable for Mnesia, this can be set in the application resource file, as a switch from the command line as you have done or using a configuration file. The order in order of precedence is command line, config file and last the application resource file. An applications environment variables can also be set dynamically using application:set_env/3,4, this may not work in your case but it useful in many cases to get a particular (or even peculiar :-) ) setup for a test by setting the environment variables in the setup part of an eunit fixture.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top