mirror of
https://github.com/google/sandboxed-api.git
synced 2024-03-22 13:11:30 +08:00
dummy test works
This commit is contained in:
parent
4c20174f83
commit
6dcac6de05
|
@ -55,3 +55,5 @@ target_include_directories(jsonnet_sapi INTERFACE
|
|||
)
|
||||
|
||||
target_link_libraries(jsonnet_sapi PUBLIC jsonnet_helper)
|
||||
|
||||
add_subdirectory(tests)
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"caption": "The other one's name is -> And that is the other one.",
|
||||
"name": "This is the first file created by the multiple-files example code."
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"caption": "If it was the first one, variable name would hold what's in <first_name> variable.",
|
||||
"first_name": "This is the first file created by the multiple-files example code.",
|
||||
"name": "And that is the other one."
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
---
|
||||
{
|
||||
"age": "Just created!",
|
||||
"name": "First object's name."
|
||||
}
|
||||
---
|
||||
{
|
||||
"name": "Hi, my name is <second_object>.",
|
||||
"sibling": "First object's name."
|
||||
}
|
||||
...
|
48
oss-internship-2020/jsonnet/tests/CMakeLists.txt
Normal file
48
oss-internship-2020/jsonnet/tests/CMakeLists.txt
Normal file
|
@ -0,0 +1,48 @@
|
|||
# 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.
|
||||
|
||||
include(GoogleTest)
|
||||
|
||||
# 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/multiple_files_example.jsonnet ${PROJECT_BINARY_DIR}/tests/tests_input
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/examples/jsonnet_codes/yaml_stream_example.jsonnet ${PROJECT_BINARY_DIR}/tests/tests_input
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/jsonnet/examples/arith.jsonnet ${PROJECT_BINARY_DIR}/tests/tests_input
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/jsonnet/examples/negroni.jsonnet ${PROJECT_BINARY_DIR}/tests/tests_input
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/jsonnet/examples/utils.libsonnet ${PROJECT_BINARY_DIR}/tests/tests_input
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/examples/jsonnet_codes_expected_output/* ${PROJECT_BINARY_DIR}/tests/tests_expected_output
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/jsonnet/examples/arith.jsonnet.golden ${PROJECT_BINARY_DIR}/tests/tests_expected_output
|
||||
COMMAND cp ${PROJECT_SOURCE_DIR}/jsonnet/examples/negroni.jsonnet.golden ${PROJECT_BINARY_DIR}/tests/tests_expected_output
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${PROJECT_SOURCE_DIR}/examples
|
||||
)
|
||||
|
||||
add_executable(tests
|
||||
jsonnet_tests.h
|
||||
jsonnet_tests.cc
|
||||
jsonnet_tests_utils.cc
|
||||
)
|
||||
|
||||
target_link_libraries(tests
|
||||
jsonnet_sapi sapi::sapi
|
||||
gtest gmock gtest_main
|
||||
)
|
||||
|
||||
gtest_discover_tests(tests)
|
|
@ -19,3 +19,7 @@ class JsonnetTest : public JsonnetTestHelper, public testing::Test {
|
|||
void SetUp() override { TestSetUp(); }
|
||||
void TearDown() override { TestTearDown(); }
|
||||
};
|
||||
|
||||
TEST_F(JsonnetTest, DummyTest) {
|
||||
std::cout << "Stuff was done.\n";
|
||||
}
|
|
@ -17,6 +17,9 @@
|
|||
#include "jsonnet_sapi.sapi.h"
|
||||
#include "sandboxed_api/util/flag.h"
|
||||
#include "sandboxed_api/util/status_matchers.h"
|
||||
#include <filesystem>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
class JsonnetTestHelper {
|
||||
protected:
|
||||
|
@ -36,4 +39,7 @@ class JsonnetTestHelper {
|
|||
std::unique_ptr<sapi::v::RemotePtr> vm;
|
||||
|
||||
std::string input_filename_in_sandboxee;
|
||||
bool if_jsonnet_vm_was_used;
|
||||
bool if_input_was_read;
|
||||
|
||||
};
|
|
@ -14,10 +14,16 @@
|
|||
|
||||
#include "jsonnet_tests.h"
|
||||
|
||||
|
||||
// Prepare what is needed to perform a test.
|
||||
void JsonnetTestHelper::TestSetUp() {
|
||||
|
||||
// Get paths to where input and output is stored.
|
||||
std::filesystem::path input_path = std::filesystem::current_path() / "tests_input";
|
||||
std::filesystem::path output_path = std::filesystem::current_path() / "tests_output";
|
||||
|
||||
// Set up sandbox and api.
|
||||
sandbox = std::make_unique<JsonnetBaseSandbox>();
|
||||
sandbox = std::make_unique<JsonnetBaseSandbox>(input_path.string(), output_path.string());
|
||||
ASSERT_THAT(sandbox->Init(), sapi::IsOk());
|
||||
api = std::make_unique<JsonnetApi>(sandbox.get());
|
||||
|
||||
|
@ -25,15 +31,22 @@ void JsonnetTestHelper::TestSetUp() {
|
|||
SAPI_ASSERT_OK_AND_ASSIGN(JsonnetVm * vm_ptr, api->c_jsonnet_make());
|
||||
vm = std::make_unique<sapi::v::RemotePtr>(vm_ptr);
|
||||
|
||||
if_jsonnet_vm_was_used = false;
|
||||
if_input_was_read = false;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up after a test.
|
||||
void JsonnetTestHelper::TestTearDown() {
|
||||
SAPI_ASSERT_OK_AND_ASSIGN(char* result,
|
||||
api->c_jsonnet_realloc(vm.get(), output.get(), 0));
|
||||
if (if_jsonnet_vm_was_used) {
|
||||
SAPI_ASSERT_OK_AND_ASSIGN(char* result,
|
||||
api->c_jsonnet_realloc(vm.get(), output.get(), 0));
|
||||
}
|
||||
ASSERT_THAT(api->c_jsonnet_destroy(vm.get()), sapi::IsOk());
|
||||
ASSERT_THAT(api->c_free_input(input.get()), sapi::IsOk());
|
||||
if (if_input_was_read) {
|
||||
ASSERT_THAT(api->c_free_input(input.get()), sapi::IsOk());
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@ -117,7 +130,7 @@ void JsonnetTestHelper::Write_output(char* filename_or_directory,
|
|||
|
||||
case YAML_STREAM: {
|
||||
std::string out_file_in_sandboxee(std::string("/output/") +
|
||||
basename(&out_file[0]));
|
||||
basename(&filename_or_directory[0]));
|
||||
sapi::v::ConstCStr out_file_var(out_file_in_sandboxee.c_str());
|
||||
SAPI_ASSERT_OK_AND_ASSIGN(
|
||||
success,
|
Loading…
Reference in New Issue
Block a user