Can I guarantee the order of execution with multiple TEST_CASE
s with Catch? I am testing some code using LLVM, and they have some despicable global state that I need to explicitly initialize.
Right now I have one test case that's like this:
TEST_CASE("", "") {
// Initialize really shitty LLVM global variables.
llvm::InitializeAllTargets();
llvm::InitializeAllTargetMCs();
llvm::InitializeAllAsmPrinters();
llvm::InitializeNativeTarget();
llvm::InitializeAllAsmParsers();
// Some per-test setup I can make into its own function
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile(...));
CHECK_NOTHROW(Compile...));
CHECK_NOTHROW(Interpret(...));
CHECK_THROWS(Compile(...));
CHECK_THROWS(Compile(...));
}
What I want is to refactor it into three TEST_CASE
,
- one for tests that should pass compilation,
- one for tests that should fail, and
- one for tests that should pass interpretation (and in the future, further such divisions, perhaps).
But I can't simply move the test contents into another TEST_CASE
because if that TEST_CASE
is called before the one that sets up the inconvenient globals, then they won't be initialized and the testing will spuriously fail.