mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 04:41:16 +00:00
Added extra parser tests for the core; in particular, one that asserts instead of throwing
This commit is contained in:
51
test/core/parsertests.cpp
Normal file
51
test/core/parsertests.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "parsertests.h"
|
||||
#include "handlermacros.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace Test
|
||||
{
|
||||
namespace Parser {
|
||||
TEST BadDocStart()
|
||||
{
|
||||
try {
|
||||
HANDLE("---{header: {id: 1");
|
||||
} catch(const YAML::ParserException& e) {
|
||||
YAML_ASSERT(true);
|
||||
return true;
|
||||
}
|
||||
return " no exception caught";
|
||||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
void RunParserTest(TEST (*test)(), const std::string& name, int& passed, int& total) {
|
||||
TEST ret;
|
||||
try {
|
||||
ret = test();
|
||||
} catch(const YAML::Exception& e) {
|
||||
ret.ok = false;
|
||||
ret.error = std::string(" Exception caught: ") + e.what();
|
||||
}
|
||||
|
||||
if(!ret.ok) {
|
||||
std::cout << "Spec test " << index << " failed: " << name << "\n";
|
||||
std::cout << ret.error << "\n";
|
||||
}
|
||||
|
||||
if(ret.ok)
|
||||
passed++;
|
||||
total++;
|
||||
}
|
||||
}
|
||||
|
||||
bool RunParserTests()
|
||||
{
|
||||
int passed = 0;
|
||||
int total = 0;
|
||||
RunParserTest(&Parser::BadDocStart, "Bad doc start", passed, total);
|
||||
|
||||
std::cout << "Parser tests: " << passed << "/" << total << " passed\n";
|
||||
return passed == total;
|
||||
}
|
||||
}
|
13
test/parsertests.h
Normal file
13
test/parsertests.h
Normal file
@@ -0,0 +1,13 @@
|
||||
#ifndef PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
#define PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
||||
#if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
namespace Test {
|
||||
bool RunParserTests();
|
||||
}
|
||||
|
||||
#endif // PARSERTESTS_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
||||
|
@@ -1,5 +1,6 @@
|
||||
#include "tests.h"
|
||||
#include "emittertests.h"
|
||||
#include "parsertests.h"
|
||||
#include "spectests.h"
|
||||
#include "yaml-cpp/yaml.h"
|
||||
#include <fstream>
|
||||
@@ -17,6 +18,9 @@ namespace Test
|
||||
|
||||
if(!RunSpecTests())
|
||||
passed = false;
|
||||
|
||||
if(!RunParserTests())
|
||||
passed = false;
|
||||
|
||||
if(passed)
|
||||
std::cout << "All tests passed!\n";
|
||||
|
Reference in New Issue
Block a user