Use indented TEST_SUITE

This commit is contained in:
Fangrui Song 2017-11-19 10:05:06 -08:00 committed by Jacob Dufault
parent 424c7b69db
commit 297ed1d13e
12 changed files with 1344 additions and 1366 deletions

View File

@ -3257,9 +3257,8 @@ int main(int argc, char** argv) {
}
}
TEST_SUITE("LexFunctionDeclaration");
TEST_CASE("simple") {
TEST_SUITE("LexFunctionDeclaration") {
TEST_CASE("simple") {
std::string buffer_content = " void Foo(); ";
lsPosition declaration = CharPos(buffer_content, 'F');
std::string insert_text;
@ -3274,9 +3273,9 @@ TEST_CASE("simple") {
&insert_text, &newlines_after_name);
REQUIRE(insert_text == "void Type::Foo() {\n}");
REQUIRE(newlines_after_name == 0);
}
}
TEST_CASE("ctor") {
TEST_CASE("ctor") {
std::string buffer_content = " Foo(); ";
lsPosition declaration = CharPos(buffer_content, 'F');
std::string insert_text;
@ -3286,9 +3285,9 @@ TEST_CASE("ctor") {
&insert_text, &newlines_after_name);
REQUIRE(insert_text == "Foo::Foo() {\n}");
REQUIRE(newlines_after_name == 0);
}
}
TEST_CASE("dtor") {
TEST_CASE("dtor") {
std::string buffer_content = " ~Foo(); ";
lsPosition declaration = CharPos(buffer_content, '~');
std::string insert_text;
@ -3298,9 +3297,9 @@ TEST_CASE("dtor") {
&insert_text, &newlines_after_name);
REQUIRE(insert_text == "Foo::~Foo() {\n}");
REQUIRE(newlines_after_name == 0);
}
}
TEST_CASE("complex return type") {
TEST_CASE("complex return type") {
std::string buffer_content = " std::vector<int> Foo(); ";
lsPosition declaration = CharPos(buffer_content, 'F');
std::string insert_text;
@ -3315,9 +3314,9 @@ TEST_CASE("complex return type") {
&insert_text, &newlines_after_name);
REQUIRE(insert_text == "std::vector<int> Type::Foo() {\n}");
REQUIRE(newlines_after_name == 0);
}
}
TEST_CASE("extra complex return type") {
TEST_CASE("extra complex return type") {
std::string buffer_content = " std::function < int() > \n Foo(); ";
lsPosition declaration = CharPos(buffer_content, 'F');
std::string insert_text;
@ -3332,9 +3331,9 @@ TEST_CASE("extra complex return type") {
&insert_text, &newlines_after_name);
REQUIRE(insert_text == "std::function < int() > \n Type::Foo() {\n}");
REQUIRE(newlines_after_name == 0);
}
}
TEST_CASE("parameters") {
TEST_CASE("parameters") {
std::string buffer_content = "void Foo(int a,\n\n int b); ";
lsPosition declaration = CharPos(buffer_content, 'F');
std::string insert_text;
@ -3349,77 +3348,73 @@ TEST_CASE("parameters") {
&insert_text, &newlines_after_name);
REQUIRE(insert_text == "void Type::Foo(int a,\n\n int b) {\n}");
REQUIRE(newlines_after_name == 2);
}
}
TEST_SUITE_END();
TEST_SUITE("LexWordAroundPos");
TEST_CASE("edges") {
TEST_SUITE("LexWordAroundPos") {
TEST_CASE("edges") {
std::string content = "Foobar";
REQUIRE(LexWordAroundPos(CharPos(content, 'F'), content) == "Foobar");
REQUIRE(LexWordAroundPos(CharPos(content, 'o'), content) == "Foobar");
REQUIRE(LexWordAroundPos(CharPos(content, 'b'), content) == "Foobar");
REQUIRE(LexWordAroundPos(CharPos(content, 'a'), content) == "Foobar");
REQUIRE(LexWordAroundPos(CharPos(content, 'r'), content) == "Foobar");
}
}
TEST_CASE("simple") {
TEST_CASE("simple") {
std::string content = " Foobar ";
REQUIRE(LexWordAroundPos(CharPos(content, 'F'), content) == "Foobar");
REQUIRE(LexWordAroundPos(CharPos(content, 'o'), content) == "Foobar");
REQUIRE(LexWordAroundPos(CharPos(content, 'b'), content) == "Foobar");
REQUIRE(LexWordAroundPos(CharPos(content, 'a'), content) == "Foobar");
REQUIRE(LexWordAroundPos(CharPos(content, 'r'), content) == "Foobar");
}
}
TEST_CASE("underscores and numbers") {
TEST_CASE("underscores and numbers") {
std::string content = " _my_t5ype7 ";
REQUIRE(LexWordAroundPos(CharPos(content, '_'), content) == "_my_t5ype7");
REQUIRE(LexWordAroundPos(CharPos(content, '5'), content) == "_my_t5ype7");
REQUIRE(LexWordAroundPos(CharPos(content, 'e'), content) == "_my_t5ype7");
REQUIRE(LexWordAroundPos(CharPos(content, '7'), content) == "_my_t5ype7");
}
}
TEST_CASE("dot, dash, colon are skipped") {
TEST_CASE("dot, dash, colon are skipped") {
std::string content = "1. 2- 3:";
REQUIRE(LexWordAroundPos(CharPos(content, '1'), content) == "1");
REQUIRE(LexWordAroundPos(CharPos(content, '2'), content) == "2");
REQUIRE(LexWordAroundPos(CharPos(content, '3'), content) == "3");
}
}
TEST_SUITE_END();
TEST_SUITE("FindIncludeLine");
TEST_CASE("in document") {
TEST_SUITE("FindIncludeLine") {
TEST_CASE("in document") {
std::vector<std::string> lines = {
"#include <bbb>", // 0
"#include <ddd>" // 1
};
REQUIRE(FindIncludeLine(lines, "#include <bbb>") == nullopt);
}
}
TEST_CASE("insert before") {
TEST_CASE("insert before") {
std::vector<std::string> lines = {
"#include <bbb>", // 0
"#include <ddd>" // 1
};
REQUIRE(FindIncludeLine(lines, "#include <aaa>") == 0);
}
}
TEST_CASE("insert middle") {
TEST_CASE("insert middle") {
std::vector<std::string> lines = {
"#include <bbb>", // 0
"#include <ddd>" // 1
};
REQUIRE(FindIncludeLine(lines, "#include <ccc>") == 1);
}
}
TEST_CASE("insert after") {
TEST_CASE("insert after") {
std::vector<std::string> lines = {
"#include <bbb>", // 0
"#include <ddd>", // 1
@ -3427,9 +3422,9 @@ TEST_CASE("insert after") {
};
REQUIRE(FindIncludeLine(lines, "#include <eee>") == 2);
}
}
TEST_CASE("ignore header") {
TEST_CASE("ignore header") {
std::vector<std::string> lines = {
"// FOOBAR", // 0
"// FOOBAR", // 1
@ -3444,6 +3439,5 @@ TEST_CASE("ignore header") {
REQUIRE(FindIncludeLine(lines, "#include <a>") == 5);
REQUIRE(FindIncludeLine(lines, "#include <c>") == 6);
REQUIRE(FindIncludeLine(lines, "#include <e>") == 7);
}
}
TEST_SUITE_END();

View File

@ -82,8 +82,6 @@ optional<std::string> ReadJsonRpcContentFrom(
return content;
}
TEST_SUITE("FindIncludeLine");
std::function<optional<char>()> MakeContentReader(std::string* content,
bool can_be_empty) {
return [content, can_be_empty]() -> optional<char> {
@ -97,7 +95,8 @@ std::function<optional<char>()> MakeContentReader(std::string* content,
};
}
TEST_CASE("ReadContentFromSource") {
TEST_SUITE("FindIncludeLine") {
TEST_CASE("ReadContentFromSource") {
auto parse_correct = [](std::string content) -> std::string {
auto reader = MakeContentReader(&content, false /*can_be_empty*/);
auto got = ReadJsonRpcContentFrom(reader);
@ -118,10 +117,9 @@ TEST_CASE("ReadContentFromSource") {
REQUIRE(parse_incorrect("Content-Length: 0\r\n") == optional<std::string>());
REQUIRE(parse_incorrect("Content-Length: 5\r\n\r\nab") ==
optional<std::string>());
}
}
TEST_SUITE_END();
optional<char> ReadCharFromStdinBlocking() {
// Bad stdin means parent process has probably exited. Either way, cquery
// can no longer be communicated with so just exit.

View File

@ -213,32 +213,29 @@ bool SubstringMatch(const std::string& search, const std::string& content) {
return false;
}
TEST_SUITE("Offset");
TEST_CASE("past end") {
TEST_SUITE("Offset") {
TEST_CASE("past end") {
std::string content = "foo";
int offset = GetOffsetForPosition(lsPosition(10, 10), content);
REQUIRE(offset <= content.size());
}
}
TEST_CASE("in middle of content") {
TEST_CASE("in middle of content") {
std::string content = "abcdefghijk";
for (int i = 0; i < content.size(); ++i) {
int offset = GetOffsetForPosition(lsPosition(0, i), content);
REQUIRE(i == offset);
}
}
}
TEST_CASE("at end of content") {
TEST_CASE("at end of content") {
REQUIRE(GetOffsetForPosition(lsPosition(0, 0), "") == 0);
REQUIRE(GetOffsetForPosition(lsPosition(0, 1), "a") == 1);
}
}
TEST_SUITE_END();
TEST_SUITE("Substring");
TEST_CASE("match") {
TEST_SUITE("Substring") {
TEST_CASE("match") {
// Sanity.
REQUIRE(SubstringMatch("a", "aa"));
REQUIRE(SubstringMatch("aa", "aa"));
@ -266,6 +263,5 @@ TEST_CASE("match") {
// Ordering.
REQUIRE(!SubstringMatch("ad", "dcba"));
}
}
TEST_SUITE_END();

View File

@ -76,9 +76,8 @@ bool GroupMatch::IsMatch(const std::string& value,
return true;
}
TEST_SUITE("Matcher");
TEST_CASE("sanity") {
TEST_SUITE("Matcher") {
TEST_CASE("sanity") {
// Matcher m("abc");
// TODO: check case
// CHECK(m.IsMatch("abc"));
@ -86,6 +85,5 @@ TEST_CASE("sanity") {
// CHECK(m.IsMatch("abc"));
// CHECK(m.IsMatch("abcfoo"));
// CHECK(m.IsMatch("11a11b11c11"));
}
}
TEST_SUITE_END();

View File

@ -87,15 +87,14 @@ void MakeDirectoryRecursive(std::string path) {
}
}
TEST_SUITE("Platform");
TEST_CASE("Split strings") {
TEST_SUITE("Platform") {
TEST_CASE("Split strings") {
std::vector<std::string> actual = Split("/a/b/c/", '/');
std::vector<std::string> expected{"a", "b", "c"};
REQUIRE(actual == expected);
}
}
TEST_CASE("Mutex lock/unlock (single process)") {
TEST_CASE("Mutex lock/unlock (single process)") {
auto m1 = CreatePlatformMutex("indexer-platformmutexttest");
auto l1 = CreatePlatformScopedMutexLock(m1.get());
auto m2 = CreatePlatformMutex("indexer-platformmutexttest");
@ -121,6 +120,5 @@ TEST_CASE("Mutex lock/unlock (single process)") {
l1.reset();
t.join();
REQUIRE(value == 1);
}
}
TEST_SUITE_END();

View File

@ -411,9 +411,8 @@ void Project::ForAllFilteredFiles(
}
}
TEST_SUITE("Project");
void CheckFlags(const std::string& directory,
TEST_SUITE("Project") {
void CheckFlags(const std::string& directory,
const std::string& file,
std::vector<std::string> raw,
std::vector<std::string> expected) {
@ -443,14 +442,14 @@ void CheckFlags(const std::string& directory,
}
}
REQUIRE(result.args == expected);
}
}
void CheckFlags(std::vector<std::string> raw,
void CheckFlags(std::vector<std::string> raw,
std::vector<std::string> expected) {
CheckFlags("/dir/", "file.cc", raw, expected);
}
}
TEST_CASE("strip meta-compiler invocations") {
TEST_CASE("strip meta-compiler invocations") {
CheckFlags(
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
/* expected */ {"clang", "-lstdc++", "myfile.cc", "-xc++", "-std=c++11",
@ -463,11 +462,11 @@ TEST_CASE("strip meta-compiler invocations") {
CheckFlags(/* raw */ {"goma", "clang", "--foo"},
/* expected */ {"clang", "--foo", "-xc++", "-std=c++11",
"-resource-dir=/w/resource_dir/"});
}
}
// Checks flag parsing for a random chromium file in comparison to what
// YouCompleteMe fetches.
TEST_CASE("ycm") {
// Checks flag parsing for a random chromium file in comparison to what
// YouCompleteMe fetches.
TEST_CASE("ycm") {
CheckFlags(
"/w/c/s/out/Release", "../../ash/login/lock_screen_sanity_unittest.cc",
@ -807,10 +806,10 @@ TEST_CASE("ycm") {
"-fvisibility-inlines-hidden",
"-xc++",
"-resource-dir=/w/resource_dir/"});
}
}
// Checks flag parsing for an example chromium file.
TEST_CASE("chromium") {
// Checks flag parsing for an example chromium file.
TEST_CASE("chromium") {
CheckFlags(
"/w/c/s/out/Release", "../../apps/app_lifetime_monitor.cc",
/* raw */
@ -1125,9 +1124,9 @@ TEST_CASE("chromium") {
"-fvisibility-inlines-hidden",
"-xc++",
"-resource-dir=/w/resource_dir/"});
}
}
TEST_CASE("Directory extraction") {
TEST_CASE("Directory extraction") {
ProjectConfig config;
config.project_dir = "/w/c/s/";
@ -1167,9 +1166,9 @@ TEST_CASE("Directory extraction") {
"&/base/q_relative2"};
REQUIRE(config.angle_dirs == angle_expected);
REQUIRE(config.quote_dirs == quote_expected);
}
}
TEST_CASE("Entry inference") {
TEST_CASE("Entry inference") {
Project p;
{
Project::Entry e;
@ -1207,9 +1206,9 @@ TEST_CASE("Entry inference") {
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}
}
}
TEST_CASE("Entry inference prefers same file endings") {
TEST_CASE("Entry inference prefers same file endings") {
Project p;
{
Project::Entry e;
@ -1263,6 +1262,5 @@ TEST_CASE("Entry inference prefers same file endings") {
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg3"});
}
}
}
TEST_SUITE_END();

View File

@ -823,17 +823,16 @@ void QueryDatabase::UpdateDetailedNames(size_t* qualified_name_index,
}
}
TEST_SUITE("query");
IndexUpdate GetDelta(IndexFile previous, IndexFile current) {
TEST_SUITE("query") {
IndexUpdate GetDelta(IndexFile previous, IndexFile current) {
QueryDatabase db;
IdMap previous_map(&db, previous.id_cache);
IdMap current_map(&db, current.id_cache);
return IndexUpdate::CreateDelta(&previous_map, &current_map, &previous,
&current);
}
}
TEST_CASE("remove defs") {
TEST_CASE("remove defs") {
IndexFile previous("foo.cc");
IndexFile current("foo.cc");
@ -849,9 +848,9 @@ TEST_CASE("remove defs") {
REQUIRE(update.types_removed == std::vector<Usr>{"usr1"});
REQUIRE(update.funcs_removed == std::vector<Usr>{"usr2"});
REQUIRE(update.vars_removed == std::vector<Usr>{"usr3"});
}
}
TEST_CASE("do not remove ref-only defs") {
TEST_CASE("do not remove ref-only defs") {
IndexFile previous("foo.cc");
IndexFile current("foo.cc");
@ -868,9 +867,9 @@ TEST_CASE("do not remove ref-only defs") {
REQUIRE(update.types_removed == std::vector<Usr>{});
REQUIRE(update.funcs_removed == std::vector<Usr>{});
REQUIRE(update.vars_removed == std::vector<Usr>{});
}
}
TEST_CASE("func callers") {
TEST_CASE("func callers") {
IndexFile previous("foo.cc");
IndexFile current("foo.cc");
@ -892,9 +891,9 @@ TEST_CASE("func callers") {
Range(Position(1, 0)));
REQUIRE(update.funcs_callers[0].to_add.size() == 1);
REQUIRE(update.funcs_callers[0].to_add[0].loc.range == Range(Position(2, 0)));
}
}
TEST_CASE("type usages") {
TEST_CASE("type usages") {
IndexFile previous("foo.cc");
IndexFile current("foo.cc");
@ -913,9 +912,9 @@ TEST_CASE("type usages") {
REQUIRE(update.types_uses[0].to_remove[0].range == Range(Position(1, 0)));
REQUIRE(update.types_uses[0].to_add.size() == 1);
REQUIRE(update.types_uses[0].to_add[0].range == Range(Position(2, 0)));
}
}
TEST_CASE("apply delta") {
TEST_CASE("apply delta") {
IndexFile previous("foo.cc");
IndexFile current("foo.cc");
@ -949,6 +948,5 @@ TEST_CASE("apply delta") {
REQUIRE(db.funcs[0].callers.size() == 2);
REQUIRE(db.funcs[0].callers[0].loc.range == Range(Position(4, 0)));
REQUIRE(db.funcs[0].callers[1].loc.range == Range(Position(5, 0)));
}
}
TEST_SUITE_END();

View File

@ -379,15 +379,14 @@ std::vector<CXUnsavedFile> WorkingFiles::AsUnsavedFiles() {
return result;
}
TEST_SUITE("WorkingFile");
lsPosition CharPos(const WorkingFile& file,
char character,
int character_offset = 0) {
return CharPos(file.buffer_content, character, character_offset);
}
TEST_CASE("simple call") {
TEST_SUITE("WorkingFile") {
TEST_CASE("simple call") {
WorkingFile f("foo.cc", "abcd(1, 2");
int active_param = 0;
REQUIRE(f.FindClosestCallNameInBuffer(CharPos(f, '('), &active_param) ==
@ -405,9 +404,9 @@ TEST_CASE("simple call") {
REQUIRE(f.FindClosestCallNameInBuffer(CharPos(f, '2'), &active_param) ==
"abcd");
REQUIRE(active_param == 1);
}
}
TEST_CASE("nested call") {
TEST_CASE("nested call") {
WorkingFile f("foo.cc", "abcd(efg(), 2");
int active_param = 0;
REQUIRE(f.FindClosestCallNameInBuffer(CharPos(f, '('), &active_param) ==
@ -434,17 +433,17 @@ TEST_CASE("nested call") {
REQUIRE(f.FindClosestCallNameInBuffer(CharPos(f, ' '), &active_param) ==
"abcd");
REQUIRE(active_param == 1);
}
}
TEST_CASE("auto-insert )") {
TEST_CASE("auto-insert )") {
WorkingFile f("foo.cc", "abc()");
int active_param = 0;
REQUIRE(f.FindClosestCallNameInBuffer(CharPos(f, ')'), &active_param) ==
"abc");
REQUIRE(active_param == 0);
}
}
TEST_CASE("existing completion") {
TEST_CASE("existing completion") {
WorkingFile f("foo.cc", "zzz.asdf");
bool is_global_completion;
std::string existing_completion;
@ -464,9 +463,9 @@ TEST_CASE("existing completion") {
f.FindStableCompletionSource(CharPos(f, 'f', 1), &is_global_completion,
&existing_completion);
REQUIRE(existing_completion == "asdf");
}
}
TEST_CASE("existing completion underscore") {
TEST_CASE("existing completion underscore") {
WorkingFile f("foo.cc", "ABC_DEF");
bool is_global_completion;
std::string existing_completion;
@ -480,6 +479,5 @@ TEST_CASE("existing completion underscore") {
f.FindStableCompletionSource(CharPos(f, 'D'), &is_global_completion,
&existing_completion);
REQUIRE(existing_completion == "ABC_");
}
}
TEST_SUITE_END();

2
third_party/doctest vendored

@ -1 +1 @@
Subproject commit 11147357234d0166c9ec96c4d9e328464b884da3
Subproject commit 79a379827251cd819c5286070834ccd0ac628af9

2
third_party/loguru vendored

@ -1 +1 @@
Subproject commit ac23215b4b9e878dfe5c2fd3d4afbf7a63cdad12
Subproject commit 83b6f3c3d16e40453ec0d12d3baef42cd2f37c3b

@ -1 +1 @@
Subproject commit 0163a53f4a1c72e6a05848a63d80eee0d8e3f387
Subproject commit 17ae6ffa857173c25708e61610121bc908c0a6cd

@ -1 +1 @@
Subproject commit b1d54fbe547cab3a13d181f16f1de758d6827f81
Subproject commit bfb0de71ee7fa12a5f12c3ef61ce9f1d6d86d907