Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
2d815c5d
Commit
2d815c5d
authored
Jun 09, 2012
by
Jesse Beder
Browse files
Added extra parser tests for the core; in particular, one that asserts instead of throwing
parent
d5130a41
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
0 deletions
+68
-0
test/core/parsertests.cpp
test/core/parsertests.cpp
+51
-0
test/parsertests.h
test/parsertests.h
+13
-0
test/tests.cpp
test/tests.cpp
+4
-0
No files found.
test/core/parsertests.cpp
0 → 100644
View file @
2d815c5d
#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
;
}
}
test/parsertests.h
0 → 100644
View file @
2d815c5d
#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
test/tests.cpp
View file @
2d815c5d
#include "tests.h"
#include "tests.h"
#include "emittertests.h"
#include "emittertests.h"
#include "parsertests.h"
#include "spectests.h"
#include "spectests.h"
#include "yaml-cpp/yaml.h"
#include "yaml-cpp/yaml.h"
#include <fstream>
#include <fstream>
...
@@ -18,6 +19,9 @@ namespace Test
...
@@ -18,6 +19,9 @@ namespace Test
if
(
!
RunSpecTests
())
if
(
!
RunSpecTests
())
passed
=
false
;
passed
=
false
;
if
(
!
RunParserTests
())
passed
=
false
;
if
(
passed
)
if
(
passed
)
std
::
cout
<<
"All tests passed!
\n
"
;
std
::
cout
<<
"All tests passed!
\n
"
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment