mirror of
https://github.com/MaskRay/ccls.git
synced 2024-11-21 23:25:07 +00:00
Remove submodule doctest
This commit is contained in:
parent
f9befbd5fb
commit
32dad17e81
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,6 +1,3 @@
|
|||||||
[submodule "third_party/rapidjson"]
|
[submodule "third_party/rapidjson"]
|
||||||
path = third_party/rapidjson
|
path = third_party/rapidjson
|
||||||
url = https://github.com/miloyip/rapidjson
|
url = https://github.com/miloyip/rapidjson
|
||||||
[submodule "third_party/doctest"]
|
|
||||||
path = third_party/doctest
|
|
||||||
url = https://github.com/onqtam/doctest
|
|
||||||
|
@ -143,9 +143,7 @@ target_compile_definitions(ccls PRIVATE
|
|||||||
target_include_directories(ccls PRIVATE
|
target_include_directories(ccls PRIVATE
|
||||||
src
|
src
|
||||||
third_party
|
third_party
|
||||||
third_party/rapidjson/include
|
third_party/rapidjson/include)
|
||||||
third_party/loguru
|
|
||||||
third_party/doctest)
|
|
||||||
|
|
||||||
### Install
|
### Install
|
||||||
|
|
||||||
@ -214,7 +212,6 @@ target_sources(ccls PRIVATE
|
|||||||
src/query.cc
|
src/query.cc
|
||||||
src/serializer.cc
|
src/serializer.cc
|
||||||
src/test.cc
|
src/test.cc
|
||||||
src/third_party_impl.cc
|
|
||||||
src/utils.cc
|
src/utils.cc
|
||||||
src/working_files.cc)
|
src/working_files.cc)
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
#include "fuzzy_match.h"
|
#include "fuzzy_match.h"
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
|
||||||
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -133,6 +131,7 @@ int FuzzyMatcher::Match(std::string_view text) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
TEST_SUITE("fuzzy_match") {
|
TEST_SUITE("fuzzy_match") {
|
||||||
bool Ranks(std::string_view pat, std::vector<const char*> texts) {
|
bool Ranks(std::string_view pat, std::vector<const char*> texts) {
|
||||||
FuzzyMatcher fuzzy(pat, 0);
|
FuzzyMatcher fuzzy(pat, 0);
|
||||||
@ -180,3 +179,4 @@ TEST_SUITE("fuzzy_match") {
|
|||||||
CHECK(Ranks("Int", {"int", "INT", "PRINT"}));
|
CHECK(Ranks("Int", {"int", "INT", "PRINT"}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
20
src/main.cc
20
src/main.cc
@ -14,7 +14,6 @@ using namespace ccls;
|
|||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
using namespace llvm::cl;
|
using namespace llvm::cl;
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
|
||||||
#include <rapidjson/error/en.h>
|
#include <rapidjson/error/en.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -29,7 +28,6 @@ namespace {
|
|||||||
opt<bool> opt_help("h", desc("Alias for -help"));
|
opt<bool> opt_help("h", desc("Alias for -help"));
|
||||||
opt<int> opt_verbose("v", desc("verbosity"), init(0));
|
opt<int> opt_verbose("v", desc("verbosity"), init(0));
|
||||||
opt<std::string> opt_test_index("test-index", ValueOptional, init("!"), desc("run index tests"));
|
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_init("init", desc("extra initialization options"));
|
||||||
opt<std::string> opt_log_file("log-file", desc("log"), value_desc("filename"));
|
opt<std::string> opt_log_file("log-file", desc("log"), value_desc("filename"));
|
||||||
@ -53,9 +51,7 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
if (opt_help) {
|
if (opt_help) {
|
||||||
PrintHelpMessage();
|
PrintHelpMessage();
|
||||||
// Also emit doctest help if --test-unit is passed.
|
return 0;
|
||||||
if (!opt_test_unit)
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pipeline::Init();
|
pipeline::Init();
|
||||||
@ -77,20 +73,6 @@ int main(int argc, char** argv) {
|
|||||||
atexit(CloseLog);
|
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 != "!") {
|
if (opt_test_index != "!") {
|
||||||
language_server = false;
|
language_server = false;
|
||||||
if (!RunIndexTests(opt_test_index, sys::Process::StandardInIsUserInput()))
|
if (!RunIndexTests(opt_test_index, sys::Process::StandardInIsUserInput()))
|
||||||
|
14
src/match.cc
14
src/match.cc
@ -4,8 +4,6 @@
|
|||||||
#include "pipeline.hh"
|
#include "pipeline.hh"
|
||||||
using namespace ccls;
|
using namespace ccls;
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
std::optional<Matcher> Matcher::Create(const std::string& search) {
|
std::optional<Matcher> Matcher::Create(const std::string& search) {
|
||||||
/*
|
/*
|
||||||
@ -75,15 +73,3 @@ bool GroupMatch::IsMatch(const std::string& value,
|
|||||||
|
|
||||||
return true;
|
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
src/project.cc
251
src/project.cc
@ -26,7 +26,6 @@ using namespace llvm;
|
|||||||
using namespace llvm::opt;
|
using namespace llvm::opt;
|
||||||
|
|
||||||
#include <clang-c/CXCompilationDatabase.h>
|
#include <clang-c/CXCompilationDatabase.h>
|
||||||
#include <doctest/doctest.h>
|
|
||||||
#include <rapidjson/writer.h>
|
#include <rapidjson/writer.h>
|
||||||
|
|
||||||
#if defined(__unix__) || defined(__APPLE__)
|
#if defined(__unix__) || defined(__APPLE__)
|
||||||
@ -493,253 +492,3 @@ void Project::Index(WorkingFiles* wfiles,
|
|||||||
// trigger refreshing semantic highlight for all working files.
|
// trigger refreshing semantic highlight for all working files.
|
||||||
pipeline::Index("", {}, false);
|
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"});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
#include "serializers/json.h"
|
#include "serializers/json.h"
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
#include "serializer.h"
|
#include "serializer.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
|
||||||
#include <rapidjson/document.h>
|
#include <rapidjson/document.h>
|
||||||
#include <rapidjson/prettywriter.h>
|
#include <rapidjson/prettywriter.h>
|
||||||
#include <rapidjson/stringbuffer.h>
|
#include <rapidjson/stringbuffer.h>
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
#define DOCTEST_CONFIG_IMPLEMENT
|
|
||||||
#include <doctest/doctest.h>
|
|
@ -3,8 +3,6 @@
|
|||||||
#include "log.hh"
|
#include "log.hh"
|
||||||
#include "position.h"
|
#include "position.h"
|
||||||
|
|
||||||
#include <doctest/doctest.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <numeric>
|
#include <numeric>
|
||||||
|
1
third_party/doctest
vendored
1
third_party/doctest
vendored
@ -1 +0,0 @@
|
|||||||
Subproject commit b40b7e799deabac916d631d181a7f19f3060acc5
|
|
Loading…
Reference in New Issue
Block a user