Browse Source

Remove main() from most tests.

This gives some flexibility to embedders.

Currently, embedders have to build a binary for each test file.

After this CL, embedders can still choose to have a binary for each test
file, by linking each test file with a googletest target that includes
main() (usually "gtest_main"). Embedders can also choose to build a
single binary for almost all test files, and link with a googletest
target that includes main(). The latter is more convenient for projects
that have very few test binaries, like Chromium.

PiperOrigin-RevId: 419470798
ld
Victor Costan 3 years ago
committed by Victor Costan
parent
commit
8f464e7f68
29 changed files with 54 additions and 174 deletions
  1. +54
    -34
      CMakeLists.txt
  2. +0
    -5
      db/autocompact_test.cc
  3. +0
    -5
      db/corruption_test.cc
  4. +0
    -5
      db/db_test.cc
  5. +0
    -5
      db/dbformat_test.cc
  6. +0
    -5
      db/fault_injection_test.cc
  7. +0
    -5
      db/filename_test.cc
  8. +0
    -5
      db/log_test.cc
  9. +0
    -5
      db/recovery_test.cc
  10. +0
    -5
      db/skiplist_test.cc
  11. +0
    -5
      db/version_edit_test.cc
  12. +0
    -5
      db/version_set_test.cc
  13. +0
    -5
      db/write_batch_test.cc
  14. +0
    -5
      helpers/memenv/memenv_test.cc
  15. +0
    -5
      issues/issue178_test.cc
  16. +0
    -5
      issues/issue200_test.cc
  17. +0
    -5
      issues/issue320_test.cc
  18. +0
    -5
      table/filter_block_test.cc
  19. +0
    -5
      table/table_test.cc
  20. +0
    -5
      util/arena_test.cc
  21. +0
    -5
      util/bloom_test.cc
  22. +0
    -5
      util/cache_test.cc
  23. +0
    -5
      util/coding_test.cc
  24. +0
    -5
      util/crc32c_test.cc
  25. +0
    -5
      util/env_test.cc
  26. +0
    -5
      util/hash_test.cc
  27. +0
    -5
      util/logging_test.cc
  28. +0
    -5
      util/no_destructor_test.cc
  29. +0
    -5
      util/status_test.cc

+ 54
- 34
CMakeLists.txt View File

@ -306,6 +306,60 @@ if(LEVELDB_BUILD_TESTS)
APPEND PROPERTY COMPILE_OPTIONS -Wno-missing-field-initializers)
endif(LEVELDB_HAVE_NO_MISSING_FIELD_INITIALIZERS)
add_executable(leveldb_tests "")
target_sources(leveldb_tests
PRIVATE
# "db/fault_injection_test.cc"
# "issues/issue178_test.cc"
# "issues/issue200_test.cc"
# "issues/issue320_test.cc"
"${PROJECT_BINARY_DIR}/${LEVELDB_PORT_CONFIG_DIR}/port_config.h"
# "util/env_test.cc"
"util/status_test.cc"
"util/no_destructor_test.cc"
"util/testutil.cc"
"util/testutil.h"
)
if(NOT BUILD_SHARED_LIBS)
target_sources(leveldb_tests
PRIVATE
"db/autocompact_test.cc"
"db/corruption_test.cc"
"db/db_test.cc"
"db/dbformat_test.cc"
"db/filename_test.cc"
"db/log_test.cc"
"db/recovery_test.cc"
"db/skiplist_test.cc"
"db/version_edit_test.cc"
"db/version_set_test.cc"
"db/write_batch_test.cc"
"helpers/memenv/memenv_test.cc"
"table/filter_block_test.cc"
"table/table_test.cc"
"util/arena_test.cc"
"util/bloom_test.cc"
"util/cache_test.cc"
"util/coding_test.cc"
"util/crc32c_test.cc"
"util/hash_test.cc"
"util/logging_test.cc"
)
endif(NOT BUILD_SHARED_LIBS)
target_link_libraries(leveldb_tests leveldb gmock gtest gtest_main)
target_compile_definitions(leveldb_tests
PRIVATE
${LEVELDB_PLATFORM_NAME}=1
)
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions(leveldb_tests
PRIVATE
LEVELDB_HAS_PORT_CONFIG_H=1
)
endif(NOT HAVE_CXX17_HAS_INCLUDE)
add_test(NAME "leveldb_tests" COMMAND "leveldb_tests")
function(leveldb_test test_file)
get_filename_component(test_target_name "${test_file}" NAME_WE)
@ -334,42 +388,8 @@ if(LEVELDB_BUILD_TESTS)
endfunction(leveldb_test)
leveldb_test("db/c_test.c")
leveldb_test("db/fault_injection_test.cc")
leveldb_test("issues/issue178_test.cc")
leveldb_test("issues/issue200_test.cc")
leveldb_test("issues/issue320_test.cc")
leveldb_test("util/env_test.cc")
leveldb_test("util/status_test.cc")
leveldb_test("util/no_destructor_test.cc")
if(NOT BUILD_SHARED_LIBS)
leveldb_test("db/autocompact_test.cc")
leveldb_test("db/corruption_test.cc")
leveldb_test("db/db_test.cc")
leveldb_test("db/dbformat_test.cc")
leveldb_test("db/filename_test.cc")
leveldb_test("db/log_test.cc")
leveldb_test("db/recovery_test.cc")
leveldb_test("db/skiplist_test.cc")
leveldb_test("db/version_edit_test.cc")
leveldb_test("db/version_set_test.cc")
leveldb_test("db/write_batch_test.cc")
leveldb_test("helpers/memenv/memenv_test.cc")
leveldb_test("table/filter_block_test.cc")
leveldb_test("table/table_test.cc")
leveldb_test("util/arena_test.cc")
leveldb_test("util/bloom_test.cc")
leveldb_test("util/cache_test.cc")
leveldb_test("util/coding_test.cc")
leveldb_test("util/crc32c_test.cc")
leveldb_test("util/hash_test.cc")
leveldb_test("util/logging_test.cc")
# TODO(costan): This test also uses
# "util/env_{posix|windows}_test_helper.h"
if (WIN32)

