mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-29 19:07:08 +00:00
Additional improvements to automatic index test updates.
This commit is contained in:
parent
68f6d34693
commit
76c07f3cc6
@ -79,7 +79,6 @@ void VerifySerializeToFrom(IndexFile* file) {
|
|||||||
std::string actual = result->ToString();
|
std::string actual = result->ToString();
|
||||||
if (expected != actual) {
|
if (expected != actual) {
|
||||||
std::cerr << "Serialization failure" << std::endl;
|
std::cerr << "Serialization failure" << std::endl;
|
||||||
;
|
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
56
src/utils.cc
56
src/utils.cc
@ -209,26 +209,18 @@ std::istream& SafeGetline(std::istream& is, std::string& t) {
|
|||||||
std::streambuf* sb = is.rdbuf();
|
std::streambuf* sb = is.rdbuf();
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
bool had_r = false;
|
|
||||||
int c = sb->sbumpc();
|
int c = sb->sbumpc();
|
||||||
switch (c) {
|
if (c == EOF) {
|
||||||
case '\r':
|
// Also handle the case when the last line has no line ending
|
||||||
had_r = true;
|
if (t.empty())
|
||||||
break;
|
is.setstate(std::ios::eofbit);
|
||||||
case '\n':
|
return is;
|
||||||
return is;
|
|
||||||
case EOF:
|
|
||||||
// Also handle the case when the last line has no line ending
|
|
||||||
if (t.empty())
|
|
||||||
is.setstate(std::ios::eofbit);
|
|
||||||
return is;
|
|
||||||
default:
|
|
||||||
if (had_r) {
|
|
||||||
t += '\r';
|
|
||||||
had_r = false;
|
|
||||||
}
|
|
||||||
t += (char)c;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t += (char)c;
|
||||||
|
|
||||||
|
if (c == '\n')
|
||||||
|
return is;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,8 +240,15 @@ std::vector<std::string> ReadLines(std::string filename) {
|
|||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
|
|
||||||
std::ifstream input(filename);
|
std::ifstream input(filename);
|
||||||
for (std::string line; SafeGetline(input, line);)
|
for (std::string line; SafeGetline(input, line);) {
|
||||||
|
#if false
|
||||||
|
LOG_S(INFO) << "!! got line |" << line << "|";
|
||||||
|
for (char c : line)
|
||||||
|
std::cout << (int)c << ",";
|
||||||
|
std::cout << std::endl;
|
||||||
|
#endif
|
||||||
result.push_back(line);
|
result.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -295,24 +294,29 @@ std::unordered_map<std::string, std::string> ParseTestExpectation(
|
|||||||
std::string active_output_filename;
|
std::string active_output_filename;
|
||||||
std::string active_output_contents;
|
std::string active_output_contents;
|
||||||
|
|
||||||
for (std::string line : ReadLines(filename)) {
|
for (std::string line_with_ending : ReadLines(filename)) {
|
||||||
if (line == "*/")
|
if (StartsWith(line_with_ending, "*/"))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (StartsWith(line, "OUTPUT:")) {
|
if (StartsWith(line_with_ending, "OUTPUT:")) {
|
||||||
if (in_output) {
|
if (in_output) {
|
||||||
result[active_output_filename] = active_output_contents;
|
result[active_output_filename] = active_output_contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.size() > 7)
|
// Try to tokenize OUTPUT: based one whitespace. If there is more than one
|
||||||
active_output_filename = line.substr(8);
|
// token assume it is a filename.
|
||||||
else
|
std::vector<std::string> tokens = SplitString(line_with_ending, " ");
|
||||||
|
if (tokens.size() > 1) {
|
||||||
|
active_output_filename = tokens[1];
|
||||||
|
Trim(active_output_filename);
|
||||||
|
} else {
|
||||||
active_output_filename = filename;
|
active_output_filename = filename;
|
||||||
|
}
|
||||||
active_output_contents = "";
|
active_output_contents = "";
|
||||||
|
|
||||||
in_output = true;
|
in_output = true;
|
||||||
} else if (in_output)
|
} else if (in_output)
|
||||||
active_output_contents += line + "\r\n";
|
active_output_contents += line_with_ending;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (in_output)
|
if (in_output)
|
||||||
|
Loading…
Reference in New Issue
Block a user