Skip to content

Commit

Permalink
Remove submodule doctest
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jul 9, 2018
1 parent eb8acf9 commit ed1b221
Show file tree
Hide file tree
Showing 11 changed files with 4 additions and 301 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "third_party/rapidjson"]
path = third_party/rapidjson
url = https://github.com/miloyip/rapidjson
[submodule "third_party/doctest"]
path = third_party/doctest
url = https://github.com/onqtam/doctest
5 changes: 1 addition & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ target_compile_definitions(ccls PRIVATE
target_include_directories(ccls PRIVATE
src
third_party
third_party/rapidjson/include
third_party/loguru
third_party/doctest)
third_party/rapidjson/include)

### Install

Expand Down Expand Up @@ -214,7 +212,6 @@ target_sources(ccls PRIVATE
src/query.cc
src/serializer.cc
src/test.cc
src/third_party_impl.cc
src/utils.cc
src/working_files.cc)

Expand Down
4 changes: 2 additions & 2 deletions src/fuzzy_match.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "fuzzy_match.h"

#include <doctest/doctest.h>

#include <ctype.h>
#include <stdio.h>
#include <algorithm>
Expand Down Expand Up @@ -133,6 +131,7 @@ int FuzzyMatcher::Match(std::string_view text) {
return ret;
}