+ 0
- 5
db/autocompact_test.cc View File

@ -108,8 +108,3 @@ TEST_F(AutoCompactTest, ReadAll) { DoReads(kCount); }
TEST_F(AutoCompactTest, ReadHalf) { DoReads(kCount / 2); }
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/corruption_test.cc View File

@ -360,8 +360,3 @@ TEST_F(CorruptionTest, UnrelatedKeys) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/db_test.cc View File

@ -2295,8 +2295,3 @@ TEST_F(DBTest, Randomized) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/dbformat_test.cc View File

@ -126,8 +126,3 @@ TEST(FormatTest, InternalKeyDebugString) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/fault_injection_test.cc View File

@ -548,8 +548,3 @@ TEST_F(FaultInjectionTest, FaultTestWithLogReuse) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/filename_test.cc View File

@ -125,8 +125,3 @@ TEST(FileNameTest, Construction) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/log_test.cc View File

@ -556,8 +556,3 @@ TEST_F(LogTest, ReadPastEnd) { CheckOffsetPastEndReturnsNoRecords(5); }
} // namespace log
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/recovery_test.cc View File

@ -332,8 +332,3 @@ TEST_F(RecoveryTest, ManifestMissing) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/skiplist_test.cc View File

@ -366,8 +366,3 @@ TEST(SkipTest, Concurrent4) { RunConcurrent(4); }
TEST(SkipTest, Concurrent5) { RunConcurrent(5); }
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/version_edit_test.cc View File

@ -39,8 +39,3 @@ TEST(VersionEditTest, EncodeDecode) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/version_set_test.cc View File

@ -329,8 +329,3 @@ TEST_F(AddBoundaryInputsTest, TestDisjoinFilePointers) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
db/write_batch_test.cc View File

@ -130,8 +130,3 @@ TEST(WriteBatchTest, ApproximateSize) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
helpers/memenv/memenv_test.cc View File

@ -257,8 +257,3 @@ TEST_F(MemEnvTest, DBTest) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
issues/issue178_test.cc View File

@ -83,8 +83,3 @@ TEST(Issue178, Test) {
}
} // anonymous namespace
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
issues/issue200_test.cc View File

@ -52,8 +52,3 @@ TEST(Issue200, Test) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
issues/issue320_test.cc View File

@ -124,8 +124,3 @@ TEST(Issue320, Test) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
table/filter_block_test.cc View File

@ -120,8 +120,3 @@ TEST_F(FilterBlockTest, MultiChunk) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
table/table_test.cc View File

@ -827,8 +827,3 @@ TEST(TableTest, ApproximateOffsetOfCompressed) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/arena_test.cc View File

@ -59,8 +59,3 @@ TEST(ArenaTest, Simple) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/bloom_test.cc View File

@ -152,8 +152,3 @@ TEST_F(BloomTest, VaryingLengths) {
// Different bits-per-byte
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/cache_test.cc View File

@ -222,8 +222,3 @@ TEST_F(CacheTest, ZeroSizeCache) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/coding_test.cc View File

@ -191,8 +191,3 @@ TEST(Coding, Strings) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/crc32c_test.cc View File

@ -54,8 +54,3 @@ TEST(CRC, Mask) {
} // namespace crc32c
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/env_test.cc View File

@ -233,8 +233,3 @@ TEST_F(EnvTest, ReopenAppendableFile) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/hash_test.cc View File

@ -39,8 +39,3 @@ TEST(HASH, SignedUnsignedIssue) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/logging_test.cc View File

@ -138,8 +138,3 @@ TEST(Logging, ConsumeDecimalNumberNoDigits) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/no_destructor_test.cc View File

@ -42,8 +42,3 @@ TEST(NoDestructorTest, StaticInstance) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

+ 0
- 5
util/status_test.cc View File

@ -37,8 +37,3 @@ TEST(Status, MoveConstructor) {
}
} // namespace leveldb
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

Loading…
Cancel
Save