From dc0b14d87188d8ae3fc62ea0392cf44c678fc01f Mon Sep 17 00:00:00 2001 From: Christian Blichmann Date: Thu, 27 Jan 2022 13:59:14 +0100 Subject: [PATCH] Jsonnet: Restructure tests - Move and rename headers to main dir - Fixup header guards - Rename test main binary that conflicted with directory name `tests` --- contrib/jsonnet/CMakeLists.txt | 26 ++++++++- contrib/jsonnet/examples/CMakeLists.txt | 1 - .../{headers => }/jsonnet_base_sandbox.h | 6 +-- .../{headers => }/jsonnet_base_transaction.h | 6 +-- contrib/jsonnet/jsonnet_helper.h | 53 +++++++++---------- .../{tests => }/jsonnet_test_helper.cc | 2 +- .../jsonnet/{tests => }/jsonnet_test_helper.h | 6 +-- contrib/jsonnet/{tests => }/jsonnet_tests.cc | 2 +- contrib/jsonnet/tests/CMakeLists.txt | 40 -------------- 9 files changed, 61 insertions(+), 81 deletions(-) rename contrib/jsonnet/{headers => }/jsonnet_base_sandbox.h (92%) rename contrib/jsonnet/{headers => }/jsonnet_base_transaction.h (89%) rename contrib/jsonnet/{tests => }/jsonnet_test_helper.cc (98%) rename contrib/jsonnet/{tests => }/jsonnet_test_helper.h (94%) rename contrib/jsonnet/{tests => }/jsonnet_tests.cc (98%) delete mode 100644 contrib/jsonnet/tests/CMakeLists.txt diff --git a/contrib/jsonnet/CMakeLists.txt b/contrib/jsonnet/CMakeLists.txt index 02cc319..6b009cb 100644 --- a/contrib/jsonnet/CMakeLists.txt +++ b/contrib/jsonnet/CMakeLists.txt @@ -64,5 +64,29 @@ if(SAPI_ENABLE_TESTS) include(GoogleTest) enable_testing() - add_subdirectory(tests) + # Create directories so the tests will be able to access them + file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/tests/tests_input" + "${PROJECT_BINARY_DIR}/tests/tests_output" + "${PROJECT_BINARY_DIR}/tests/tests_expected_output") + + add_custom_target(test_preparation ALL + COMMAND cp ${PROJECT_SOURCE_DIR}/examples/jsonnet_codes/* + ${PROJECT_BINARY_DIR}/tests/tests_input + COMMAND cp ${PROJECT_SOURCE_DIR}/examples/jsonnet_codes_expected_output/* + ${PROJECT_BINARY_DIR}/tests/tests_expected_output + ) + + add_executable(jsonnet_tests + jsonnet_test_helper.cc + jsonnet_test_helper.h + jsonnet_tests.cc + ) + target_include_directories(jsonnet_tests PUBLIC + ${PROJECT_SOURCE_DIR} + ) + target_link_libraries(jsonnet_tests + jsonnet_sapi + sapi::test_main + ) + gtest_discover_tests(jsonnet_tests) endif() diff --git a/contrib/jsonnet/examples/CMakeLists.txt b/contrib/jsonnet/examples/CMakeLists.txt index 1a40fb5..64b03b2 100644 --- a/contrib/jsonnet/examples/CMakeLists.txt +++ b/contrib/jsonnet/examples/CMakeLists.txt @@ -24,7 +24,6 @@ add_custom_command( list(APPEND JSONNET_SAPI_INCLUDE_DIRS ${PROJECT_SOURCE_DIR} - ${PROJECT_SOURCE_DIR}/headers ${PROJECT_BINARY_DIR} ${PROJECT_BINARY_DIR}/gen_files ) diff --git a/contrib/jsonnet/headers/jsonnet_base_sandbox.h b/contrib/jsonnet/jsonnet_base_sandbox.h similarity index 92% rename from contrib/jsonnet/headers/jsonnet_base_sandbox.h rename to contrib/jsonnet/jsonnet_base_sandbox.h index 4d2eb1e..caff406 100644 --- a/contrib/jsonnet/headers/jsonnet_base_sandbox.h +++ b/contrib/jsonnet/jsonnet_base_sandbox.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef JSONNET_BASE_SANDBOX_H_ -#define JSONNET_BASE_SANDBOX_H_ +#ifndef CONTRIB_JSONNET_BASE_SANDBOX_H_ +#define CONTRIB_JSONNET_BASE_SANDBOX_H_ #include #include @@ -52,4 +52,4 @@ class JsonnetBaseSandbox : public JsonnetSandbox { std::string out_file_; }; -#endif // JSONNET_BASE_SANDBOX_H_ +#endif // CONTRIB_JSONNET_BASE_SANDBOX_H_ diff --git a/contrib/jsonnet/headers/jsonnet_base_transaction.h b/contrib/jsonnet/jsonnet_base_transaction.h similarity index 89% rename from contrib/jsonnet/headers/jsonnet_base_transaction.h rename to contrib/jsonnet/jsonnet_base_transaction.h index 7208ae3..f45685d 100644 --- a/contrib/jsonnet/headers/jsonnet_base_transaction.h +++ b/contrib/jsonnet/jsonnet_base_transaction.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef JSNONNET_BASE_TRANSACTION_H_ -#define JSNONNET_BASE_TRANSACTION_H_ +#ifndef CONTRIB_JSNONNET_BASE_TRANSACTION_H_ +#define CONTRIB_JSNONNET_BASE_TRANSACTION_H_ #include "jsonnet_base_sandbox.h" // NOLINT(build/include) @@ -35,4 +35,4 @@ class JsonnetTransaction : public sapi::Transaction { absl::Status Main() override; }; -#endif // JSNONNET_BASE_TRANSACTION_H_ +#endif // CONTRIB_JSNONNET_BASE_TRANSACTION_H_ diff --git a/contrib/jsonnet/jsonnet_helper.h b/contrib/jsonnet/jsonnet_helper.h index f38ed74..c34d6e9 100644 --- a/contrib/jsonnet/jsonnet_helper.h +++ b/contrib/jsonnet/jsonnet_helper.h @@ -12,55 +12,52 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef JSONNET_HELPER_H_ -#define JSONNET_HELPER_H_ +#ifndef CONTRIB_JSONNET_HELPER_H_ +#define CONTRIB_JSONNET_HELPER_H_ extern "C" { -#include // NOLINT(build/include) +#include // NOLINT(build/include) #include // NOLINT(build/include) } #include "jsonnet/cmd/utils.h" // NOLINT(build/include) -extern "C" struct JsonnetVm* c_jsonnet_make(void); +extern "C" { +struct JsonnetVm* c_jsonnet_make(void); -extern "C" void c_jsonnet_destroy(struct JsonnetVm* vm); +void c_jsonnet_destroy(struct JsonnetVm* vm); -extern "C" char* c_jsonnet_evaluate_snippet(struct JsonnetVm* vm, - const char* filename, char* snippet, - int* error); +char* c_jsonnet_evaluate_snippet(struct JsonnetVm* vm, const char* filename, + char* snippet, int* error); -extern "C" char* c_jsonnet_evaluate_snippet_multi(struct JsonnetVm* vm, - const char* filename, - const char* snippet, - int* error); +char* c_jsonnet_evaluate_snippet_multi(struct JsonnetVm* vm, + const char* filename, + const char* snippet, int* error); -extern "C" char* c_jsonnet_evaluate_snippet_stream(struct JsonnetVm* vm, - const char* filename, - const char* snippet, - int* error); +char* c_jsonnet_evaluate_snippet_stream(struct JsonnetVm* vm, + const char* filename, + const char* snippet, int* error); -extern "C" char* c_read_input(bool filename_is_code, const char* filename); +char* c_read_input(bool filename_is_code, const char* filename); -extern "C" void c_free_input(char* input); +void c_free_input(char* input); -extern "C" bool c_write_output_file(const char* output, - const char* output_file); +bool c_write_output_file(const char* output, const char* output_file); -extern "C" char* c_jsonnet_realloc(struct JsonnetVm* vm, char* str, size_t sz); +char* c_jsonnet_realloc(struct JsonnetVm* vm, char* str, size_t sz); -extern "C" bool c_write_multi_output_files(char* output, char* output_dir, - bool show_output_file_names); +bool c_write_multi_output_files(char* output, char* output_dir, + bool show_output_file_names); bool write_multi_output_files(char* output, const std::string& output_dir, bool show_output_file_names); -extern "C" bool c_write_output_stream(char* output, char* output_file); +bool c_write_output_stream(char* output, char* output_file); bool write_output_stream(char* output, const std::string& output_file); -extern "C" char* c_jsonnet_fmt_snippet(struct JsonnetVm* vm, - const char* filename, - const char* snippet, int* error); +char* c_jsonnet_fmt_snippet(struct JsonnetVm* vm, const char* filename, + const char* snippet, int* error); +} -#endif // JSONNET_HELPER_H_ +#endif // CONTRIB_JSONNET_HELPER_H_ diff --git a/contrib/jsonnet/tests/jsonnet_test_helper.cc b/contrib/jsonnet/jsonnet_test_helper.cc similarity index 98% rename from contrib/jsonnet/tests/jsonnet_test_helper.cc rename to contrib/jsonnet/jsonnet_test_helper.cc index d5b3900..894ea99 100644 --- a/contrib/jsonnet/tests/jsonnet_test_helper.cc +++ b/contrib/jsonnet/jsonnet_test_helper.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "jsonnet_tests.h" // NOLINT(build/include) +#include "jsonnet_test_helper.h" // NOLINT(build/include) // Prepares what is needed to perform a test. void JsonnetTestHelper::TestSetUp() { diff --git a/contrib/jsonnet/tests/jsonnet_test_helper.h b/contrib/jsonnet/jsonnet_test_helper.h similarity index 94% rename from contrib/jsonnet/tests/jsonnet_test_helper.h rename to contrib/jsonnet/jsonnet_test_helper.h index 898249b..06da104 100644 --- a/contrib/jsonnet/tests/jsonnet_test_helper.h +++ b/contrib/jsonnet/jsonnet_test_helper.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef JSONNET_TESTS_H_ -#define JSONNET_TESTS_H_ +#ifndef CONTRIB_JSONNET_TESTS_H_ +#define CONTRIB_JSONNET_TESTS_H_ #include @@ -54,4 +54,4 @@ class JsonnetTestHelper { bool input_was_read_; }; -#endif // JSONNET_TESTS_H_ +#endif // CONTRIB_JSONNET_TESTS_H_ diff --git a/contrib/jsonnet/tests/jsonnet_tests.cc b/contrib/jsonnet/jsonnet_tests.cc similarity index 98% rename from contrib/jsonnet/tests/jsonnet_tests.cc rename to contrib/jsonnet/jsonnet_tests.cc index 56c168b..c317674 100644 --- a/contrib/jsonnet/tests/jsonnet_tests.cc +++ b/contrib/jsonnet/jsonnet_tests.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "jsonnet_tests.h" // NOLINT(build/include) +#include "jsonnet_test_helper.h" // NOLINT(build/include) namespace { diff --git a/contrib/jsonnet/tests/CMakeLists.txt b/contrib/jsonnet/tests/CMakeLists.txt deleted file mode 100644 index 9925b61..0000000 --- a/contrib/jsonnet/tests/CMakeLists.txt +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2020 Google LLC -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http:#www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# We need to prepare convenient directories so the tests will be able to access them -file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tests/tests_input) -file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tests/tests_output) -file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/tests/tests_expected_output) - -add_custom_target(test_preparation ALL - COMMAND cp ${PROJECT_SOURCE_DIR}/examples/jsonnet_codes/* ${PROJECT_BINARY_DIR}/tests/tests_input - COMMAND cp ${PROJECT_SOURCE_DIR}/examples/jsonnet_codes_expected_output/* ${PROJECT_BINARY_DIR}/tests/tests_expected_output -) - -add_executable(tests - jsonnet_test_helper.cc - jsonnet_test_helper.h - jsonnet_tests.cc -) - -target_include_directories(tests PUBLIC - ${PROJECT_SOURCE_DIR}/headers -) - -target_link_libraries(tests - jsonnet_sapi sapi::sapi - gtest gmock gtest_main -) - -gtest_discover_tests(tests)