'how to build leveldb's single test files?

i kown it's about gtest framework, i can use gtest for my own demo but in leveldb repo i don't know how to build a single test file such as:leveldb/db/db_test.cc, it will report other confused errors.

precondition:

  • what i want is debug a single testfile such as db_test.cc.

i use vscode, this is part of my task.json which i think already contains all needed:

                "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
                "-I", "/root/wzy/code/cpp/leveldb/include",
                "-I", "/root/wzy/code/cpp/leveldb",
                "-I", "/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include",
                "-L", "/root/wzy/code/cpp/leveldb/build",
                "-lleveldb",
                "-lsnappy",
                "-pthread"
            ]

and build errors like these:

/usr/bin/g++ -fdiagnostics-color=always -g /root/wzy/code/cpp/leveldb/db/db_test.cc -o /root/wzy/code/cpp/leveldb/db/db_test -I /root/wzy/code/cpp/leveldb/include -I /root/wzy/code/cpp/leveldb -I /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include -L /root/wzy/code/cpp/leveldb/build -lleveldb -lsnappy -lpthread
In file included from /root/wzy/code/cpp/leveldb/db/db_test.cc:12:
/root/wzy/code/cpp/leveldb/db/db_impl.h:174:3: error: 'port' does not name a type
  174 |   port::Mutex mutex_;
      |   ^~~~
/root/wzy/code/cpp/leveldb/db/db_impl.h:176:3: error: 'port' does not name a type
  176 |   port::CondVar background_work_finished_signal_ GUARDED_BY(mutex_);
      |   ^~~~
In file included from /root/wzy/code/cpp/leveldb/db/db_test.cc:14:
/root/wzy/code/cpp/leveldb/db/version_set.h:181:41: error: 'port' has not been declared
  181 |   Status LogAndApply(VersionEdit* edit, port::Mutex* mu)
      |                                         ^~~~
/root/wzy/code/cpp/leveldb/db/version_set.h:181:52: error: expected ',' or '...' before '*' token
  181 |   Status LogAndApply(VersionEdit* edit, port::Mutex* mu)
      |                                                    ^
