Skip to content

Commit

Permalink
Remove main() from most tests.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pwnall committed Jan 3, 2022
1 parent b2801ee commit 8f464e7
Show file tree
Hide file tree
Showing 29 changed files with 54 additions and 174 deletions.
88 changes: 54 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions db/autocompact_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 0 additions & 5 deletions db/corruption_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,3 @@ TEST_F(CorruptionTest, UnrelatedKeys) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions db/db_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2295,8 +2295,3 @@ TEST_F(DBTest, Randomized) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions db/dbformat_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,3 @@ TEST(FormatTest, InternalKeyDebugString) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions db/fault_injection_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -548,8 +548,3 @@ TEST_F(FaultInjectionTest, FaultTestWithLogReuse) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions db/filename_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,3 @@ TEST(FileNameTest, Construction) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions db/log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 0 additions & 5 deletions db/recovery_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,3 @@ TEST_F(RecoveryTest, ManifestMissing) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions db/skiplist_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 0 additions & 5 deletions db/version_edit_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,3 @@ TEST(VersionEditTest, EncodeDecode) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions db/version_set_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,8 +329,3 @@ TEST_F(AddBoundaryInputsTest, TestDisjoinFilePointers) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions db/write_batch_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,3 @@ TEST(WriteBatchTest, ApproximateSize) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions helpers/memenv/memenv_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,3 @@ TEST_F(MemEnvTest, DBTest) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions issues/issue178_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,3 @@ TEST(Issue178, Test) {
}

} // anonymous namespace

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions issues/issue200_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,3 @@ TEST(Issue200, Test) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions issues/issue320_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,3 @@ TEST(Issue320, Test) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions table/filter_block_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,3 @@ TEST_F(FilterBlockTest, MultiChunk) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions table/table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,3 @@ TEST(TableTest, ApproximateOffsetOfCompressed) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions util/arena_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,3 @@ TEST(ArenaTest, Simple) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions util/bloom_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 0 additions & 5 deletions util/cache_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,3 @@ TEST_F(CacheTest, ZeroSizeCache) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions util/coding_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,3 @@ TEST(Coding, Strings) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions util/crc32c_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
5 changes: 0 additions & 5 deletions util/env_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,3 @@ TEST_F(EnvTest, ReopenAppendableFile) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions util/hash_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,3 @@ TEST(HASH, SignedUnsignedIssue) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions util/logging_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,3 @@ TEST(Logging, ConsumeDecimalNumberNoDigits) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions util/no_destructor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,3 @@ TEST(NoDestructorTest, StaticInstance) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
5 changes: 0 additions & 5 deletions util/status_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,3 @@ TEST(Status, MoveConstructor) {
}

} // namespace leveldb

int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

0 comments on commit 8f464e7

Please sign in to comment.