Jsonnet: Restructure tests

- Move and rename headers to main dir
- Fixup header guards
- Rename test main binary that conflicted with directory name `tests`
This commit is contained in:
Christian Blichmann 2022-01-27 13:59:14 +01:00
parent cb2aef7d26
commit dc0b14d871
9 changed files with 61 additions and 81 deletions

View File

@ -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()

View File

@ -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
)

View File

@ -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 <libgen.h>
#include <syscall.h>
@ -52,4 +52,4 @@ class JsonnetBaseSandbox : public JsonnetSandbox {
std::string out_file_;
};
#endif // JSONNET_BASE_SANDBOX_H_
#endif // CONTRIB_JSONNET_BASE_SANDBOX_H_

View File

@ -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_

View File

@ -12,8 +12,8 @@
// 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 <libjsonnet.h> // NOLINT(build/include)
@ -22,45 +22,42 @@ extern "C" {
#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,
char* c_jsonnet_evaluate_snippet_multi(struct JsonnetVm* vm,
const char* filename,
const char* snippet,
int* error);
const char* snippet, int* error);
extern "C" char* c_jsonnet_evaluate_snippet_stream(struct JsonnetVm* vm,
char* c_jsonnet_evaluate_snippet_stream(struct JsonnetVm* vm,
const char* filename,
const char* snippet,
int* error);
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 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,
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_

View File

@ -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() {

View File

@ -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 <unistd.h>
@ -54,4 +54,4 @@ class JsonnetTestHelper {
bool input_was_read_;
};
#endif // JSONNET_TESTS_H_
#endif // CONTRIB_JSONNET_TESTS_H_

View File

@ -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 {

View File

@ -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)