In file included from /root/wzy/code/cpp/leveldb/db/db_test.cc:24:
/root/wzy/code/cpp/leveldb/util/mutexlock.h:25:22: error: 'port' has not been declared
   25 |   explicit MutexLock(port::Mutex* mu) EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) {
      |                      ^~~~
/root/wzy/code/cpp/leveldb/util/mutexlock.h:25:33: error: expected ')' before '*' token
   25 |   explicit MutexLock(port::Mutex* mu) EXCLUSIVE_LOCK_FUNCTION(mu) : mu_(mu) {
      |                     ~           ^
      |                                 )
/root/wzy/code/cpp/leveldb/util/mutexlock.h:34:3: error: 'port' does not name a type
   34 |   port::Mutex* const mu_;
      |   ^~~~
/root/wzy/code/cpp/leveldb/util/mutexlock.h: In destructor 'leveldb::MutexLock::~MutexLock()':
/root/wzy/code/cpp/leveldb/util/mutexlock.h:28:42: error: 'class leveldb::MutexLock' has no member named 'mu_'
   28 |   ~MutexLock() UNLOCK_FUNCTION() { this->mu_->Unlock(); }
      |                                          ^~~
In file included from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-spec-builders.h:75,
                 from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-function-mocker.h:42,
                 from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock.h:61,
                 from /root/wzy/code/cpp/leveldb/util/testutil.h:8,
                 from /root/wzy/code/cpp/leveldb/db/db_test.cc:25:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In member function 'testing::internal::FieldsAreMatcher<Inner>::operator testing::Matcher<T>() const':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:3165:49: error: 'IndexSequenceFor' was not declared in this scope; did you mean 'IndexSequence'?
 3165 |         new FieldsAreMatcherImpl<const Struct&, IndexSequenceFor<Inner...>>(
      |                                                 ^~~~~~~~~~~~~~~~
      |                                                 IndexSequence
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:3165:71: error: expected parameter pack before '...'
 3165 |         new FieldsAreMatcherImpl<const Struct&, IndexSequenceFor<Inner...>>(
      |                                                                       ^~~
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:3165:71: error: template argument 2 is invalid
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4291:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
 4291 |     const internal::StringLike<T>& str) {
      |                     ^~~~~~~~~~
      |                     Strings
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4291:31: error: expected ',' or '...' before '<' token
 4291 |     const internal::StringLike<T>& str) {
      |                               ^
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher<testing::internal::StrEqualityMatcher<std::__cxx11::basic_string<char> > > testing::StrEq(int)':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4293:61: error: 'str' was not declared in this scope; did you mean 'std'?
 4293 |       internal::StrEqualityMatcher<std::string>(std::string(str), true, true));
      |                                                             ^~~
      |                                                             std
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4299:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
 4299 |     const internal::StringLike<T>& str) {
      |                     ^~~~~~~~~~
      |                     Strings
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4299:31: error: expected ',' or '...' before '<' token
 4299 |     const internal::StringLike<T>& str) {
      |                               ^
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher<testing::internal::StrEqualityMatcher<std::__cxx11::basic_string<char> > > testing::StrNe(int)':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4301:61: error: 'str' was not declared in this scope; did you mean 'std'?
 4301 |       internal::StrEqualityMatcher<std::string>(std::string(str), false, true));
      |                                                             ^~~
      |                                                             std
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4307:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
 4307 |     const internal::StringLike<T>& str) {
      |                     ^~~~~~~~~~
      |                     Strings
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4307:31: error: expected ',' or '...' before '<' token
 4307 |     const internal::StringLike<T>& str) {
      |                               ^
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher<testing::internal::StrEqualityMatcher<std::__cxx11::basic_string<char> > > testing::StrCaseEq(int)':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4309:61: error: 'str' was not declared in this scope; did you mean 'std'?
 4309 |       internal::StrEqualityMatcher<std::string>(std::string(str), true, false));
      |                                                             ^~~
      |                                                             std
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4315:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
 4315 |     const internal::StringLike<T>& str) {
      |                     ^~~~~~~~~~
      |                     Strings
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4315:31: error: expected ',' or '...' before '<' token
 4315 |     const internal::StringLike<T>& str) {
      |                               ^
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher<testing::internal::StrEqualityMatcher<std::__cxx11::basic_string<char> > > testing::StrCaseNe(int)':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4317:19: error: 'str' was not declared in this scope; did you mean 'std'?
 4317 |       std::string(str), false, false));
      |                   ^~~
      |                   std
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4324:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
 4324 |     const internal::StringLike<T>& substring) {
      |                     ^~~~~~~~~~
      |                     Strings
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4324:31: error: expected ',' or '...' before '<' token
 4324 |     const internal::StringLike<T>& substring) {
      |                               ^
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher<testing::internal::HasSubstrMatcher<std::__cxx11::basic_string<char> > > testing::HasSubstr(int)':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4326:59: error: 'substring' was not declared in this scope; did you mean 'IsSubstring'?
 4326 |       internal::HasSubstrMatcher<std::string>(std::string(substring)));
      |                                                           ^~~~~~~~~
      |                                                           IsSubstring
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4332:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
 4332 |     const internal::StringLike<T>& prefix) {
      |                     ^~~~~~~~~~
      |                     Strings
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4332:31: error: expected ',' or '...' before '<' token
 4332 |     const internal::StringLike<T>& prefix) {
      |                               ^
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher<testing::internal::StartsWithMatcher<std::__cxx11::basic_string<char> > > testing::StartsWith(int)':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4334:60: error: 'prefix' was not declared in this scope; did you mean 'profil'?
 4334 |       internal::StartsWithMatcher<std::string>(std::string(prefix)));
      |                                                            ^~~~~~
      |                                                            profil
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: At global scope:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4340:21: error: 'StringLike' in namespace 'testing::internal' does not name a template type; did you mean 'Strings'?
 4340 |     const internal::StringLike<T>& suffix) {
      |                     ^~~~~~~~~~
      |                     Strings
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4340:31: error: expected ',' or '...' before '<' token
 4340 |     const internal::StringLike<T>& suffix) {
      |                               ^
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In function 'testing::PolymorphicMatcher<testing::internal::EndsWithMatcher<std::__cxx11::basic_string<char> > > testing::EndsWith(int)':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:4342:58: error: 'suffix' was not declared in this scope
 4342 |       internal::EndsWithMatcher<std::string>(std::string(suffix)));
      |                                                          ^~~~~~
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h: In member function 'bool testing::internal::ExceptionMatcherImpl<Err>::MatchAndExplain(T&&, testing::MatchResultListener*) const':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:5150:77: error: no matching function for call to 'GetTypeName(const std::type_info&)'
 5150 |       *listener << "throws an exception of type " << GetTypeName(typeid(err));
      |                                                                             ^
