mirror of
https://github.com/MaskRay/ccls.git
synced 2025-01-19 12:05:50 +00:00
Test improvements:
- Update files with \r\n newlines. - Require clang 4.0.0 for running tests.
This commit is contained in:
parent
6538274e66
commit
4aeb6acf04
@ -1868,3 +1868,7 @@ void ClangSanityCheck() {
|
|||||||
clang_disposeTranslationUnit(tu);
|
clang_disposeTranslationUnit(tu);
|
||||||
clang_disposeIndex(index);
|
clang_disposeIndex(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string GetClangVersion() {
|
||||||
|
return ToString(clang_getClangVersion());
|
||||||
|
}
|
@ -559,3 +559,5 @@ std::vector<std::unique_ptr<IndexFile>> ParseWithTu(
|
|||||||
void IndexInit();
|
void IndexInit();
|
||||||
|
|
||||||
void ClangSanityCheck();
|
void ClangSanityCheck();
|
||||||
|
|
||||||
|
std::string GetClangVersion();
|
19
src/test.cc
19
src/test.cc
@ -19,7 +19,8 @@ std::string ToString(const rapidjson::Document& document) {
|
|||||||
|
|
||||||
buffer.Clear();
|
buffer.Clear();
|
||||||
document.Accept(writer);
|
document.Accept(writer);
|
||||||
return buffer.GetString();
|
std::string output = buffer.GetString();
|
||||||
|
return UpdateToRnNewlines(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffDocuments(std::string path,
|
void DiffDocuments(std::string path,
|
||||||
@ -110,7 +111,16 @@ IndexFile* FindDbForPathEnding(
|
|||||||
void RunIndexTests(const std::string& filter_path) {
|
void RunIndexTests(const std::string& filter_path) {
|
||||||
SetTestOutputMode();
|
SetTestOutputMode();
|
||||||
|
|
||||||
// TODO: Assert that we need to be on clang >= 3.9.1
|
// Index tests change based on the version of clang used.
|
||||||
|
static constexpr const char* kRequiredClangVersion =
|
||||||
|
"clang version 4.0.0 (tags/RELEASE_400/final)";
|
||||||
|
if (GetClangVersion() != kRequiredClangVersion) {
|
||||||
|
std::cerr << "Index tests must be run using clang version \""
|
||||||
|
<< kRequiredClangVersion << "\" (cquery is running with \""
|
||||||
|
<< GetClangVersion() << "\")" << std::endl;
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
bool update_all = false;
|
bool update_all = false;
|
||||||
ClangIndex index;
|
ClangIndex index;
|
||||||
|
|
||||||
@ -230,8 +240,9 @@ void RunIndexTests(const std::string& filter_path) {
|
|||||||
update_all = true;
|
update_all = true;
|
||||||
|
|
||||||
if (update_all || c == 'u') {
|
if (update_all || c == 'u') {
|
||||||
UpdateTestExpectation(path, expected_output,
|
// Note: we use |entry.second| instead of |expected_output| because
|
||||||
ToString(actual) + "\n");
|
// |expected_output| has had text replacements applied.
|
||||||
|
UpdateTestExpectation(path, entry.second, ToString(actual) + "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
src/utils.cc
34
src/utils.cc
@ -502,6 +502,28 @@ std::string GetDefaultResourceDirectory() {
|
|||||||
return NormalizePath(result);
|
return NormalizePath(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string UpdateToRnNewlines(std::string output) {
|
||||||
|
size_t idx = 0;
|
||||||
|
while (true) {
|
||||||
|
idx = output.find('\n', idx);
|
||||||
|
|
||||||
|
// No more matches.
|
||||||
|
if (idx == std::string::npos)
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Skip an existing "\r\n" match.
|
||||||
|
if (idx > 0 && output[idx - 1] == '\r') {
|
||||||
|
++idx;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace "\n" with "\r|n".
|
||||||
|
output.replace(output.begin() + idx, output.begin() + idx + 1, "\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
};
|
||||||
|
|
||||||
TEST_SUITE("ParseTestExpectation") {
|
TEST_SUITE("ParseTestExpectation") {
|
||||||
TEST_CASE("Parse TEXT_REPLACE") {
|
TEST_CASE("Parse TEXT_REPLACE") {
|
||||||
// clang-format off
|
// clang-format off
|
||||||
@ -552,3 +574,15 @@ TEST_SUITE("ParseTestExpectation") {
|
|||||||
REQUIRE(replacer.Apply("foofoobar0123") == "barbarbar22456");
|
REQUIRE(replacer.Apply("foofoobar0123") == "barbarbar22456");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_SUITE("Update \\n to \\r\\n") {
|
||||||
|
TEST_CASE("all") {
|
||||||
|
REQUIRE(UpdateToRnNewlines("\n") == "\r\n");
|
||||||
|
REQUIRE(UpdateToRnNewlines("\n\n") == "\r\n\r\n");
|
||||||
|
REQUIRE(UpdateToRnNewlines("\r\n\n") == "\r\n\r\n");
|
||||||
|
REQUIRE(UpdateToRnNewlines("\n\r\n") == "\r\n\r\n");
|
||||||
|
REQUIRE(UpdateToRnNewlines("\r\n\r\n") == "\r\n\r\n");
|
||||||
|
REQUIRE(UpdateToRnNewlines("f1\nfo2\nfoo3") == "f1\r\nfo2\r\nfoo3");
|
||||||
|
REQUIRE(UpdateToRnNewlines("f1\r\nfo2\r\nfoo3") == "f1\r\nfo2\r\nfoo3");
|
||||||
|
}
|
||||||
|
}
|
@ -181,3 +181,6 @@ float GetProcessMemoryUsedInMb();
|
|||||||
std::string FormatMicroseconds(long long microseconds);
|
std::string FormatMicroseconds(long long microseconds);
|
||||||
|
|
||||||
std::string GetDefaultResourceDirectory();
|
std::string GetDefaultResourceDirectory();
|
||||||
|
|
||||||
|
// Makes sure all newlines in |output| are in \r\n format.
|
||||||
|
std::string UpdateToRnNewlines(std::string output);
|
||||||
|
Loading…
Reference in New Issue
Block a user