Skip to content

Commit a846215

Browse files
committed
[clang][clang-doc] add a test case
1 parent 6fee7d0 commit a846215

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

clang-tools-extra/clang-doc/tool/ClangDocMain.cpp

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ static llvm::cl::list<std::string> UserStylesheets(
8181
llvm::cl::desc("CSS stylesheets to extend the default styles."),
8282
llvm::cl::cat(ClangDocCategory));
8383

84-
static llvm::cl::opt<std::string>
85-
UserAssetPath("asset",
86-
llvm::cl::desc("User supplied asset path to "
87-
"override the default css and js files for html output"),
88-
llvm::cl::cat(ClangDocCategory));
84+
static llvm::cl::opt<std::string> UserAssetPath(
85+
"asset",
86+
llvm::cl::desc("User supplied asset path to "
87+
"override the default css and js files for html output"),
88+
llvm::cl::cat(ClangDocCategory));
8989

9090
static llvm::cl::opt<std::string> SourceRoot("source-root", llvm::cl::desc(R"(
9191
Directory where processed files are stored.
@@ -144,7 +144,7 @@ llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
144144
!Code && DirIt != DirEnd; DirIt.increment(Code)) {
145145
llvm::SmallString<128> FilePath = llvm::SmallString<128>(DirIt->path());
146146
if (!Code) {
147-
return llvm::createFileError(FilePath, Code);
147+
return llvm::createFileError(FilePath, Code);
148148
}
149149
if (llvm::sys::fs::is_regular_file(FilePath)) {
150150
if (llvm::sys::path::extension(FilePath) == ".css") {
@@ -158,7 +158,7 @@ llvm::Error GetAssetFiles(clang::doc::ClangDocContext &CDCtx) {
158158
}
159159

160160
llvm::Error GetDefaultAssetFiles(const char *Argv0,
161-
clang::doc::ClangDocContext &CDCtx) {
161+
clang::doc::ClangDocContext &CDCtx) {
162162
void *MainAddr = (void *)(intptr_t)GetExecutablePath;
163163
std::string ClangDocPath = GetExecutablePath(Argv0, MainAddr);
164164
llvm::SmallString<128> NativeClangDocPath;
@@ -177,32 +177,37 @@ llvm::Error GetDefaultAssetFiles(const char *Argv0,
177177

178178
if (!llvm::sys::fs::is_regular_file(IndexJS)) {
179179
return llvm::createStringError(llvm::inconvertibleErrorCode(),
180-
"error default index.js file at " + IndexJS + "\n");
180+
"error default index.js file at " + IndexJS +
181+
"\n");
181182
}
182183

183184
if (!llvm::sys::fs::is_regular_file(DefaultStylesheet)) {
184-
return llvm::createStringError(llvm::inconvertibleErrorCode(),
185-
"error default clang-doc-default-stylesheet.css file at " + DefaultStylesheet + "\n");
185+
return llvm::createStringError(
186+
llvm::inconvertibleErrorCode(),
187+
"error default clang-doc-default-stylesheet.css file at " +
188+
DefaultStylesheet + "\n");
186189
}
187190

188191
CDCtx.UserStylesheets.insert(CDCtx.UserStylesheets.begin(),
189192
std::string(DefaultStylesheet));
190193
CDCtx.FilesToCopy.emplace_back(IndexJS.str());
191194

192-
llvm::outs() << "Using default asset: "
193-
<< AssetsPath << "\n";
195+
llvm::outs() << "Using default asset: " << AssetsPath << "\n";
194196

195197
return llvm::Error::success();
196198
}
197199

198-
llvm::Error GetHTMLAssetFiles(const char *Argv0, clang::doc::ClangDocContext &CDCtx) {
199-
if (!UserAssetPath.empty() && !llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
200-
llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath << " falling back to default\n";
201-
}
202-
if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
203-
return GetAssetFiles(CDCtx);
204-
}
205-
return GetDefaultAssetFiles(Argv0, CDCtx);
200+
llvm::Error GetHTMLAssetFiles(const char *Argv0,
201+
clang::doc::ClangDocContext &CDCtx) {
202+
if (!UserAssetPath.empty() &&
203+
!llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
204+
llvm::outs() << "Asset path supply is not a directory: " << UserAssetPath
205+
<< " falling back to default\n";
206+
}
207+
if (llvm::sys::fs::is_directory(std::string(UserAssetPath))) {
208+
return GetAssetFiles(CDCtx);
209+
}
210+
return GetDefaultAssetFiles(Argv0, CDCtx);
206211
}
207212

208213
int main(int argc, const char **argv) {
@@ -256,11 +261,11 @@ Example usage for a project using a compile commands database:
256261
{"index.js", "index_json.js"}};
257262

258263
if (Format == "html") {
259-
auto Err = GetHTMLAssetFiles(argv[0], CDCtx);
260-
if (Err) {
261-
llvm::errs() << toString(std::move(Err)) << "\n";
262-
return 1;
263-
}
264+
auto Err = GetHTMLAssetFiles(argv[0], CDCtx);
265+
if (Err) {
266+
llvm::errs() << toString(std::move(Err)) << "\n";
267+
return 1;
268+
}
264269
}
265270

266271
// Mapping phase
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: echo "" > %t/compile_flags.txt
4+
// RUN: cp "%s" "%t/test.cpp"
5+
// RUN: clang-doc --format=html --executor=standalone -p %t %t/test.cpp -output=%t/docs > %t/output.txt
6+
// RUN: cat %t/output.txt | FileCheck %s --check-prefix=CHECK
7+
8+
// CHECK: Emiting docs in html format.
9+
// CHECK-NEXT: Using default asset: {{.*}}..\share\clang
10+
// CHECK-NEXT: Mapping decls...
11+
// CHECK-NEXT: Collecting infos...
12+
// CHECK-NEXT: Reducing 0 infos...
13+
// CHECK-NEXT: Generating docs...
14+
// CHECK-NEXT: Generating assets for docs...

0 commit comments

Comments
 (0)