Improved testing from CMake project

This commit is contained in:
Konstantin Podsvirov 2015-09-15 15:01:05 +03:00
parent 905f464035
commit 2fa0439b00
2 changed files with 17 additions and 3 deletions

View File

@ -96,6 +96,8 @@ set(common_test_files
${protobuf_source_dir}/src/google/protobuf/test_util.cc
${protobuf_source_dir}/src/google/protobuf/testing/file.cc
${protobuf_source_dir}/src/google/protobuf/testing/googletest.cc
${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc
)
set(common_lite_test_files
@ -116,7 +118,6 @@ set(tests_files
${protobuf_source_dir}/src/google/protobuf/compiler/importer_unittest.cc
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc
${protobuf_source_dir}/src/google/protobuf/compiler/java/java_plugin_unittest.cc
${protobuf_source_dir}/src/google/protobuf/compiler/mock_code_generator.cc
${protobuf_source_dir}/src/google/protobuf/compiler/objectivec/objectivec_helpers_unittest.cc
${protobuf_source_dir}/src/google/protobuf/compiler/parser_unittest.cc
${protobuf_source_dir}/src/google/protobuf/compiler/python/python_plugin_unittest.cc
@ -162,7 +163,6 @@ set(tests_files
${protobuf_source_dir}/src/google/protobuf/util/internal/json_stream_parser_test.cc
${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectsource_test.cc
${protobuf_source_dir}/src/google/protobuf/util/internal/protostream_objectwriter_test.cc
${protobuf_source_dir}/src/google/protobuf/util/internal/type_info_test_helper.cc
${protobuf_source_dir}/src/google/protobuf/util/json_util_test.cc
${protobuf_source_dir}/src/google/protobuf/util/time_util_test.cc
${protobuf_source_dir}/src/google/protobuf/util/type_resolver_util_test.cc
@ -179,7 +179,6 @@ set(test_plugin_files
${protobuf_source_dir}/src/google/protobuf/testing/file.h
${protobuf_source_dir}/src/google/protobuf/compiler/test_plugin.cc
)
add_executable(test_plugin ${test_plugin_files})
target_link_libraries(test_plugin libprotoc libprotobuf gmock)
@ -194,3 +193,14 @@ set(lite_arena_test_files
)
add_executable(lite-arena-test ${lite_arena_test_files} ${common_lite_test_files} ${lite_test_proto_files})
target_link_libraries(lite-arena-test libprotobuf-lite gmock_main)
enable_testing()
add_compile_options(-DGOOGLE_PROTOBUF_TEST_PLUGIN_PATH="$<TARGET_FILE:test_plugin>")
add_library(libtests STATIC ${common_test_files} ${tests_proto_files} ${lite_test_proto_files})
foreach(file ${tests_files})
get_filename_component(name ${file} NAME_WE)
add_executable(${name} ${file})
target_link_libraries(${name} libtests libprotoc libprotobuf gmock_main)
add_test(NAME ${name} COMMAND ${name}
WORKING_DIRECTORY ${protobuf_source_dir})
endforeach()

View File

@ -314,12 +314,16 @@ void CommandLineInterfaceTest::Run(const string& command) {
string plugin_path;
#ifdef GOOGLE_PROTOBUF_TEST_PLUGIN_PATH
plugin_path = GOOGLE_PROTOBUF_TEST_PLUGIN_PATH;
#else
for (int i = 0; i < GOOGLE_ARRAYSIZE(possible_paths); i++) {
if (access(possible_paths[i], F_OK) == 0) {
plugin_path = possible_paths[i];
break;
}
}
#endif
if (plugin_path.empty()) {
#else