inject no long for FBS generation to remove logs in flattests (#7926)

* inject no long for FBS generation to remove logs in flattests

* updated blaze rules
This commit is contained in:
Derek Bailey
2023-04-28 13:40:38 -07:00
committed by GitHub
parent e7dc252b0e
commit 966aae2144
8 changed files with 113 additions and 42 deletions

View File

@@ -113,6 +113,7 @@ cc_test(
":monster_test_cc_fbs",
":native_type_test_cc_fbs",
"//:flatbuffers",
"//src:generate_fbs",
],
)

View File

@@ -1,5 +1,7 @@
#include "proto_test.h"
#include "flatbuffers/code_generator.h"
#include "idl_gen_fbs.h"
#include "test_assert.h"
namespace flatbuffers {
@@ -15,7 +17,7 @@ void RunTest(const flatbuffers::IDLOptions &opts, const std::string &proto_path,
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
// Generate fbs.
auto fbs = flatbuffers::GenerateFBS(parser, "test");
auto fbs = flatbuffers::GenerateFBS(parser, "test", true);
// Ensure generated file is parsable.
flatbuffers::Parser parser2;
@@ -25,7 +27,7 @@ void RunTest(const flatbuffers::IDLOptions &opts, const std::string &proto_path,
flatbuffers::Parser import_parser(opts);
TEST_EQ(import_parser.Parse(import_proto_file.c_str(), include_directories),
true);
auto import_fbs = flatbuffers::GenerateFBS(import_parser, "test");
auto import_fbs = flatbuffers::GenerateFBS(import_parser, "test", true);
// Since `imported.fbs` isn't in the filesystem AbsolutePath can't figure it
// out by itself. We manually construct it so Parser works.
std::string imported_fbs = flatbuffers::PosixPath(
@@ -222,6 +224,8 @@ void ParseCorruptedProto(const std::string &proto_path) {
std::string proto_file;
std::unique_ptr<CodeGenerator> fbs_generator = NewFBSCodeGenerator(true);
// Parse proto with non positive id.
{
flatbuffers::Parser parser(opts);
@@ -230,8 +234,8 @@ void ParseCorruptedProto(const std::string &proto_path) {
false, &proto_file),
true);
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
auto fbs = flatbuffers::GenerateFBS(parser, "test");
TEST_EQ(fbs.empty(), true);
TEST_NE(fbs_generator->GenerateCode(parser, "temp.fbs", "test"),
CodeGenerator::Status::OK);
}
// Parse proto with twice id.
@@ -241,8 +245,8 @@ void ParseCorruptedProto(const std::string &proto_path) {
false, &proto_file),
true);
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
auto fbs = flatbuffers::GenerateFBS(parser, "test");
TEST_EQ(fbs.empty(), true);
TEST_NE(fbs_generator->GenerateCode(parser, "temp.fbs", "test"),
CodeGenerator::Status::OK);
}
// Parse proto with using reserved id.
@@ -252,8 +256,8 @@ void ParseCorruptedProto(const std::string &proto_path) {
false, &proto_file),
true);
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
auto fbs = flatbuffers::GenerateFBS(parser, "test");
TEST_EQ(fbs.empty(), true);
TEST_NE(fbs_generator->GenerateCode(parser, "temp.fbs", "test"),
CodeGenerator::Status::OK);
}
// Parse proto with error on gap.
@@ -264,8 +268,9 @@ void ParseCorruptedProto(const std::string &proto_path) {
&proto_file),
true);
TEST_EQ(parser.Parse(proto_file.c_str(), include_directories), true);
auto fbs = flatbuffers::GenerateFBS(parser, "test");
TEST_EQ(fbs.empty(), true);
TEST_NE(fbs_generator->GenerateCode(parser, "temp.fbs", "test"),
CodeGenerator::Status::OK);
}
}

View File

@@ -17,6 +17,7 @@
#endif
#define TEST_EQ(exp, val) TestEq(exp, val, "'" #exp "' != '" #val "'", __FILE__, __LINE__, "")
#define TEST_NE(exp, val) TestNe(exp, val, "'" #exp "' == '" #val "'", __FILE__, __LINE__, "")
#define TEST_ASSERT(val) TestEq(true, !!(val), "'" "true" "' != '" #val "'", __FILE__, __LINE__, "")
#define TEST_NOTNULL(val) TestEq(true, (val) != nullptr, "'" "nullptr" "' == '" #val "'", __FILE__, __LINE__, "")
#define TEST_EQ_STR(exp, val) TestEqStr(exp, val, "'" #exp "' != '" #val "'", __FILE__, __LINE__, "")
@@ -106,4 +107,24 @@ inline void TestEq<std::string, std::string>(std::string expval,
}
}
template<typename T, typename U>
void TestNe(T expval, U val, const char *exp, const char *file, int line,
const char *func) {
if (static_cast<U>(expval) == val) {
TestFail(flatbuffers::NumToString(scalar_as_underlying(expval)).c_str(),
flatbuffers::NumToString(scalar_as_underlying(val)).c_str(), exp,
file, line, func);
}
}
template<>
inline void TestNe<std::string, std::string>(std::string expval,
std::string val, const char *exp,
const char *file, int line,
const char *func) {
if (expval == val) {
TestFail(expval.c_str(), val.c_str(), exp, file, line, func);
}
}
#endif // !TEST_ASSERT_H