Skip to content

Commit

Permalink
[clang-doc] Limit integration tests
Browse files Browse the repository at this point in the history
Now that the clang-doc libraries are covered by unit tests, we don't
need to have extensive (and unmaintainable) integration tests. This
replaces the integration test suite with a smaller one that just tests
the tool itself and removes extraneous dumping logic from the tool
itself.

Includes tests that cover the parse->serialize->merge->generate
pipeline, as well as tests for the --public, --format, --doxygen, and
--output flags.

Differential Revision: https://reviews.llvm.org/D53150

llvm-svn: 344655
  • Loading branch information
Julie Hockett committed Oct 16, 2018
1 parent 7f87ca6 commit 229c63b
Show file tree
Hide file tree
Showing 35 changed files with 94 additions and 4,750 deletions.
227 changes: 0 additions & 227 deletions clang-tools-extra/clang-doc/gen_tests.py

This file was deleted.

78 changes: 14 additions & 64 deletions clang-tools-extra/clang-doc/tool/ClangDocMain.cpp
Expand Up @@ -55,20 +55,15 @@ static llvm::cl::opt<std::string>
llvm::cl::desc("Directory for outputting generated files."),
llvm::cl::init("docs"), llvm::cl::cat(ClangDocCategory));

static llvm::cl::opt<bool>
DumpMapperResult("dump-mapper",
llvm::cl::desc("Dump mapper results to bitcode file."),
llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));

static llvm::cl::opt<bool> DumpIntermediateResult(
"dump-intermediate",
llvm::cl::desc("Dump intermediate results to bitcode file."),
llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));

static llvm::cl::opt<bool>
PublicOnly("public", llvm::cl::desc("Document only public declarations."),
llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));

static llvm::cl::opt<bool> DoxygenOnly(
"doxygen",
llvm::cl::desc("Use only doxygen-style comments to generate docs."),
llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));

enum OutputFormatTy {
md,
yaml,
Expand All @@ -83,10 +78,15 @@ static llvm::cl::opt<OutputFormatTy>
llvm::cl::init(OutputFormatTy::yaml),
llvm::cl::cat(ClangDocCategory));

static llvm::cl::opt<bool> DoxygenOnly(
"doxygen",
llvm::cl::desc("Use only doxygen-style comments to generate docs."),
llvm::cl::init(false), llvm::cl::cat(ClangDocCategory));
std::string getFormatString() {
switch (FormatEnum) {
case OutputFormatTy::yaml:
return "yaml";
case OutputFormatTy::md:
return "md";
}
llvm_unreachable("Unknown OutputFormatTy");
}

bool CreateDirectory(const Twine &DirName, bool ClearDirectory = false) {
std::error_code OK;
Expand All @@ -107,26 +107,6 @@ bool CreateDirectory(const Twine &DirName, bool ClearDirectory = false) {
return false;
}

bool DumpResultToFile(const Twine &DirName, const Twine &FileName,
StringRef Buffer, bool ClearDirectory = false) {
std::error_code OK;
llvm::SmallString<128> IRRootPath;
llvm::sys::path::native(OutDirectory, IRRootPath);
llvm::sys::path::append(IRRootPath, DirName);
if (CreateDirectory(IRRootPath, ClearDirectory))
return true;
llvm::sys::path::append(IRRootPath, FileName);
std::error_code OutErrorInfo;
llvm::raw_fd_ostream OS(IRRootPath, OutErrorInfo, llvm::sys::fs::F_None);
if (OutErrorInfo != OK) {
llvm::errs() << "Error opening documentation file.\n";
return true;
}
OS << Buffer;
OS.close();
return false;
}

// A function to extract the appropriate path name for a given info's
// documentation. The path returned is a composite of the parent namespaces as
// directories plus the decl name as the filename.
Expand Down Expand Up @@ -161,16 +141,6 @@ getInfoOutputFile(StringRef Root,
return Path;
}

std::string getFormatString() {
switch (FormatEnum) {
case OutputFormatTy::yaml:
return "yaml";
case OutputFormatTy::md:
return "md";
}
llvm_unreachable("Unknown OutputFormatTy");
}

// Iterate through tool results and build string map of info vectors from the
// encoded bitstreams.
bool bitcodeResultsToInfos(
Expand Down Expand Up @@ -234,17 +204,6 @@ int main(int argc, const char **argv) {
return 1;
}

if (DumpMapperResult) {
bool Err = false;
Exec->get()->getToolResults()->forEachResult(
[&](StringRef Key, StringRef Value) {
Err = DumpResultToFile("bc", Key + ".bc", Value);
});
if (Err)
llvm::errs() << "Error dumping map results.\n";
return Err;
}

// Collect values into output by key.
// In ToolResults, the Key is the hashed USR and the value is the
// bitcode-encoded representation of the Info object.
Expand All @@ -262,15 +221,6 @@ int main(int argc, const char **argv) {
continue;
}

if (DumpIntermediateResult) {
SmallString<4096> Buffer;
llvm::BitstreamWriter Stream(Buffer);
doc::ClangDocBitcodeWriter Writer(Stream);
Writer.dispatchInfoForWrite(Reduced.get().get());
if (DumpResultToFile("bc", Group.getKey() + ".bc", Buffer))
llvm::errs() << "Error dumping to bitcode.\n";
continue;
}
doc::Info *I = Reduced.get().get();

auto InfoPath =
Expand Down

0 comments on commit 229c63b

Please sign in to comment.