This commit enables the tests located in test/YAMLParser directory.
Those tests were never actually enabled, as llvm-lit didn't pick up the
files with the 'data' extension. The commit renames those test files to files
with the 'test' extension so that llvm-lit would find them.
This commit also modifies yaml-bench so that it returns an error status
if an error occurred during parsing. It also adds the '-use-color'
command line option to yaml-bench (to make sure that file check matches
the error messages in the output stream).
This commit modifies some of the renamed tests so that they wouldn't
fail. It gets rid of XFAILs and uses the 'not' command instead for
some of the tests that have to fail during parsing. This commit
also adds some 'FIXME' comments to a couple of tests that are
supposed to fail but currently pass because of various bugs
in the implementation of the yaml parser.
Reviewers: Justin Bogner
Differential Revision: http://reviews.llvm.org/D9448
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236754
91177308-0d34-0410-b5e6-
96231b3b80d8
class Stream {
public:
/// \brief This keeps a reference to the string referenced by \p Input.
- Stream(StringRef Input, SourceMgr &);
+ Stream(StringRef Input, SourceMgr &, bool ShowColors = true);
- Stream(MemoryBufferRef InputBuffer, SourceMgr &);
+ Stream(MemoryBufferRef InputBuffer, SourceMgr &, bool ShowColors = true);
~Stream();
document_iterator begin();
/// @brief Scans YAML tokens from a MemoryBuffer.
class Scanner {
public:
- Scanner(StringRef Input, SourceMgr &SM);
- Scanner(MemoryBufferRef Buffer, SourceMgr &SM_);
+ Scanner(StringRef Input, SourceMgr &SM, bool ShowColors = true);
+ Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors = true);
/// @brief Parse the next token and return it without popping it.
Token &peekNext();
void printError(SMLoc Loc, SourceMgr::DiagKind Kind, const Twine &Message,
ArrayRef<SMRange> Ranges = None) {
- SM.PrintMessage(Loc, Kind, Message, Ranges);
+ SM.PrintMessage(Loc, Kind, Message, Ranges, /* FixIts= */ None, ShowColors);
}
void setError(const Twine &Message, StringRef::iterator Position) {
/// @brief True if an error has occurred.
bool Failed;
+ /// @brief Should colors be used when printing out the diagnostic messages?
+ bool ShowColors;
+
/// @brief Queue of tokens. This is required to queue up tokens while looking
/// for the end of a simple key. And for cases where a single character
/// can produce multiple tokens (e.g. BlockEnd).
return EscapedInput;
}
-Scanner::Scanner(StringRef Input, SourceMgr &sm) : SM(sm) {
+Scanner::Scanner(StringRef Input, SourceMgr &sm, bool ShowColors)
+ : SM(sm), ShowColors(ShowColors) {
init(MemoryBufferRef(Input, "YAML"));
}
-Scanner::Scanner(MemoryBufferRef Buffer, SourceMgr &SM_) : SM(SM_) {
+Scanner::Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors)
+ : SM(SM_), ShowColors(ShowColors) {
init(Buffer);
}
return false;
}
-Stream::Stream(StringRef Input, SourceMgr &SM)
- : scanner(new Scanner(Input, SM)), CurrentDoc() {}
+Stream::Stream(StringRef Input, SourceMgr &SM, bool ShowColors)
+ : scanner(new Scanner(Input, SM, ShowColors)), CurrentDoc() {}
-Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM)
- : scanner(new Scanner(InputBuffer, SM)), CurrentDoc() {}
+Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM, bool ShowColors)
+ : scanner(new Scanner(InputBuffer, SM, ShowColors)), CurrentDoc() {}
Stream::~Stream() {}
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
+# RUN: not yaml-bench -canonical %s 2>&1 | FileCheck %s
# Invalid use of BOM
# inside a
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
+# RUN: not yaml-bench -canonical %s 2>&1 | FileCheck %s
commercial-at: @text
grave-accent: `text
# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
#
+# FIXME: This test should actually fail. Yaml-bench should report an error
+# that a tab is being used to indent a plain scalar at line 15.
# We don't currently reject tabs as indentation.
-# XFAIL: *
# Tabs do's and don'ts:
# comment:
elsewhere: # separation
indentation, in plain scalar
-# CHECK: error
+
+# CHECK: !!str "Quoted\t\t"
+++ /dev/null
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
-
-Bad escapes:
- "\c
- \xq-"
-
-# CHECK: error
--- /dev/null
+# RUN: not yaml-bench -canonical %s 2>&1 | FileCheck %s
+
+Bad escapes:
+ "\c
+ \xq-"
+
+# CHECK: error
+++ /dev/null
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
-
-%YAML 1.1
-%YAML 1.1
-foo
-
-# CHECK: error
--- /dev/null
+# RUN: not yaml-bench -canonical %s 2>&1 | FileCheck %s
+
+%YAML 1.1
+%YAML 1.1
+foo
+
+# CHECK: error
+++ /dev/null
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
-#
-# We don't currently parse TAG directives.
-# XFAIL: *
-
-%TAG ! !foo
-%TAG ! !foo
-bar
-
-# CHECK: error
--- /dev/null
+# RUN: not yaml-bench -canonical %s 2>&1 | FileCheck %s
+#
+# We don't currently parse TAG directives.
+# CHECK: error: Unexpected token
+
+%TAG ! !foo
+%TAG ! !foo
+bar
+++ /dev/null
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
-#
-# We don't currently look at the content of literal tags.
-# XFAIL: *
-
-- !<!> foo
-- !<$:?> bar
-
-# CHECK: error
--- /dev/null
+# RUN: not yaml-bench -canonical %s 2>&1 | FileCheck %s
+#
+# We don't currently look at the content of literal tags.
+# CHECK: error: Unknown tag handle
+
+- !<!> foo
+- !<$:?> bar
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
+# RUN: not yaml-bench -canonical %s 2>&1 | FileCheck %s
#
# We don't currently validate tags.
-# XFAIL: *
+# CHECK: error: Unknown tag handle
%TAG !o! tag:ben-kiki.org,2000:
---
- !o! bar
- !h!type baz
-# CHECK: error
+++ /dev/null
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
-#
-# Indent trimming is not yet implemented.
-# XFAIL: *
-
- "as space
- trimmed
-
- specific
-
- escaped \
- none"
-
-# CHECK: !!str "as space trimmed\nspecific\nescaped\tnone"
--- /dev/null
+# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
+
+ "as space
+ trimmed
+
+ specific
+
+ escaped \
+ none"
+
+# FIXME: The string below should actually be
+# "as space trimmed\nspecific\nescaped\tnone", but the parser currently has
+# a bug when parsing multiline quoted strings.
+# CHECK: !!str "as space\n trimmed\n specific\n escaped\t none"
+++ /dev/null
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
-#
-# Not quite sure why this doesn't fail.
-# XFAIL: *
-
----
---- ||| : foo
-... >>>: bar
----
-[
----
-,
-... ,
-{
---- :
-... # Nested
-}
-]
-...
-
-# CHECK: error
--- /dev/null
+# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
+#
+# FIXME: This test should actually fail. Yaml bench should report an error that
+# says that the '---' and '...' document start/end markers must not be specified
+# as the first content line of a non-indented plain scalar.
+# CHECK: !!str
+
+---
+--- ||| : foo
+... >>>: bar
+---
+[
+---
+,
+... ,
+{
+--- :
+... # Nested
+}
+]
+...
-# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
+# RUN: not yaml-bench -canonical %s 2>&1 | FileCheck %s
- |
# RUN: yaml-bench -canonical %s 2>&1 | FileCheck %s
#
-# This fails because even without a key token, some contexts (in this case flow
-# maps) allow implicit null keys, which mix with this in weird ways.
-# XFAIL: *
+# FIXME: This test should fail. Yaml bench should report an error that a simple
+# key spans across multiple lines and that another simple key is longer than
+# 1024 characters.
{
multi-line
very long ...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................(>1KB)................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................... key: value
}
-# CHECK: error
+# CHECK: ? !!str "very long
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/Timer.h"
+#include "llvm/Support/Process.h"
#include "llvm/Support/YAMLParser.h"
#include "llvm/Support/raw_ostream.h"
#include <system_error>
"Do not use more megabytes of memory"),
cl::init(1000));
+cl::opt<cl::boolOrDefault>
+ UseColor("use-color", cl::desc("Emit colored output (default=autodetect)"),
+ cl::init(cl::BOU_UNSET));
+
struct indent {
unsigned distance;
indent(unsigned d) : distance(d) {}
int main(int argc, char **argv) {
llvm::cl::ParseCommandLineOptions(argc, argv);
+ bool ShowColors = UseColor == cl::BOU_UNSET
+ ? sys::Process::StandardOutHasColors()
+ : UseColor == cl::BOU_TRUE;
if (Input.getNumOccurrences()) {
ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
MemoryBuffer::getFileOrSTDIN(Input);
}
if (DumpCanonical) {
- yaml::Stream stream(Buf.getBuffer(), sm);
+ yaml::Stream stream(Buf.getBuffer(), sm, ShowColors);
dumpStream(stream);
+ if (stream.failed())
+ return 1;
}
}