Split test struct and handler macros out for the emitter/spec tests

This commit is contained in:
Jesse Beder
2012-05-22 22:10:47 -05:00
parent 115101d25d
commit 0fb59c18dd
5 changed files with 63 additions and 14 deletions

View File

@@ -1,4 +1,5 @@
#include "tests.h"
#include "handlermacros.h"
#include "yaml-cpp/yaml.h"
#include "yaml-cpp/eventhandler.h"
#include <iostream>
@@ -1051,7 +1052,37 @@ namespace Test
}
total++;
}
void RunGenEmitterTest(TEST (*test)(YAML::Emitter&), const std::string& name, int& passed, int& total) {
YAML::Emitter out;
TEST ret;
try {
ret = test(out);
} catch(const YAML::Exception& e) {
ret.ok = false;
ret.error = std::string(" Exception caught: ") + e.what();
}
if(!out.good()) {
ret.ok = false;
ret.error = out.GetLastError();
}
if(!ret.ok) {
std::cout << "Generated emitter test failed: " << name << "\n";
std::cout << "Output:\n";
std::cout << out.c_str() << "<<<\n";
std::cout << ret.error << "\n";
}
if(ret.ok)
passed++;
total++;
}
}
#include "genemittertests.h"
bool RunEmitterTests()
{
@@ -1142,6 +1173,8 @@ namespace Test
RunEmitterErrorTest(&Emitter::InvalidAnchor, "invalid anchor", passed, total);
RunEmitterErrorTest(&Emitter::InvalidAlias, "invalid alias", passed, total);
RunEmitterErrorTest(&Emitter::BadLocalTag, "bad local tag", passed, total);
RunGenEmitterTests(passed, total);
std::cout << "Emitter tests: " << passed << "/" << total << " passed\n";
return passed == total;