Skip to content

Commit

Permalink
revert unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bkietz committed Aug 15, 2024
1 parent 0788f56 commit 7d78c76
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 84 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,7 @@ if(NANOARROW_IPC AND (NANOARROW_BUILD_INTEGRATION_TESTS OR NANOARROW_BUILD_TESTS
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
$<INSTALL_INTERFACE:include>)
target_link_libraries(nanoarrow_ipc_integration
PRIVATE nanoarrow_testing
nanoarrow_ipc
flatccrt
gtest
gmock
PRIVATE nanoarrow_testing nanoarrow_ipc flatccrt
nanoarrow_coverage_config)
endif()

Expand Down Expand Up @@ -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)
Expand Down
112 changes: 35 additions & 77 deletions src/nanoarrow/integration/ipc_integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
// under the License.

#include <cstdlib>
#include <fstream>

#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include <nanoarrow/nanoarrow_ipc.hpp>
#include <nanoarrow/nanoarrow_testing.hpp>

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

0 comments on commit 7d78c76

Please sign in to comment.