In file included from /usr/include/gtest/internal/gtest-internal.h:67,
                 from /usr/include/gtest/gtest.h:62,
                 from /root/wzy/code/cpp/leveldb/db/db_test.cc:11:
/usr/include/gtest/internal/gtest-type-util.h:80:13: note: candidate: 'template<class T> std::string testing::internal::GetTypeName()'
   80 | std::string GetTypeName() {
      |             ^~~~~~~~~~~
/usr/include/gtest/internal/gtest-type-util.h:80:13: note:   template argument deduction/substitution failed:
In file included from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-spec-builders.h:75,
                 from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-function-mocker.h:42,
                 from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock.h:61,
                 from /root/wzy/code/cpp/leveldb/util/testutil.h:8,
                 from /root/wzy/code/cpp/leveldb/db/db_test.cc:25:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-matchers.h:5150:77: note:   candidate expects 0 arguments, 1 provided
 5150 |       *listener << "throws an exception of type " << GetTypeName(typeid(err));
      |                                                                             ^
In file included from /root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock.h:63,
                 from /root/wzy/code/cpp/leveldb/util/testutil.h:8,
                 from /root/wzy/code/cpp/leveldb/db/db_test.cc:25:
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h: In member function 'decltype (testing::internal::InvokeArgument(get<index>(std::forward_as_tuple((forward<Args>)(args)...)), (declval<const Params&>)()...)) testing::internal::InvokeArgumentAction<index, Params>::operator()(Args&& ...) const':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h:519:47: error: 'FlatTupleConstructTag' was not declared in this scope
  519 |     internal::FlatTuple<Args&&...> args_tuple(FlatTupleConstructTag{},
      |                                               ^~~~~~~~~~~~~~~~~~~~~
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h: In function 'testing::internal::InvokeArgumentAction<index, typename std::decay<Params>::type ...> testing::InvokeArgument(Params&& ...)':
/root/wzy/code/cpp/leveldb/third_party/googletest/googlemock/include/gmock/gmock-more-actions.h:564:17: error: 'FlatTupleConstructTag' is not a member of 'testing::internal'
  564 |       internal::FlatTupleConstructTag{}, std::forward<Params>(params)...)};
      |                 ^~~~~~~~~~~~~~~~~~~~~
/root/wzy/code/cpp/leveldb/db/db_test.cc: At global scope:
/root/wzy/code/cpp/leveldb/db/db_test.cc:61:3: error: 'port' does not name a type
   61 |   port::Mutex mu_;
      |   ^~~~
/root/wzy/code/cpp/leveldb/db/db_test.cc: In member function 'void leveldb::{anonymous}::AtomicCounter::IncrementBy(int)':
/root/wzy/code/cpp/leveldb/db/db_test.cc:48:18: error: 'mu_' was not declared in this scope
   48 |     MutexLock l(&mu_);
      |                  ^~~
/root/wzy/code/cpp/leveldb/db/db_test.cc: In member function 'int leveldb::{anonymous}::AtomicCounter::Read()':
/root/wzy/code/cpp/leveldb/db/db_test.cc:52:18: error: 'mu_' was not declared in this scope
   52 |     MutexLock l(&mu_);
      |                  ^~~
/root/wzy/code/cpp/leveldb/db/db_test.cc: In member function 'void leveldb::{anonymous}::AtomicCounter::Reset()':
/root/wzy/code/cpp/leveldb/db/db_test.cc:56:18: error: 'mu_' was not declared in this scope
   56 |     MutexLock l(&mu_); 

thanks @Tsyvarev, I defined a LEVELDB_PLATFORM_POSIX in source and this "prot" err is missing, but other errs still exist, I will keep doing this till I can GDB a single gtest file.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source