minor changes

This commit is contained in:
Katarzyna Miernikiewicz 2020-09-18 12:27:31 +00:00
parent 961441672f
commit bcdda46857
8 changed files with 64 additions and 18 deletions

View File

@ -55,7 +55,7 @@ int main(int argc, char* argv[]) {
// Process jsonnet data.
sapi::v::RemotePtr input_pointer(input.value());
sapi::v::Int error;
sapi::StatusOr<char *> output = api.c_jsonnet_evaluate_snippet(
sapi::StatusOr<char*> output = api.c_jsonnet_evaluate_snippet(
&vm_pointer, in_file_var.PtrBefore(), &input_pointer, error.PtrAfter());
CHECK(output.ok() && !error.GetValue())
<< "Jsonnet code evaluation failed: " << output.status() << " "

View File

@ -1,3 +1,17 @@
// 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.
// This is a poorly written jsonnet file. Given to the formatter executable will be changed into a canonical jsonnet file form.
local b = import "somefile.libsonnet"; # comment
local a = import "differentfile.libsonnet"; // another comment in different style

View File

@ -1,3 +1,17 @@
// 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.
// This is a jsonnet code which evaluates to mutliple output files.
{
"first_file.json": {

View File

@ -1,3 +1,17 @@
// 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.
// This is a jsonnet code which evaluates to json file, which can be interpreted as YAML stream.
local
first_object = {

View File

@ -51,7 +51,7 @@ class JsonnetSapiSandbox : public JsonnetSandbox {
std::string out_file_;
};
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);

View File

@ -25,7 +25,8 @@
class JsonnetSapiSandbox : public JsonnetSandbox {
public:
explicit JsonnetSapiSandbox(std::string in_file, std::string out_directory)
: in_file_(std::move(in_file)), out_directory_(std::move(out_directory)) {}
: in_file_(std::move(in_file)),
out_directory_(std::move(out_directory)) {}
// We need a slightly different policy than the default one
std::unique_ptr<sandbox2::Policy> ModifyPolicy(
@ -42,7 +43,8 @@ class JsonnetSapiSandbox : public JsonnetSandbox {
__NR_futex,
__NR_close,
})
.AddDirectoryAt(sandbox2::file::CleanPath(&out_directory_[0]), "/output",
.AddDirectoryAt(sandbox2::file::CleanPath(&out_directory_[0]),
"/output",
/*is_ro=*/false)
.AddDirectoryAt(dirname(&in_file_[0]), "/input", true)
.BuildOrDie();
@ -53,7 +55,7 @@ class JsonnetSapiSandbox : public JsonnetSandbox {
std::string out_directory_;
};
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
@ -111,7 +113,7 @@ int main(int argc, char* argv[]) {
<< success.value();
// Clean up.
sapi::StatusOr<char*> result =
sapi::StatusOr<char *> result =
api.c_jsonnet_realloc(&vm_pointer, &output_pointer, 0);
CHECK(result.ok()) << "JsonnetVm realloc failed: " << result.status();

View File

@ -17,7 +17,7 @@
#include "jsonnet_base_sandbox.h"
int main(int argc, char* argv[]) {
int main(int argc, char *argv[]) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
@ -70,14 +70,14 @@ int main(int argc, char* argv[]) {
sapi::v::RemotePtr output_pointer(output.value());
sapi::StatusOr<bool> success;
success = api.c_write_output_stream(&output_pointer,
out_file_var.PtrBefore());
success =
api.c_write_output_stream(&output_pointer, out_file_var.PtrBefore());
CHECK(success.ok() && success.value())
<< "Writing to output file failed " << success.status() << " "
<< success.value();
// Clean up.
sapi::StatusOr<char*> result =
sapi::StatusOr<char *> result =
api.c_jsonnet_realloc(&vm_pointer, &output_pointer, 0);
CHECK(result.ok()) << "JsonnetVm realloc failed: " << result.status();

View File

@ -12,17 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
#include <unistd.h>
#include <filesystem>
#include <fstream>
#include <iostream>
#include <streambuf>
#include <string>
#include "gtest/gtest.h"
#include "jsonnet_base_sandbox.h"
#include "jsonnet_sapi.sapi.h"
#include "sandboxed_api/util/flag.h"
#include "sandboxed_api/util/status_matchers.h"
#include <filesystem>
#include <iostream>
#include <fstream>
#include <streambuf>
#include <string>
#include <unistd.h>
class JsonnetTestHelper {
protected:
@ -32,7 +34,8 @@ class JsonnetTestHelper {
void TestTearDown();
void Read_input(char* filename);
void Evaluate_jsonnet_code(char* filename, Evaluation type, bool expected_correct);
void Evaluate_jsonnet_code(char* filename, Evaluation type,
bool expected_correct);
void Write_output(char* filename_or_directory, Evaluation type);
std::string Read_output(char* filename);
@ -45,5 +48,4 @@ class JsonnetTestHelper {
std::string input_filename_in_sandboxee;
bool if_jsonnet_vm_was_used;
bool if_input_was_read;
};