Skip to content

Commit

Permalink
Add clang_parser::parse_fail test
Browse files Browse the repository at this point in the history
Adding clang_parser::parse_fail test to test the
failure of the ClangParser::parse.

Testing the standard 'undefined struct' failure
for folowing struct:

  struct a {
    int a;
    struct b b;
  };

Also adding check on ClangParser::parse return value
in all the clang_parser tests.
  • Loading branch information
olsajiri authored and ajor committed May 26, 2019
1 parent ecb7a1b commit 6fd7aac
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tests/clang_parser.cpp
Expand Up @@ -7,14 +7,14 @@ namespace bpftrace {
namespace test {
namespace clang_parser {

void parse(const std::string &input, BPFtrace &bpftrace)
static void parse(const std::string &input, BPFtrace &bpftrace, int result = 0)
{
auto extended_input = input + "kprobe:sys_read { 1 }";
Driver driver(bpftrace);
ASSERT_EQ(driver.parse_str(extended_input), 0);

ClangParser clang;
clang.parse(driver.root_, bpftrace);
ASSERT_EQ(clang.parse(driver.root_, bpftrace), result);
}

TEST(clang_parser, integers)
Expand Down Expand Up @@ -284,6 +284,12 @@ TEST(clang_parser, macro_preprocessor)
ASSERT_EQ(macros["FOO"], "size_t");
}

TEST(clang_parser, parse_fail)
{
BPFtrace bpftrace;
parse("struct a { int a; struct b b; };", bpftrace, 1);
}

} // namespace clang_parser
} // namespace test
} // namespace bpftrace

0 comments on commit 6fd7aac

Please sign in to comment.