Skip to content

Commit fa5c26a

Browse files
committed
refactor test actions
1 parent df0953f commit fa5c26a

File tree

6 files changed

+61
-167
lines changed

6 files changed

+61
-167
lines changed

include/mrdox/Corpus.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <mrdox/Config.hpp>
1717
#include <mrdox/Errors.hpp>
1818
#include <clang/Tooling/Execution.h>
19+
#include <llvm/Support/Mutex.h>
1920

2021
namespace clang {
2122
namespace mrdox {
@@ -24,10 +25,6 @@ namespace mrdox {
2425
*/
2526
struct Corpus
2627
{
27-
Corpus() = default;
28-
Corpus(Corpus&&) noexcept = default;
29-
Corpus& operator=(Corpus const&) = delete;
30-
3128
/** Index of all emitted symbols.
3229
*/
3330
Index Idx;
@@ -107,6 +104,13 @@ struct Corpus
107104
tooling::ToolExecutor& ex,
108105
Config const& cfg,
109106
Reporter& R);
107+
108+
private:
109+
Corpus() = default;
110+
111+
llvm::sys::Mutex infoMutex;
112+
llvm::sys::Mutex allResultsMutex;
113+
llvm::sys::Mutex indexMutexMutex;
110114
};
111115

112116
} // mrdox

include/mrdox/XML.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#define MRDOX_XML_HPP
1414

1515
#include <mrdox/Config.hpp>
16+
#include <mrdox/Corpus.hpp>
1617
#include <llvm/ADT/StringRef.h>
1718
#include <llvm/Support/Error.h>
1819
#include <string>

source/lib/Corpus.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ build(
132132
Config const& cfg,
133133
Reporter& R)
134134
{
135-
Corpus corpus;
135+
auto up = std::unique_ptr<Corpus>(new Corpus);
136+
Corpus& corpus = *up;
136137

137138
// Traverse the AST for all translation
138139
// units and emit serializd bitcode into
@@ -153,8 +154,8 @@ build(
153154
}
154155

155156
llvm::errs() <<
156-
"Error mapping decls in files. mrdox will ignore "
157-
"these files and continue:\n" <<
157+
"Error mapping decls in files. "
158+
"MrDox will ignore these files and continue:\n" <<
158159
toString(std::move(err)) << "\n";
159160
}
160161

@@ -265,7 +266,7 @@ build(
265266
});
266267
}
267268

268-
return std::make_unique<Corpus>(std::move(corpus));
269+
return std::move(up);
269270
}
270271

271272
} // mrdox

source/tests/TestAction.cpp

Lines changed: 0 additions & 67 deletions
This file was deleted.

source/tests/TestAction.hpp

Lines changed: 0 additions & 85 deletions
This file was deleted.

source/tests/TestMain.cpp

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
// Official repository: https://github.com/cppalliance/mrdox
99
//
1010

11-
#include "TestAction.hpp"
11+
#include <mrdox/XML.hpp>
1212
#include <mrdox/Errors.hpp>
1313
#include <clang/Tooling/AllTUsExecution.h>
1414
#include <clang/Tooling/CompilationDatabase.h>
15+
#include <clang/Tooling/StandaloneExecution.h>
1516
#include <llvm/ADT/SmallString.h>
1617
#include <llvm/ADT/Twine.h>
1718
#include <llvm/Support/Signals.h>
@@ -122,6 +123,48 @@ visitDirectory(
122123
return true;
123124
}
124125

126+
void
127+
testResult(
128+
Corpus const& corpus,
129+
Config const& cfg,
130+
llvm::StringRef file,
131+
llvm::StringRef out,
132+
Reporter& R)
133+
{
134+
std::string xml;
135+
renderToXMLString(xml, corpus, cfg);
136+
std::error_code ec;
137+
fs::file_status stat;
138+
ec = fs::status(out, stat, false);
139+
if(ec == std::errc::no_such_file_or_directory)
140+
{
141+
// create the xml file and write to it
142+
}
143+
else if(! R.failed("fs::status", ec))
144+
{
145+
if(stat.type() == fs::file_type::regular_file)
146+
{
147+
auto bufferResult = llvm::MemoryBuffer::getFile(out, true);
148+
if(R.failed("MemoryBuffer::getFile", bufferResult))
149+
return;
150+
if(xml != bufferResult->get()->getBuffer())
151+
{
152+
llvm::errs() <<
153+
"File: \"" << file << "\" failed.\n"
154+
"Expected:\n" <<
155+
bufferResult->get()->getBuffer() << "\n" <<
156+
"Got:\n" <<
157+
xml << "\n";
158+
R.testFailed();
159+
}
160+
}
161+
else
162+
{
163+
// VFALCO report that it is not a regular file
164+
}
165+
}
166+
}
167+
125168
//------------------------------------------------
126169

127170
int
@@ -147,12 +190,9 @@ testMain(int argc, const char** argv)
147190
SingleFile db(dir, file, out);
148191
tooling::StandaloneToolExecutor ex(
149192
db, { std::string(file) });
150-
Corpus corpus;
151-
llvm::Error err = ex.execute(
152-
std::make_unique<TestFactory>(ex, cfg, R));
153-
if(! err)
154-
{
155-
}
193+
auto corpus = Corpus::build(ex, cfg, R);
194+
if(corpus)
195+
testResult(*corpus, cfg, file, out, R);
156196
});
157197
});
158198
}

0 commit comments

Comments
 (0)