Coverage Report

Created: 2021-08-24 07:12

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/tools/apinotes-test/APINotesTest.cpp
Line
Count
Source (jump to first uncovered line)
1
//===-- APINotesTest.cpp - API Notes Testing Tool ------------------ C++ --===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "clang/APINotes/APINotesYAMLCompiler.h"
10
#include "llvm/Support/CommandLine.h"
11
#include "llvm/Support/FileSystem.h"
12
#include "llvm/Support/MemoryBuffer.h"
13
#include "llvm/Support/Signals.h"
14
#include "llvm/Support/ToolOutputFile.h"
15
#include "llvm/Support/WithColor.h"
16
17
static llvm::cl::list<std::string> APINotes(llvm::cl::Positional,
18
                                            llvm::cl::desc("[<apinotes> ...]"),
19
                                            llvm::cl::Required);
20
21
static llvm::cl::opt<std::string>
22
    OutputFileName("o", llvm::cl::desc("output filename"),
23
                   llvm::cl::value_desc("filename"), llvm::cl::init("-"));
24
25
2
int main(int argc, const char **argv) {
26
2
  const bool DisableCrashReporting = true;
27
2
  llvm::sys::PrintStackTraceOnErrorSignal(argv[0], DisableCrashReporting);
28
2
  llvm::cl::ParseCommandLineOptions(argc, argv);
29
30
2
  auto Error = [](const llvm::Twine &Msg) {
31
0
    llvm::WithColor::error(llvm::errs(), "apinotes-test") << Msg << '\n';
32
0
  };
33
34
2
  std::error_code EC;
35
2
  auto Out = std::make_unique<llvm::ToolOutputFile>(OutputFileName, EC,
36
2
                                                    llvm::sys::fs::OF_None);
37
2
  if (EC) {
38
0
    Error("failed to open '" + OutputFileName + "': " + EC.message());
39
0
    return EXIT_FAILURE;
40
0
  }
41
42
2
  for (const std::string &Notes : APINotes) {
43
2
    llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> NotesOrError =
44
2
        llvm::MemoryBuffer::getFileOrSTDIN(Notes);
45
2
    if (std::error_code EC = NotesOrError.getError()) {
46
0
      llvm::errs() << EC.message() << '\n';
47
0
      return EXIT_FAILURE;
48
0
    }
49
50
2
    clang::api_notes::parseAndDumpAPINotes((*NotesOrError)->getBuffer(),
51
2
                                           Out->os());
52
2
  }
53
54
2
  return EXIT_SUCCESS;
55
2
}