/* * Copyright (c) Meta Platforms, Inc. and affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include namespace apache::thrift::conformance { // Gets and env value, returning dflt if not found. const char* getEnvOr(const char* name, const char* dflt); // Gets an env value, throwing an exception if not found. const char* getEnvOrThrow(const char* name); // Reads the contents of a file into a string. // Returns "" if filename == nullptr. std::string readFromFile(const char* filename); // Runs the given command and returns its stdout as a string. std::string readFromCmd(const std::vector& argv); // Names default to parent directory, or can be customized by appending // '#' to the command. If the command itself has a '#' character in it, // appending an additional "#" will cause it to parse correctly. std::pair parseNameAndCmd( std::string_view entry); // Parses commands (and optionally custom names) seporated by ',' std::map parseCmds( std::string_view cmdsStr); // Parses a set of non-conforming test names, seporated by '/n' // // Use # for comments. std::set parseNonconforming(std::string_view data); // Reads or generates the test suites to run. std::vector getSuites(); // Read the list of non-conforming tests. std::set getNonconforming(); // From a newer version of gtest. // // TODO(afuller): Delete once gtest is updated. template inline testing::TestInfo* registerTest( const char* test_suite_name, const char* test_name, const char* type_param, const char* value_param, const char* file, int line, Factory factory) { using TestT = typename std::remove_pointer::type; class FactoryImpl : public testing::internal::TestFactoryBase { public: explicit FactoryImpl(Factory f) : factory_(std::move(f)) {} testing::Test* CreateTest() override { return factory_(); } private: Factory factory_; }; return testing::internal::MakeAndRegisterTestInfo( test_suite_name, test_name, type_param, value_param, testing::internal::CodeLocation(file, line), testing::internal::GetTypeId(), TestT::SetUpTestCase, TestT::TearDownTestCase, new FactoryImpl{std::move(factory)}); } // Get conformance test description template std::string genDescription(const T& test) { if (test.description().has_value()) { return *test.description() + "\n"; } return ""; } // Converts conformance test tags into helpful links, so they can be reported // with failures. template std::string genTagLinks(const T& tagged) { std::string result; for (const auto& tag : *tagged.tags()) { result += " sdoc thrift/docs/" + tag + "\n"; } return result; } template std::string jsonify(const T& o) { std::string json = apache::thrift::SimpleJSONSerializer::serialize(o); return folly::toPrettyJson(folly::parseJson(std::move(json))); } } // namespace apache::thrift::conformance