www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - unit testing version statements

reply "Robert burner Schadek" <rburners gmail.com> writes:
How do I unit test version statements without fixing version in 
place forever.

----------------
bool fun() {
     version(Version1) return true;
     else version(Version2) return true;
     else return false;
}

version = Version1;
unittest {
     assert(fun());
}

version = Version2;
unittest {
     assert(fun());
}

unittest {
     assert(!fun());
}

version = None; // is there anyway to save and reset the version
----------------
Aug 22 2014
parent reply "Kagamin" <spam here.lot> writes:
Compile and run the tests with different version options.
Aug 22 2014
parent reply "Robert burner Schadek" <rburners gmail.com> writes:
On Friday, 22 August 2014 at 09:33:10 UTC, Kagamin wrote:
 Compile and run the tests with different version options.
that is not an option
Aug 22 2014
next sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Friday, 22 August 2014 at 09:37:30 UTC, Robert burner Schadek 
wrote:
 On Friday, 22 August 2014 at 09:33:10 UTC, Kagamin wrote:
 Compile and run the tests with different version options.
that is not an option
Well, that's normally how it would be done. But if you need to test them all with the same build, it's probably easier if the unit tests are in separate modules, since then you can just set the version for the module without having to worry about resetting it. - Jonathan M Davis
Aug 22 2014
prev sibling parent "Dicebot" <public dicebot.lv> writes:
On Friday, 22 August 2014 at 09:37:30 UTC, Robert burner Schadek 
wrote:
 On Friday, 22 August 2014 at 09:33:10 UTC, Kagamin wrote:
 Compile and run the tests with different version options.
that is not an option
This is how version feature is intentionally designed to work
Aug 22 2014