#if 0
TEST_SUITE("fuzzy_match") {
bool Ranks(std::string_view pat, std::vector<const char*> texts) {
FuzzyMatcher fuzzy(pat, 0);
Expand Down Expand Up @@ -180,3 +179,4 @@ TEST_SUITE("fuzzy_match") {
CHECK(Ranks("Int", {"int", "INT", "PRINT"}));
}
}
#endif
20 changes: 1 addition & 19 deletions src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ using namespace ccls;
using namespace llvm;
using namespace llvm::cl;

#include <doctest/doctest.h>
#include <rapidjson/error/en.h>

#include <stdio.h>
Expand All @@ -29,7 +28,6 @@ namespace {
opt<bool> opt_help("h", desc("Alias for -help"));
opt<int> opt_verbose("v", desc("verbosity"), init(0));
opt<std::string> opt_test_index("test-index", ValueOptional, init("!"), desc("run index tests"));
opt<bool> opt_test_unit("test-unit", desc("run unit tests"));

opt<std::string> opt_init("init", desc("extra initialization options"));
opt<std::string> opt_log_file("log-file", desc("log"), value_desc("filename"));
Expand All @@ -53,9 +51,7 @@ int main(int argc, char** argv) {

if (opt_help) {
PrintHelpMessage();
// Also emit doctest help if --test-unit is passed.
if (!opt_test_unit)
return 0;
return 0;
}

pipeline::Init();
Expand All @@ -77,20 +73,6 @@ int main(int argc, char** argv) {
atexit(CloseLog);
}

if (opt_test_unit) {
language_server = false;
doctest::Context context;
std::vector<const char*> args{argv[0]};
if (opt_help)
args.push_back("-h");
for (auto& arg : opt_extra)
args.push_back(arg.c_str());
context.applyCommandLine(args.size(), args.data());
int res = context.run();
if (res != 0 || context.shouldExit())
return res;
}

if (opt_test_index != "!") {
language_server = false;
if (!RunIndexTests(opt_test_index, sys::Process::StandardInIsUserInput()))
Expand Down
14 changes: 0 additions & 14 deletions src/match.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "pipeline.hh"
using namespace ccls;

#include <doctest/doctest.h>

// static
std::optional<Matcher> Matcher::Create(const std::string& search) {
/*
Expand Down Expand Up @@ -75,15 +73,3 @@ bool GroupMatch::IsMatch(const std::string& value,

return true;
}

TEST_SUITE("Matcher") {
TEST_CASE("sanity") {
// Matcher m("abc");
// TODO: check case
// CHECK(m.IsMatch("abc"));
// CHECK(m.IsMatch("fooabc"));
// CHECK(m.IsMatch("abc"));
// CHECK(m.IsMatch("abcfoo"));
// CHECK(m.IsMatch("11a11b11c11"));
}
}
251 changes: 0 additions & 251 deletions src/project.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ using namespace llvm;
using namespace llvm::opt;

#include <clang-c/CXCompilationDatabase.h>
#include <doctest/doctest.h>
#include <rapidjson/writer.h>

#if defined(__unix__) || defined(__APPLE__)
Expand Down Expand Up @@ -493,253 +492,3 @@ void Project::Index(WorkingFiles* wfiles,
// trigger refreshing semantic highlight for all working files.
pipeline::Index("", {}, false);
}

TEST_SUITE("Project") {
void CheckFlags(const std::string& directory, const std::string& file,
std::vector<std::string> raw,
std::vector<std::string> expected) {
if (g_config)
delete g_config;
g_config = new Config;
g_config->clang.resourceDir = "/w/resource_dir/";
ProjectConfig project;
project.project_dir = "/w/c/s/";

CompileCommandsEntry entry;
entry.directory = directory;
entry.args = raw;
entry.file = file;
Project::Entry result =
GetCompilationEntryFromCompileCommandEntry(&project, entry);

if (result.args != expected) {
fprintf(stderr, "Raw: %s\n", StringJoin(raw).c_str());
fprintf(stderr, "Expected: %s\n", StringJoin(expected).c_str());
fprintf(stderr, "Actual: %s\n", StringJoin(result.args).c_str());
}
REQUIRE(result.args == expected);
}

void CheckFlags(std::vector<std::string> raw,
std::vector<std::string> expected) {
CheckFlags("/dir/", "file.cc", raw, expected);
}

TEST_CASE("strip meta-compiler invocations") {
CheckFlags(
/* raw */ {"clang", "-lstdc++", "myfile.cc"},
/* expected */
{"clang", "-lstdc++", "/dir/myfile.cc",
"-resource-dir=/w/resource_dir/", "-working-directory=/dir/",
"-Wno-unknown-warning-option", "-fparse-all-comments"});

CheckFlags(
/* raw */ {"clang.exe"},
/* expected */
{"clang.exe", "-resource-dir=/w/resource_dir/",
"-working-directory=/dir/", "-Wno-unknown-warning-option",
"-fparse-all-comments"});
}

#ifdef _WIN32
TEST_CASE("Windows path normalization") {
CheckFlags("E:/workdir", "E:/workdir/bar.cc", /* raw */ {"clang", "bar.cc"},
/* expected */
{"clang", "-working-directory=E:/workdir", "E:/workdir/bar.cc",
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option",
"-fparse-all-comments"});

CheckFlags("E:/workdir", "E:/workdir/bar.cc",
/* raw */ {"clang", "E:/workdir/bar.cc"},
/* expected */
{"clang", "-working-directory=E:/workdir", "E:/workdir/bar.cc",
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option",
"-fparse-all-comments"});

CheckFlags("E:/workdir", "E:/workdir/bar.cc",
/* raw */ {"clang-cl.exe", "/I./test", "E:/workdir/bar.cc"},
/* expected */
{"clang-cl.exe", "-working-directory=E:/workdir",
"/I&E:/workdir/./test", "E:/workdir/bar.cc",
"-resource-dir=/w/resource_dir/", "-Wno-unknown-warning-option",
"-fparse-all-comments"});

CheckFlags("E:/workdir", "E:/workdir/bar.cc",
/* raw */
{"cl.exe", "/I../third_party/test/include", "E:/workdir/bar.cc"},
/* expected */
{"cl.exe", "-working-directory=E:/workdir",
"/I&E:/workdir/../third_party/test/include",
"E:/workdir/bar.cc", "-resource-dir=/w/resource_dir/",
"-Wno-unknown-warning-option", "-fparse-all-comments"});
}
#endif

TEST_CASE("Path in args") {
CheckFlags(
"/home/user", "/home/user/foo/bar.c",
/* raw */ {"cc", "-O0", "foo/bar.c"},
/* expected */
{"cc", "-O0", "/home/user/foo/bar.c", "-resource-dir=/w/resource_dir/",
"-working-directory=/home/user", "-Wno-unknown-warning-option",
"-fparse-all-comments"});
}

TEST_CASE("Directory extraction") {
if (g_config)
delete g_config;
g_config = new Config;
ProjectConfig config;
config.project_dir = "/w/c/s/";

CompileCommandsEntry entry;
entry.directory = "/base";
entry.args = {"clang",
"-I/a_absolute1",
"--foobar",
"-I",
"/a_absolute2",
"--foobar",
"-Ia_relative1",
"--foobar",
"-isystem",
"a_relative2",
"--foobar",
"-iquote/q_absolute1",
"--foobar",
"-iquote",
"/q_absolute2",
"--foobar",
"-iquoteq_relative1",
"--foobar",
"-iquote",
"q_relative2",
"--foobar",
"foo.cc"};
entry.file = "foo.cc";
Project::Entry result =
GetCompilationEntryFromCompileCommandEntry(&config, entry);

std::unordered_set<std::string> angle_expected{
"/a_absolute1", "/a_absolute2", "/base/a_relative1",
"/base/a_relative2"};
std::unordered_set<std::string> quote_expected{
"/a_absolute1", "/a_absolute2", "/base/a_relative1",
"/q_absolute1", "/q_absolute2", "/base/q_relative1",
"/base/q_relative2"};
REQUIRE(config.angle_dirs == angle_expected);
REQUIRE(config.quote_dirs == quote_expected);
}

TEST_CASE("Entry inference") {
Project p;
{
Project::Entry e;
e.args = {"arg1"};
e.filename = "/a/b/c/d/bar.cc";
p.entries.push_back(e);
}
{
Project::Entry e;
e.args = {"arg2"};
e.filename = "/a/b/c/baz.cc";
p.entries.push_back(e);
}

// Guess at same directory level, when there are parent directories.
{
std::optional<Project::Entry> entry =
p.FindCompilationEntryForFile("/a/b/c/d/new.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg1"});
}

// Guess at same directory level, when there are child directories.
{
std::optional<Project::Entry> entry =
p.FindCompilationEntryForFile("/a/b/c/new.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}

// Guess at new directory (use the closest parent directory).
{
std::optional<Project::Entry> entry =
p.FindCompilationEntryForFile("/a/b/c/new/new.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}
}

TEST_CASE("Entry inference remaps file names") {
Project p;
{
Project::Entry e;
e.args = {"a", "b", "aaaa.cc", "d"};
e.filename = "absolute/aaaa.cc";
p.entries.push_back(e);
}

{
std::optional<Project::Entry> entry = p.FindCompilationEntryForFile("ee.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"a", "b", "ee.cc", "d"});
}
}

TEST_CASE("Entry inference prefers same file endings") {
Project p;
{
Project::Entry e;
e.args = {"arg1"};
e.filename = "common/simple_browsertest.cc";
p.entries.push_back(e);
}
{
Project::Entry e;
e.args = {"arg2"};
e.filename = "common/simple_unittest.cc";
p.entries.push_back(e);
}
{
Project::Entry e;
e.args = {"arg3"};
e.filename = "common/a/simple_unittest.cc";
p.entries.push_back(e);
}

// Prefer files with the same ending.
{
std::optional<Project::Entry> entry =
p.FindCompilationEntryForFile("my_browsertest.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg1"});
}
{
std::optional<Project::Entry> entry =
p.FindCompilationEntryForFile("my_unittest.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}
{
std::optional<Project::Entry> entry =
p.FindCompilationEntryForFile("common/my_browsertest.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg1"});
}
{
std::optional<Project::Entry> entry =
p.FindCompilationEntryForFile("common/my_unittest.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg2"});
}

// Prefer the same directory over matching file-ending.
{
std::optional<Project::Entry> entry =
p.FindCompilationEntryForFile("common/a/foo.cc");
REQUIRE(entry.has_value());
REQUIRE(entry->args == std::vector<std::string>{"arg3"});
}
}
}
2 changes: 0 additions & 2 deletions src/query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "serializer.h"
#include "serializers/json.h"

#include <doctest/doctest.h>

#include <cassert>
#include <cstdint>
#include <functional>
Expand Down
1 change: 0 additions & 1 deletion src/test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include "serializer.h"
#include "utils.h"

#include <doctest/doctest.h>
#include <rapidjson/document.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
Expand Down
Loading

0 comments on commit ed1b221

Please sign in to comment.