-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[llvm] add tool to verify mustache library #111487
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ac1c7b5
bcc4b0d
5fe47ca
28fb40f
0d150ea
e5e70b8
1c4f631
b8f3f9c
bb98aad
c60e2b5
0a20de8
8290c38
07d31b4
6e893c0
976593e
6a60eab
6a1fcc8
f1c27af
eb1e1a6
8ff1100
f4b0520
7ffaeec
746fb97
4944435
bcc86fe
2ceb0b0
95ad7a6
bb3b1ac
d8aa85c
0534a05
06da7a5
f713198
6b4f5cd
d400c29
8fa5fd7
fd7c106
29bba68
7eed82f
e73454d
b58fbcb
bb4ba40
b0ce196
561c7eb
96f6990
a247423
a0e7d48
4165fec
5b0a20a
ba4a6db
362728f
dca40c5
6fffeb2
7337a99
439955b
c7ba28b
756c3a3
db52154
1a23334
2e01630
69e5fbb
d812837
d576d69
6985fcc
cfa8e5e
fe6d4ba
093b732
6ff0b7e
fa558e5
dbfdb5d
35d717e
c85fb69
c238bbc
6bf2231
a439e55
6a73432
ee21301
8228800
f6aa0c5
f7a68bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,12 @@ | ||||||
llvm-mustachespec - LLVM tool to test Mustache Compliance Library | ||||||
================================================================= | ||||||
|
||||||
llvm-mustachespec test the mustache spec conformance of the LLVM | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
mustache library. The spec can be found here https://github.com/mustache/spec | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or something. |
||||||
|
||||||
$ llvm-mustachespec input-file | ||||||
|
||||||
.. program:: llvm-mustachespec | ||||||
|
||||||
Outputs the number of tests failures and success in the spec | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
add_llvm_utility(llvm-mustachespec | ||
llvm-mustachespec.cpp | ||
) | ||
|
||
target_link_libraries(llvm-mustachespec PRIVATE LLVMSupport) |
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,104 @@ | ||||||||||||||||||
//===- llvm-mustachespec.cpp - The LLVM Modular Optimizer | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We no longer include this line. |
||||||||||||||||||
//===----------------------------------------------------------------------===// | ||||||||||||||||||
// | ||||||||||||||||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||||||||||||||||
// See https://llvm.org/LICENSE.txt for license information. | ||||||||||||||||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||||||||||||||||
// | ||||||||||||||||||
//===----------------------------------------------------------------------===// | ||||||||||||||||||
// | ||||||||||||||||||
// Simple drivers to test the mustache spec found here | ||||||||||||||||||
// https://github.com/mustache/ | ||||||||||||||||||
// It is used to verify that the current implementation conforms to the spec | ||||||||||||||||||
// simply download the spec and pass the test files to the driver | ||||||||||||||||||
Comment on lines
+10
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
// | ||||||||||||||||||
// Currently Triple Mustache is not supported we expect the following spec | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
// test to fail: | ||||||||||||||||||
// Triple Mustache | ||||||||||||||||||
// Triple Mustache Integer Interpolation | ||||||||||||||||||
// Triple Mustache Decimal Interpolation | ||||||||||||||||||
// Triple Mustache Null Interpolation | ||||||||||||||||||
// Triple Mustache Context Miss Interpolation | ||||||||||||||||||
// Dotted Names - Triple Mustache Interpolation | ||||||||||||||||||
// Implicit Iterators - Triple Mustache | ||||||||||||||||||
// Triple Mustache - Surrounding Whitespace | ||||||||||||||||||
// Triple Mustache - Standalone | ||||||||||||||||||
// Triple Mustache With Padding | ||||||||||||||||||
// Standalone Indentation | ||||||||||||||||||
// Implicit Iterator - Triple mustache | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder whether it would make sense to include this list directly in the program, and report these as "xfail"? That way it's easy to see whether there are any unexpected failures without manually comparing to this list. |
||||||||||||||||||
// | ||||||||||||||||||
// Usage: | ||||||||||||||||||
// mustache path/to/test/file/test.json path/to/test/file/test2.json ... | ||||||||||||||||||
//===----------------------------------------------------------------------===// | ||||||||||||||||||
|
||||||||||||||||||
#include "llvm/Support/CommandLine.h" | ||||||||||||||||||
#include "llvm/Support/MemoryBuffer.h" | ||||||||||||||||||
#include "llvm/Support/Mustache.h" | ||||||||||||||||||
#include <string> | ||||||||||||||||||
|
||||||||||||||||||
using namespace llvm; | ||||||||||||||||||
using namespace llvm::json; | ||||||||||||||||||
using namespace llvm::mustache; | ||||||||||||||||||
|
||||||||||||||||||
cl::list<std::string> InputFiles(cl::Positional, cl::desc("<input files>"), | ||||||||||||||||||
cl::OneOrMore); | ||||||||||||||||||
|
||||||||||||||||||
void runThroughTest(StringRef InputFile) { | ||||||||||||||||||
llvm::outs() << "Running Tests: " << InputFile << "\n"; | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You're using |
||||||||||||||||||
ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> BufferOrError = | ||||||||||||||||||
MemoryBuffer::getFile(InputFile); | ||||||||||||||||||
|
||||||||||||||||||
if (auto EC = BufferOrError.getError()) { | ||||||||||||||||||
return; | ||||||||||||||||||
} | ||||||||||||||||||
Comment on lines
+51
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the error get reported? |
||||||||||||||||||
std::unique_ptr<llvm::MemoryBuffer> Buffer = std::move(BufferOrError.get()); | ||||||||||||||||||
llvm::StringRef FileContent = Buffer->getBuffer(); | ||||||||||||||||||
Expected<Value> Json = parse(FileContent); | ||||||||||||||||||
|
||||||||||||||||||
if (auto E = Json.takeError()) { | ||||||||||||||||||
errs() << "Parsing error: " << toString(std::move(E)) << "\n"; | ||||||||||||||||||
return; | ||||||||||||||||||
} | ||||||||||||||||||
// Get test | ||||||||||||||||||
Array *Obj = (*Json).getAsObject()->getArray("tests"); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This looks a bit odd, does this work? |
||||||||||||||||||
size_t Total = 0; | ||||||||||||||||||
size_t Success = 0; | ||||||||||||||||||
for (Value V : *Obj) { | ||||||||||||||||||
Object *TestCase = V.getAsObject(); | ||||||||||||||||||
StringRef TemplateStr = TestCase->getString("template").value(); | ||||||||||||||||||
StringRef ExpectedStr = TestCase->getString("expected").value(); | ||||||||||||||||||
StringRef Name = TestCase->getString("name").value(); | ||||||||||||||||||
Value *Data = TestCase->get("data"); | ||||||||||||||||||
Value *Partials = TestCase->get("partials"); | ||||||||||||||||||
|
||||||||||||||||||
if (!Data) | ||||||||||||||||||
continue; | ||||||||||||||||||
|
||||||||||||||||||
Template T = Template(TemplateStr); | ||||||||||||||||||
if (Partials) { | ||||||||||||||||||
for (auto &PartialPairs : *Partials->getAsObject()) { | ||||||||||||||||||
const auto &[Partial, Str] = PartialPairs; | ||||||||||||||||||
T.registerPartial((*Str.getAsString()).str(), Partial.str()); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
} | ||||||||||||||||||
std::string ActualStr; | ||||||||||||||||||
llvm::raw_string_ostream OS(ActualStr); | ||||||||||||||||||
T.render(*Data, OS); | ||||||||||||||||||
if (ExpectedStr == ActualStr) { | ||||||||||||||||||
Success++; | ||||||||||||||||||
} else { | ||||||||||||||||||
llvm::outs() << "Test Failed: " << Name << "\n"; | ||||||||||||||||||
} | ||||||||||||||||||
Total++; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
llvm::outs() << "Result " << Success << "/" << Total << " succeeded\n"; | ||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
int main(int argc, char **argv) { | ||||||||||||||||||
llvm::cl::ParseCommandLineOptions(argc, argv); | ||||||||||||||||||
for (const auto &FileName : InputFiles) { | ||||||||||||||||||
runThroughTest(FileName); | ||||||||||||||||||
} | ||||||||||||||||||
return 0; | ||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly?