mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
This PR corrects misspellings identified by the [check-spelling action](https://github.com/marketplace/actions/check-spelling). The misspellings have been reported at https://github.com/jsoref/carbon-lang/commit/38a1c1640151899fd6da0442a92557f9543b6280#commitcomment-79197316 The action reports that the changes in this PR would make it happy: https://github.com/jsoref/carbon-lang/commit/173c8f9083a68aa61f7cfe94f720f1e5dc7f1ea3 Note: this PR does not include the action. If you're interested in running a spell check on every PR and push, that can be offered separately. Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
74 lines
2.3 KiB
C++
74 lines
2.3 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#include "explorer/fuzzing/fuzzer_util.h"
|
|
|
|
#include <gmock/gmock.h>
|
|
#include <gtest/gtest.h>
|
|
|
|
#include <fstream>
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
namespace Carbon::Testing {
|
|
namespace {
|
|
|
|
static std::vector<llvm::StringRef>* carbon_files = nullptr;
|
|
|
|
// A workaround for https://github.com/carbon-language/carbon-lang/issues/1208.
|
|
TEST(FuzzerUtilTest, RunFuzzerOnCorpus) {
|
|
int parsed_file_count = 0;
|
|
for (const llvm::StringRef f : *carbon_files) {
|
|
llvm::outs() << "Processing " << f << "\n";
|
|
std::ifstream file(f.str(), std::ios::in);
|
|
ASSERT_TRUE(file.is_open());
|
|
std::stringstream contents;
|
|
contents << file.rdbuf();
|
|
// Parsing errors are ignored to make the fuzzer inputs less brittle as the
|
|
// explorer code changes. This also matches standard fuzzer behavior.
|
|
if (auto carbon_proto = ParseCarbonTextProto(contents.str());
|
|
carbon_proto.ok()) {
|
|
ParseAndExecute(carbon_proto->compilation_unit());
|
|
++parsed_file_count;
|
|
}
|
|
}
|
|
EXPECT_GT(parsed_file_count, 0);
|
|
}
|
|
|
|
TEST(FuzzerUtilTest, GetRunfilesFile) {
|
|
EXPECT_THAT(*Internal::GetRunfilesFile("carbon/explorer/data/prelude.carbon"),
|
|
testing::EndsWith("/prelude.carbon"));
|
|
EXPECT_THAT(Internal::GetRunfilesFile("nonexistent-file").error().message(),
|
|
testing::EndsWith("doesn't exist"));
|
|
}
|
|
|
|
TEST(FuzzerUtilTest, ParseCarbonTextProtoWithUnknownField) {
|
|
const ErrorOr<Fuzzing::Carbon> carbon_proto =
|
|
ParseCarbonTextProto(R"(
|
|
compilation_unit {
|
|
garbage: "value"
|
|
declarations {
|
|
choice {
|
|
name: "Ch"
|
|
}
|
|
}
|
|
})",
|
|
/*allow_unknown=*/true);
|
|
ASSERT_TRUE(carbon_proto.ok());
|
|
// No EqualsProto in gmock - https://github.com/google/googletest/issues/1761.
|
|
EXPECT_EQ(carbon_proto->compilation_unit().declarations(0).choice().name(),
|
|
"Ch");
|
|
}
|
|
|
|
} // namespace
|
|
} // namespace Carbon::Testing
|
|
|
|
auto main(int argc, char** argv) -> int {
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
Carbon::Testing::carbon_files =
|
|
new std::vector<llvm::StringRef>(&argv[1], &argv[argc]);
|
|
return RUN_ALL_TESTS();
|
|
}
|