From bfa6b2502b734a029bb1f893c1fa09eba0cafb86 Mon Sep 17 00:00:00 2001 From: Katarzyna Miernikiewicz Date: Mon, 28 Sep 2020 14:41:32 +0000 Subject: [PATCH] Google style added --- .../jsonnet/tests/jsonnet_tests.cc | 149 +++++++++--------- .../jsonnet/tests/jsonnet_tests_utils.cc | 24 +-- 2 files changed, 89 insertions(+), 84 deletions(-) diff --git a/oss-internship-2020/jsonnet/tests/jsonnet_tests.cc b/oss-internship-2020/jsonnet/tests/jsonnet_tests.cc index c0210c1..9431768 100644 --- a/oss-internship-2020/jsonnet/tests/jsonnet_tests.cc +++ b/oss-internship-2020/jsonnet/tests/jsonnet_tests.cc @@ -16,97 +16,98 @@ namespace { - class JsonnetTest : public JsonnetTestHelper, public testing::Test { - protected: - void SetUp() override { TestSetUp(); } - void TearDown() override { TestTearDown(); } - }; +class JsonnetTest : public JsonnetTestHelper, public testing::Test { + protected: + void SetUp() override { TestSetUp(); } + void TearDown() override { TestTearDown(); } +}; - // Basic test - TEST_F(JsonnetTest, SetUp_TearDown) { - ASSERT_FALSE(if_jsonnet_vm_was_used_); - ASSERT_FALSE(if_input_was_read_); - } +// Basic test +TEST_F(JsonnetTest, SetUp_TearDown) { + ASSERT_FALSE(if_jsonnet_vm_was_used_); + ASSERT_FALSE(if_input_was_read_); +} - // One file evaluation to one file - TEST_F(JsonnetTest, One_file_no_dependencies) { - constexpr char kInputFile[] = "arith.jsonnet"; - constexpr char kOutputFile[] = "arith_output"; - constexpr char kOutputToRead[] = "tests_output/arith_output"; - constexpr char kOutputToExpect[] = "tests_expected_output/arith.golden"; +// One file evaluation to one file +TEST_F(JsonnetTest, One_file_no_dependencies) { + constexpr char kInputFile[] = "arith.jsonnet"; + constexpr char kOutputFile[] = "arith_output"; + constexpr char kOutputToRead[] = "tests_output/arith_output"; + constexpr char kOutputToExpect[] = "tests_expected_output/arith.golden"; - Read_input(kInputFile); - Evaluate_jsonnet_code(kBase, true); - Write_output(kOutputFile, kBase); + Read_input(kInputFile); + Evaluate_jsonnet_code(kBase, true); + Write_output(kOutputFile, kBase); - std::string produced_output = Read_output(kOutputToRead); - std::string expected_output = Read_output(kOutputToExpect); + std::string produced_output = Read_output(kOutputToRead); + std::string expected_output = Read_output(kOutputToExpect); - ASSERT_STREQ(produced_output.c_str(), expected_output.c_str()); - } + ASSERT_STREQ(produced_output.c_str(), expected_output.c_str()); +} - // One file evaluating to one file, dependent on some other files - TEST_F(JsonnetTest, One_file_some_dependencies) { - constexpr char kInputFile[] = "negroni.jsonnet"; - constexpr char kOutputFile[] = "negroni_output"; - constexpr char kOutputToRead[] = "tests_output/negroni_output"; - constexpr char kOutputToExpect[] = "tests_expected_output/negroni.golden"; +// One file evaluating to one file, dependent on some other files +TEST_F(JsonnetTest, One_file_some_dependencies) { + constexpr char kInputFile[] = "negroni.jsonnet"; + constexpr char kOutputFile[] = "negroni_output"; + constexpr char kOutputToRead[] = "tests_output/negroni_output"; + constexpr char kOutputToExpect[] = "tests_expected_output/negroni.golden"; - Read_input(kInputFile); - Evaluate_jsonnet_code(kBase, true); - Write_output(kOutputFile, kBase); + Read_input(kInputFile); + Evaluate_jsonnet_code(kBase, true); + Write_output(kOutputFile, kBase); - const std::string produced_output = Read_output(kOutputToRead); - const std::string expected_output = Read_output(kOutputToExpect); + const std::string produced_output = Read_output(kOutputToRead); + const std::string expected_output = Read_output(kOutputToExpect); - ASSERT_STREQ(produced_output.c_str(), expected_output.c_str()); - } + ASSERT_STREQ(produced_output.c_str(), expected_output.c_str()); +} - // One file evaluating to two files - TEST_F(JsonnetTest, Multiple_files) { - constexpr char kInputFile[] = "multiple_files_example.jsonnet"; - constexpr char kOutputFile[] = ""; - constexpr char kOutputToRead1[] = "tests_output/first_file.json"; - constexpr char kOutputToRead2[] = "tests_output/second_file.json"; - constexpr char kOutputToExpect1[] = "tests_expected_output/first_file.json"; - constexpr char kOutputToExpect2[] = "tests_expected_output/second_file.json"; +// One file evaluating to two files +TEST_F(JsonnetTest, Multiple_files) { + constexpr char kInputFile[] = "multiple_files_example.jsonnet"; + constexpr char kOutputFile[] = ""; + constexpr char kOutputToRead1[] = "tests_output/first_file.json"; + constexpr char kOutputToRead2[] = "tests_output/second_file.json"; + constexpr char kOutputToExpect1[] = "tests_expected_output/first_file.json"; + constexpr char kOutputToExpect2[] = "tests_expected_output/second_file.json"; - Read_input(kInputFile); - Evaluate_jsonnet_code(kMultipleFiles, true); - Write_output(kOutputFile, kMultipleFiles); + Read_input(kInputFile); + Evaluate_jsonnet_code(kMultipleFiles, true); + Write_output(kOutputFile, kMultipleFiles); - const std::string produced_output_1 = Read_output(kOutputToRead1); - const std::string produced_output_2 = Read_output(kOutputToRead2); - const std::string expected_output_1 = Read_output(kOutputToExpect1); - const std::string expected_output_2 = Read_output(kOutputToExpect2); + const std::string produced_output_1 = Read_output(kOutputToRead1); + const std::string produced_output_2 = Read_output(kOutputToRead2); + const std::string expected_output_1 = Read_output(kOutputToExpect1); + const std::string expected_output_2 = Read_output(kOutputToExpect2); - ASSERT_STREQ(produced_output_1.c_str(), expected_output_1.c_str()); - ASSERT_STREQ(produced_output_2.c_str(), expected_output_2.c_str()); - } + ASSERT_STREQ(produced_output_1.c_str(), expected_output_1.c_str()); + ASSERT_STREQ(produced_output_2.c_str(), expected_output_2.c_str()); +} - // One file evaluating to yaml stream format - TEST_F(JsonnetTest, Yaml_stream) { - constexpr char kInputFile[] = "yaml_stream_example.jsonnet"; - constexpr char kOutputFile[] = "yaml_stream_example.yaml"; - constexpr char kOutputToRead[] = "tests_output/yaml_stream_example.yaml"; - constexpr char kOutputToExpect[] = "tests_expected_output/yaml_stream_example.yaml"; +// One file evaluating to yaml stream format +TEST_F(JsonnetTest, Yaml_stream) { + constexpr char kInputFile[] = "yaml_stream_example.jsonnet"; + constexpr char kOutputFile[] = "yaml_stream_example.yaml"; + constexpr char kOutputToRead[] = "tests_output/yaml_stream_example.yaml"; + constexpr char kOutputToExpect[] = + "tests_expected_output/yaml_stream_example.yaml"; - Read_input(kInputFile); - Evaluate_jsonnet_code(kYamlStream, true); - Write_output(kOutputFile, kYamlStream); + Read_input(kInputFile); + Evaluate_jsonnet_code(kYamlStream, true); + Write_output(kOutputFile, kYamlStream); - const std::string produced_output = Read_output(kOutputToRead); - const std::string expected_output = Read_output(kOutputToExpect); + const std::string produced_output = Read_output(kOutputToRead); + const std::string expected_output = Read_output(kOutputToExpect); - ASSERT_STREQ(produced_output.c_str(), expected_output.c_str()); - } + ASSERT_STREQ(produced_output.c_str(), expected_output.c_str()); +} - // One file depended on some other files not accessible by the sandbox - TEST_F(JsonnetTest, Bad_evaluation) { - constexpr char kInputFile[] = "imports.jsonnet"; +// One file depended on some other files not accessible by the sandbox +TEST_F(JsonnetTest, Bad_evaluation) { + constexpr char kInputFile[] = "imports.jsonnet"; - Read_input(kInputFile); - Evaluate_jsonnet_code(kBase, false); - } + Read_input(kInputFile); + Evaluate_jsonnet_code(kBase, false); +} -} //namespace +} // namespace diff --git a/oss-internship-2020/jsonnet/tests/jsonnet_tests_utils.cc b/oss-internship-2020/jsonnet/tests/jsonnet_tests_utils.cc index 48a2c17..b0f6ff5 100644 --- a/oss-internship-2020/jsonnet/tests/jsonnet_tests_utils.cc +++ b/oss-internship-2020/jsonnet/tests/jsonnet_tests_utils.cc @@ -21,15 +21,17 @@ void JsonnetTestHelper::TestSetUp() { int error = readlink("/proc/self/exe", buffer, 256); ASSERT_GE(error, 0); - std::pair parts_of_path = sandbox2::file::SplitPath(buffer); + std::pair parts_of_path = + sandbox2::file::SplitPath(buffer); absl::string_view binary_path = parts_of_path.first; - std::string input_path = sandbox2::file::JoinPath(binary_path, "tests_input", "dummy_input"); - std::string output_path = sandbox2::file::JoinPath(binary_path, "tests_output", "dummy_input"); + std::string input_path = + sandbox2::file::JoinPath(binary_path, "tests_input", "dummy_input"); + std::string output_path = + sandbox2::file::JoinPath(binary_path, "tests_output", "dummy_input"); // Set up sandbox and api. - sandbox_ = absl::make_unique(input_path, - output_path); + sandbox_ = absl::make_unique(input_path, output_path); ASSERT_THAT(sandbox_->Init(), sapi::IsOk()); api_ = absl::make_unique(sandbox_.get()); @@ -79,7 +81,7 @@ void JsonnetTestHelper::Evaluate_jsonnet_code(Evaluation type, SAPI_ASSERT_OK_AND_ASSIGN( output_ptr, api_->c_jsonnet_evaluate_snippet(vm_.get(), in_file_var.PtrBefore(), - input_.get(), error.PtrAfter())); + input_.get(), error.PtrAfter())); break; } @@ -118,8 +120,9 @@ void JsonnetTestHelper::Write_output(const char* filename_or_directory, switch (type) { case kBase: { - std::string out_file_in_sandboxee(std::string("/output/") + - basename(const_cast(&filename_or_directory[0]))); + std::string out_file_in_sandboxee( + std::string("/output/") + + basename(const_cast(&filename_or_directory[0]))); sapi::v::ConstCStr out_file_var(out_file_in_sandboxee.c_str()); SAPI_ASSERT_OK_AND_ASSIGN( @@ -137,8 +140,9 @@ void JsonnetTestHelper::Write_output(const char* filename_or_directory, } case kYamlStream: { - std::string out_file_in_sandboxee(std::string("/output/") + - basename(const_cast(&filename_or_directory[0]))); + std::string out_file_in_sandboxee( + std::string("/output/") + + basename(const_cast(&filename_or_directory[0]))); sapi::v::ConstCStr out_file_var(out_file_in_sandboxee.c_str()); SAPI_ASSERT_OK_AND_ASSIGN( success,