aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/test/cpp
diff options
context:
space:
mode:
authorGravatar ccalvarin <ccalvarin@google.com>2018-04-13 12:20:43 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-04-13 12:22:38 -0700
commit10d9155d6b1fad5c05c5872fb917cc77fbc61810 (patch)
tree7d540a0dfcf619165a8e34497d6495781c368f7f /src/test/cpp
parentb985f619755864acd1a6bde13372c808ac609d35 (diff)
Break out the SuccessfulIs(Un|Null)aryTest into a helper file.
RELNOTES: None. PiperOrigin-RevId: 192805836
Diffstat (limited to 'src/test/cpp')
-rw-r--r--src/test/cpp/BUILD12
-rw-r--r--src/test/cpp/startup_options_test.cc82
-rw-r--r--src/test/cpp/test_util.cc53
-rw-r--r--src/test/cpp/test_util.h29
4 files changed, 122 insertions, 54 deletions
diff --git a/src/test/cpp/BUILD b/src/test/cpp/BUILD
index 42f81129d1..782d1814b0 100644
--- a/src/test/cpp/BUILD
+++ b/src/test/cpp/BUILD
@@ -54,11 +54,23 @@ cc_test(
],
)
+cc_library(
+ name = "test_util",
+ testonly = 1,
+ srcs = ["test_util.cc"],
+ hdrs = ["test_util.h"],
+ deps = [
+ "//src/main/cpp:startup_options",
+ "@com_google_googletest//:gtest_main",
+ ],
+)
+
cc_test(
name = "startup_options_test",
size = "small",
srcs = ["startup_options_test.cc"],
deps = [
+ ":test_util",
"//src/main/cpp:blaze_util",
"//src/main/cpp:startup_options",
"//src/main/cpp:workspace_layout",
diff --git a/src/test/cpp/startup_options_test.cc b/src/test/cpp/startup_options_test.cc
index 9090a64e0f..a42180ba9d 100644
--- a/src/test/cpp/startup_options_test.cc
+++ b/src/test/cpp/startup_options_test.cc
@@ -18,6 +18,7 @@
#include "src/main/cpp/blaze_util_platform.h"
#include "src/main/cpp/workspace_layout.h"
+#include "src/test/cpp/test_util.h"
#include "googletest/include/gtest/gtest.h"
namespace blaze {
@@ -47,34 +48,6 @@ class StartupOptionsTest : public ::testing::Test {
startup_options_.reset(new StartupOptions(workspace_layout_.get()));
}
- void SuccessfulIsNullaryTest(const std::string& flag_name) const {
- EXPECT_TRUE(startup_options_->IsNullary("--" + flag_name));
- EXPECT_TRUE(startup_options_->IsNullary("--no" + flag_name));
-
- EXPECT_FALSE(startup_options_->IsNullary("--" + flag_name + "__invalid"));
-
- EXPECT_DEATH(startup_options_->IsNullary("--" + flag_name + "=foo"),
- ("In argument '--" + flag_name + "=foo': option "
- "'--" + flag_name + "' does not take a value").c_str());
-
- EXPECT_DEATH(startup_options_->IsNullary("--no" + flag_name + "=foo"),
- ("In argument '--no" + flag_name + "=foo': option "
- "'--no" + flag_name + "' does not take a value").c_str());
-
- EXPECT_FALSE(startup_options_->IsUnary("--" + flag_name));
- EXPECT_FALSE(startup_options_->IsUnary("--no" + flag_name));
- }
-
- void SuccessfulIsUnaryTest(const std::string& flag_name) const {
- EXPECT_TRUE(startup_options_->IsUnary("--" + flag_name));
- EXPECT_TRUE(startup_options_->IsUnary("--" + flag_name + "="));
- EXPECT_TRUE(startup_options_->IsUnary("--" + flag_name + "=foo"));
-
- EXPECT_FALSE(startup_options_->IsUnary("--" + flag_name + "__invalid"));
- EXPECT_FALSE(startup_options_->IsNullary("--" + flag_name));
- EXPECT_FALSE(startup_options_->IsNullary("--no" + flag_name));
- }
-
private:
std::unique_ptr<WorkspaceLayout> workspace_layout_;
@@ -126,32 +99,33 @@ TEST_F(StartupOptionsTest, ValidStartupFlagsTest) {
// IMPORTANT: Before modifying this test, please contact a Bazel core team
// member that knows the Google-internal procedure for adding/deprecating
// startup flags.
- SuccessfulIsNullaryTest("batch");
- SuccessfulIsNullaryTest("batch_cpu_scheduling");
- SuccessfulIsNullaryTest("block_for_lock");
- SuccessfulIsNullaryTest("client_debug");
- SuccessfulIsNullaryTest("deep_execroot");
- SuccessfulIsNullaryTest("experimental_oom_more_eagerly");
- SuccessfulIsNullaryTest("fatal_event_bus_exceptions");
- SuccessfulIsNullaryTest("host_jvm_debug");
- SuccessfulIsNullaryTest("master_bazelrc");
- SuccessfulIsNullaryTest("master_blazerc");
- SuccessfulIsNullaryTest("watchfs");
- SuccessfulIsNullaryTest("write_command_log");
- SuccessfulIsUnaryTest("bazelrc");
- SuccessfulIsUnaryTest("blazerc");
- SuccessfulIsUnaryTest("command_port");
- SuccessfulIsUnaryTest("connect_timeout_secs");
- SuccessfulIsUnaryTest("experimental_oom_more_eagerly_threshold");
- SuccessfulIsUnaryTest("host_javabase");
- SuccessfulIsUnaryTest("host_jvm_args");
- SuccessfulIsUnaryTest("host_jvm_profile");
- SuccessfulIsUnaryTest("invocation_policy");
- SuccessfulIsUnaryTest("io_nice_level");
- SuccessfulIsUnaryTest("install_base");
- SuccessfulIsUnaryTest("max_idle_secs");
- SuccessfulIsUnaryTest("output_base");
- SuccessfulIsUnaryTest("output_user_root");
+ const StartupOptions* options = startup_options_.get();
+ ExpectIsNullaryOption(options, "batch");
+ ExpectIsNullaryOption(options, "batch_cpu_scheduling");
+ ExpectIsNullaryOption(options, "block_for_lock");
+ ExpectIsNullaryOption(options, "client_debug");
+ ExpectIsNullaryOption(options, "deep_execroot");
+ ExpectIsNullaryOption(options, "experimental_oom_more_eagerly");
+ ExpectIsNullaryOption(options, "fatal_event_bus_exceptions");
+ ExpectIsNullaryOption(options, "host_jvm_debug");
+ ExpectIsNullaryOption(options, "master_bazelrc");
+ ExpectIsNullaryOption(options, "master_blazerc");
+ ExpectIsNullaryOption(options, "watchfs");
+ ExpectIsNullaryOption(options, "write_command_log");
+ ExpectIsUnaryOption(options, "bazelrc");
+ ExpectIsUnaryOption(options, "blazerc");
+ ExpectIsUnaryOption(options, "command_port");
+ ExpectIsUnaryOption(options, "connect_timeout_secs");
+ ExpectIsUnaryOption(options, "experimental_oom_more_eagerly_threshold");
+ ExpectIsUnaryOption(options, "host_javabase");
+ ExpectIsUnaryOption(options, "host_jvm_args");
+ ExpectIsUnaryOption(options, "host_jvm_profile");
+ ExpectIsUnaryOption(options, "invocation_policy");
+ ExpectIsUnaryOption(options, "io_nice_level");
+ ExpectIsUnaryOption(options, "install_base");
+ ExpectIsUnaryOption(options, "max_idle_secs");
+ ExpectIsUnaryOption(options, "output_base");
+ ExpectIsUnaryOption(options, "output_user_root");
}
TEST_F(StartupOptionsTest, ProcessSpaceSeparatedArgsTest) {
diff --git a/src/test/cpp/test_util.cc b/src/test/cpp/test_util.cc
new file mode 100644
index 0000000000..b50f74d79c
--- /dev/null
+++ b/src/test/cpp/test_util.cc
@@ -0,0 +1,53 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// 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 "src/test/cpp/test_util.h"
+
+#include "src/main/cpp/startup_options.h"
+#include "googletest/include/gtest/gtest.h"
+
+namespace blaze {
+
+void ExpectIsNullaryOption(const StartupOptions* options,
+ const std::string& flag_name) {
+ EXPECT_TRUE(options->IsNullary("--" + flag_name));
+ EXPECT_TRUE(options->IsNullary("--no" + flag_name));
+
+ EXPECT_FALSE(options->IsNullary("--" + flag_name + "__invalid"));
+
+ EXPECT_DEATH(options->IsNullary("--" + flag_name + "=foo"),
+ ("In argument '--" + flag_name + "=foo': option '--" +
+ flag_name + "' does not take a value")
+ .c_str());
+
+ EXPECT_DEATH(options->IsNullary("--no" + flag_name + "=foo"),
+ ("In argument '--no" + flag_name + "=foo': option '--no" +
+ flag_name + "' does not take a value")
+ .c_str());
+
+ EXPECT_FALSE(options->IsUnary("--" + flag_name));
+ EXPECT_FALSE(options->IsUnary("--no" + flag_name));
+}
+
+void ExpectIsUnaryOption(const StartupOptions* options,
+ const std::string& flag_name) {
+ EXPECT_TRUE(options->IsUnary("--" + flag_name));
+ EXPECT_TRUE(options->IsUnary("--" + flag_name + "="));
+ EXPECT_TRUE(options->IsUnary("--" + flag_name + "=foo"));
+
+ EXPECT_FALSE(options->IsUnary("--" + flag_name + "__invalid"));
+ EXPECT_FALSE(options->IsNullary("--" + flag_name));
+ EXPECT_FALSE(options->IsNullary("--no" + flag_name));
+}
+
+} // namespace blaze
diff --git a/src/test/cpp/test_util.h b/src/test/cpp/test_util.h
new file mode 100644
index 0000000000..e571f6b134
--- /dev/null
+++ b/src/test/cpp/test_util.h
@@ -0,0 +1,29 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// 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.
+#ifndef BAZEL_SRC_TEST_CPP_TEST_UTIL_H
+#define BAZEL_SRC_TEST_CPP_TEST_UTIL_H
+
+#include "src/main/cpp/startup_options.h"
+#include "googletest/include/gtest/gtest.h"
+
+namespace blaze {
+
+void ExpectIsNullaryOption(const StartupOptions* options,
+ const std::string& flag_name);
+void ExpectIsUnaryOption(const StartupOptions* options,
+ const std::string& flag_name);
+
+} // namespace blaze
+
+#endif // BAZEL_SRC_TEST_CPP_TEST_UTIL_H