Split test struct and handler macros out for the emitter/spec tests
This commit is contained in:
parent
115101d25d
commit
0fb59c18dd
@ -61,8 +61,10 @@ def gen_tests():
|
|||||||
def create_emitter_tests(out):
|
def create_emitter_tests(out):
|
||||||
out.write('namespace %s {\n' % NS)
|
out.write('namespace %s {\n' % NS)
|
||||||
|
|
||||||
for test in gen_tests():
|
tests = list(gen_tests())
|
||||||
out.write('inline TEST %s(YAML::Emitter& out)\n' % test['name'])
|
|
||||||
|
for test in tests:
|
||||||
|
out.write('TEST %s(YAML::Emitter& out)\n' % test['name'])
|
||||||
out.write('{\n')
|
out.write('{\n')
|
||||||
for event in test['events']:
|
for event in test['events']:
|
||||||
emit = event['emit']
|
emit = event['emit']
|
||||||
@ -82,5 +84,11 @@ def create_emitter_tests(out):
|
|||||||
|
|
||||||
out.write('}\n')
|
out.write('}\n')
|
||||||
|
|
||||||
|
out.write('void RunGenEmitterTests(int& passed, int& total)\n')
|
||||||
|
out.write('{\n')
|
||||||
|
for test in tests:
|
||||||
|
out.write(' RunGenEmitterTest(&Emitter::%s, %s, passed, total);\n' % (test['name'], encode(test['name'])))
|
||||||
|
out.write('}\n')
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
create_emitter_tests(sys.stdout)
|
create_emitter_tests(sys.stdout)
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include "tests.h"
|
#include "tests.h"
|
||||||
|
#include "handlermacros.h"
|
||||||
#include "yaml-cpp/yaml.h"
|
#include "yaml-cpp/yaml.h"
|
||||||
#include "yaml-cpp/eventhandler.h"
|
#include "yaml-cpp/eventhandler.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -1051,8 +1052,38 @@ namespace Test
|
|||||||
}
|
}
|
||||||
total++;
|
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()
|
bool RunEmitterTests()
|
||||||
{
|
{
|
||||||
int passed = 0;
|
int passed = 0;
|
||||||
@ -1143,6 +1174,8 @@ namespace Test
|
|||||||
RunEmitterErrorTest(&Emitter::InvalidAlias, "invalid alias", passed, total);
|
RunEmitterErrorTest(&Emitter::InvalidAlias, "invalid alias", passed, total);
|
||||||
RunEmitterErrorTest(&Emitter::BadLocalTag, "bad local tag", passed, total);
|
RunEmitterErrorTest(&Emitter::BadLocalTag, "bad local tag", passed, total);
|
||||||
|
|
||||||
|
RunGenEmitterTests(passed, total);
|
||||||
|
|
||||||
std::cout << "Emitter tests: " << passed << "/" << total << " passed\n";
|
std::cout << "Emitter tests: " << passed << "/" << total << " passed\n";
|
||||||
return passed == total;
|
return passed == total;
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include "teststruct.h"
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "yaml-cpp/yaml.h"
|
#include "yaml-cpp/yaml.h"
|
||||||
@ -5,8 +6,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
|
|
||||||
|
|
||||||
namespace Test {
|
namespace Test {
|
||||||
std::string Quote(const std::string& text) {
|
std::string Quote(const std::string& text) {
|
||||||
YAML::Emitter out;
|
YAML::Emitter out;
|
||||||
|
@ -5,18 +5,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <string>
|
#include "teststruct.h"
|
||||||
|
|
||||||
namespace Test {
|
namespace Test {
|
||||||
struct TEST {
|
|
||||||
TEST(): ok(false) {}
|
|
||||||
TEST(bool ok_): ok(ok_) {}
|
|
||||||
TEST(const char *error_): ok(false), error(error_) {}
|
|
||||||
|
|
||||||
bool ok;
|
|
||||||
std::string error;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Spec {
|
namespace Spec {
|
||||||
// 2.1
|
// 2.1
|
||||||
TEST SeqScalars();
|
TEST SeqScalars();
|
||||||
|
18
test/teststruct.h
Normal file
18
test/teststruct.h
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#define YAML_ASSERT(cond) do { if(!(cond)) return " Assert failed: " #cond; } while(false)
|
||||||
|
|
||||||
|
namespace Test
|
||||||
|
{
|
||||||
|
struct TEST {
|
||||||
|
TEST(): ok(false) {}
|
||||||
|
TEST(bool ok_): ok(ok_) {}
|
||||||
|
TEST(const char *error_): ok(false), error(error_) {}
|
||||||
|
|
||||||
|
bool ok;
|
||||||
|
std::string error;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user