diff --git a/CMakeLists.txt b/CMakeLists.txt index 75e293f3f..9b1158404 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -232,11 +232,7 @@ if(NANOARROW_IPC AND (NANOARROW_BUILD_INTEGRATION_TESTS OR NANOARROW_BUILD_TESTS $ $) target_link_libraries(nanoarrow_ipc_integration - PRIVATE nanoarrow_testing - nanoarrow_ipc - flatccrt - gtest - gmock + PRIVATE nanoarrow_testing nanoarrow_ipc flatccrt nanoarrow_coverage_config) endif() @@ -527,8 +523,6 @@ if(NANOARROW_BUILD_TESTS) target_link_libraries(nanoarrow_ipc_files_test nanoarrow_testing ZLIB::ZLIB nanoarrow_coverage_config) target_link_libraries(nanoarrow_ipc_decoder_test gmock_main) - - gtest_discover_tests(nanoarrow_ipc_integration) endif() if(NANOARROW_DEVICE) diff --git a/src/nanoarrow/integration/ipc_integration.cc b/src/nanoarrow/integration/ipc_integration.cc index aa3c8351e..52392c8d1 100644 --- a/src/nanoarrow/integration/ipc_integration.cc +++ b/src/nanoarrow/integration/ipc_integration.cc @@ -16,10 +16,7 @@ // under the License. #include -#include -#include -#include #include #include @@ -62,6 +59,41 @@ ArrowErrorCode JsonToArrow(struct ArrowError*); ArrowErrorCode StreamToFile(struct ArrowError*); ArrowErrorCode FileToStream(struct ArrowError*); +int main(int argc, char** argv) try { + std::string command = GetEnv("COMMAND"); + + ArrowErrorCode error_code; + struct ArrowError error; + + if (command == "VALIDATE") { + std::cout << "Validating that " << GetEnv("ARROW_PATH") << " reads identical to " + << GetEnv("JSON_PATH") << std::endl; + + error_code = Validate(&error); + } else if (command == "JSON_TO_ARROW") { + std::cout << "Producing " << GetEnv("ARROW_PATH") << " from " << GetEnv("JSON_PATH") + << std::endl; + + error_code = JsonToArrow(&error); + } else if (command == "STREAM_TO_FILE") { + error_code = StreamToFile(&error); + } else if (command == "FILE_TO_STREAM") { + error_code = FileToStream(&error); + } else { + std::cerr << kUsage; + return 1; + } + + if (error_code != NANOARROW_OK) { + std::cerr << "Command " << command << " failed (" << error_code << "=" + << strerror(error_code) << "): " << error.message << std::endl; + } + return error_code; +} catch (std::exception const& e) { + std::cerr << "Uncaught exception: " << e.what() << std::endl; + return 1; +} + struct File { ~File() { if (file_ != nullptr) { @@ -297,77 +329,3 @@ ArrowErrorCode FileToStream(struct ArrowError* error) { return table.Write(output_stream.get(), /*write_file=*/false, error); } - -TEST(Integration, ErrorMessages) { - MaterializedArrayStream table; - { - struct ArrowError error {}; - EXPECT_NE(table.FromJsonFile(__FILE__, &error), NANOARROW_OK); - EXPECT_THAT(std::string(error.message), - testing::HasSubstr("syntax error while parsing value")); - } - - { - struct ArrowError error {}; - EXPECT_NE(table.FromIpcFile(__FILE__, &error), NANOARROW_OK); - EXPECT_THAT(std::string(error.message), - testing::HasSubstr("File did not begin with 'ARROW1")); - } - - { - struct ArrowError error {}; - EXPECT_NE(table.FromJsonFile(__FILE__ + std::string(".phony"), &error), NANOARROW_OK); - EXPECT_THAT(std::string(error.message), - testing::MatchesRegex( - R"(Opening file '.*/ipc_integration.cc.phony' failed with errno=2)")); - } - - { - struct ArrowError error {}; - File tmp{tmpfile()}; - EXPECT_EQ(fwrite("yo", 1, sizeof("yo"), tmp), sizeof("yo")); - EXPECT_NE(table.FromIpcFile(tmp, &error), NANOARROW_OK); - EXPECT_THAT(std::string(error.message), - testing::HasSubstr("Expected file of more than 8 bytes, got 3")); - } -} - -int main(int argc, char** argv) try { - std::string command = GetEnv("COMMAND"); - - ArrowErrorCode error_code; - struct ArrowError error; - - if (command == "VALIDATE") { - std::cout << "Validating that " << GetEnv("ARROW_PATH") << " reads identical to " - << GetEnv("JSON_PATH") << std::endl; - - error_code = Validate(&error); - } else if (command == "JSON_TO_ARROW") { - std::cout << "Producing " << GetEnv("ARROW_PATH") << " from " << GetEnv("JSON_PATH") - << std::endl; - - error_code = JsonToArrow(&error); - } else if (command == "STREAM_TO_FILE") { - error_code = StreamToFile(&error); - } else if (command == "FILE_TO_STREAM") { - error_code = FileToStream(&error); - } else { - if (argc == 1 || argv[1] == std::string{"-h"} || argv[1] == std::string{"--help"}) { - // skip printing usage if for example --gtest_list_tests is used; - // that command obviously doesn't need the extra noise - std::cerr << kUsage; - } - testing::InitGoogleTest(&argc, argv); - return RUN_ALL_TESTS(); - } - - if (error_code != NANOARROW_OK) { - std::cerr << "Command " << command << " failed (" << error_code << "=" - << strerror(error_code) << "): " << error.message << std::endl; - } - return error_code; -} catch (std::exception const& e) { - std::cerr << "Uncaught exception: " << e.what() << std::endl; - return 1; -}