Skip to content

Commit

Permalink
help msg tweaks and fix format (retrigger ci x2)
Browse files Browse the repository at this point in the history
  • Loading branch information
wisechengyi committed Mar 11, 2021
1 parent cf7f538 commit f8f5b4b
Show file tree
Hide file tree
Showing 2 changed files with 238 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ public static final class Options extends OptionsBase {
valueHelp = "<path>",
help =
"The location of the user .bazelrc file containing default values of "
+ "Bazel options. This option can also be specified multiple times.\n"
+ "Bazel options. "
+ "/dev/null indicates that all further `--bazelrc`s will be ignored, "
+ "This is useful to disable the search for a user rc file, "
+ "e.g. in release builds.\n"
+ "This option can also be specified multiple times.\n"
+ "E.g. with "
+ "`--bazelrc=x.rc --bazelrc=y.rc --bazelrc=/dev/null --bazelrc=z.rc`,\n"
+ " 1) x.rc and y.rc will be read.\n"
+ " 2) /dev/null indicates that all further `--bazelrc`s will be ignored, "
+ "so in this case z.rc will be ignored. This is useful "
+ "to disable the search for a user rc file, e.g. in release builds.\n"
+ " 1) x.rc and y.rc are read.\n"
+ " 2) z.rc is ignored due to the prior /dev/null.\n"
+ "If unspecified, Bazel uses the first .bazelrc file it finds in "
+ "the following two locations: the workspace directory, then the user's home "
+ "directory.\n"
Expand Down
280 changes: 231 additions & 49 deletions src/test/cpp/blaze_util_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,88 +234,270 @@ TEST_F(BlazeUtilTest, TestSearchUnaryCommandOptionWarnsAboutDuplicates) {
}
}

void assert_equal_vector_char_pointer(std::vector<std::string> expected, std::vector<std::string> actual) {
ASSERT_EQ(actual.size(), expected.size()) << "Vectors expected and actual are of unequal length";
void assert_equal_vector_char_pointer(std::vector<std::string> expected,
std::vector<std::string> actual) {
ASSERT_EQ(actual.size(), expected.size())
<< "Vectors expected and actual are of unequal length";

for (int i = 0; i < actual.size(); ++i) {
ASSERT_EQ(actual[i], expected[i]) << "Vectors expected and actual differ at index " << i;
ASSERT_EQ(actual[i], expected[i])
<< "Vectors expected and actual differ at index " << i;
}
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryForEmpty) {
assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({"bazel", "build", ":target"}, ""));
assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({
"bazel",
"build",
":target"
}, ""));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryFlagNotPresent) {
assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({"bazel", "build", ":target"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithEquals) {
assert_equal_vector_char_pointer({"value"}, GetAllUnaryOptionValues({"bazel", "--flag=value", "build", ":target"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithEquals2) {
assert_equal_vector_char_pointer({"value1", "value2"}, GetAllUnaryOptionValues({"bazel", "--flag=value1", "--flag=value2", "build", ":target"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithRepeatingFlag) {
assert_equal_vector_char_pointer({"--flag"}, GetAllUnaryOptionValues({"bazel", "--flag", "--flag", "value1", "build", ":target"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithRepeatingFlagOptionsOnly) {
assert_equal_vector_char_pointer({"--flag"}, GetAllUnaryOptionValues({"bazel", "--flag", "--flag", "value1"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithRepeatingFlagOptionsOnlyMulti) {
assert_equal_vector_char_pointer({"--flag", "value1"}, GetAllUnaryOptionValues({"bazel", "--flag", "--flag", "--flag", "value1"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithRepeatingFlagOptionsOnlyMultiWithEquals) {
assert_equal_vector_char_pointer({"--flag", "value1"}, GetAllUnaryOptionValues({"bazel", "--flag=--flag", "--flag", "value1"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithEquals3) {
assert_equal_vector_char_pointer({"value1", "value2", "value3"}, GetAllUnaryOptionValues({"bazel", "--flag=value1", "--flag=value2", "--flag=value3", "build", ":target"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithoutEquals) {
assert_equal_vector_char_pointer({"value"}, GetAllUnaryOptionValues({"bazel", "--flag", "value", "build", ":target"}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryStartupOptionWithoutEquals2) {
assert_equal_vector_char_pointer({"value1", "value2"}, GetAllUnaryOptionValues({"bazel", "--flag", "value1", "--flag", "value2", "build", ":target"}, "--flag"));
assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({
"bazel",
"build",
":target"
}, "--flag"));
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithEquals) {
assert_equal_vector_char_pointer({
"value"
},
GetAllUnaryOptionValues({
"bazel",
"--flag=value",
"build",
":target"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithEquals2) {
assert_equal_vector_char_pointer({
"value1",
"value2"
},
GetAllUnaryOptionValues({
"bazel",
"--flag=value1",
"--flag=value2",
"build",
":target"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithRepeatingFlag) {
assert_equal_vector_char_pointer({
"--flag"
},
GetAllUnaryOptionValues({
"bazel",
"--flag",
"--flag",
"value1",
"build",
":target"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithRepeatingFlagOptions) {
assert_equal_vector_char_pointer({
"--flag"
},
GetAllUnaryOptionValues({
"bazel",
"--flag",
"--flag",
"value1"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionValuesWithEquals) {
assert_equal_vector_char_pointer({
"--flag",
"value1"
},
GetAllUnaryOptionValues({
"bazel",
"--flag=--flag",
"--flag",
"value1"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithEquals3) {
assert_equal_vector_char_pointer({
"value1",
"value2",
"value3"
},
GetAllUnaryOptionValues({
"bazel",
"--flag=value1",
"--flag=value2",
"--flag=value3",
"build",
":target"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithoutEquals) {
assert_equal_vector_char_pointer({
"value"
},
GetAllUnaryOptionValues({
"bazel",
"--flag",
"value",
"build",
":target"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryOptionWithoutEquals2) {
assert_equal_vector_char_pointer({
"value1",
"value2"
},
GetAllUnaryOptionValues({
"bazel",
"--flag",
"value1",
"--flag",
"value2",
"build",
":target"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithEquals) {
assert_equal_vector_char_pointer({"value"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag", "value"}, "--flag"));
assert_equal_vector_char_pointer({
"value"
},
GetAllUnaryOptionValues({
"bazel",
"build",
":target",
"--flag",
"value"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithEquals2) {
assert_equal_vector_char_pointer({"value1","value2"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag", "value1", "--flag", "value2"}, "--flag"));
assert_equal_vector_char_pointer({
"value1",
"value2"
},
GetAllUnaryOptionValues({
"bazel",
"build",
":target",
"--flag",
"value1",
"--flag",
"value2"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithoutEquals) {
assert_equal_vector_char_pointer({"value"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag=value"}, "--flag"));
assert_equal_vector_char_pointer({
"value"
},
GetAllUnaryOptionValues({
"bazel",
"build",
":target",
"--flag=value"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithoutEquals2) {
assert_equal_vector_char_pointer({"value1", "value2"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag=value1", "--flag=value2"}, "--flag"));
assert_equal_vector_char_pointer({
"value1",
"value2"
},
GetAllUnaryOptionValues({
"bazel",
"build",
":target",
"--flag=value1",
"--flag=value2"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnarySkipsAfterDashDashWithEquals) {
assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--", "--flag", "value"}, "--flag"));
assert_equal_vector_char_pointer({},
GetAllUnaryOptionValues({
"bazel",
"build",
":target",
"--",
"--flag",
"value"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnarySkipsAfterDashDashWithoutEquals) {
assert_equal_vector_char_pointer({}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--", "--flag=value"}, "--flag"));
assert_equal_vector_char_pointer({},
GetAllUnaryOptionValues({
"bazel",
"build",
":target",
"--",
"--flag=value"
}, "--flag")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithIgnoreAfter) {
assert_equal_vector_char_pointer({"value1","/dev/null"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag", "value1", "--flag", "/dev/null", "--flag", "value3"}, "--flag", "/dev/null"));
assert_equal_vector_char_pointer({
"value1",
"/dev/null"
},
GetAllUnaryOptionValues({
"bazel",
"build",
":target",
"--flag",
"value1",
"--flag",
"/dev/null",
"--flag",
"value3"
}, "--flag", "/dev/null")
);
}

TEST_F(BlazeUtilTest, TestSearchAllUnaryCommandOptionWithIgnoreAfterDevNull) {
assert_equal_vector_char_pointer({"/dev/null"}, GetAllUnaryOptionValues({"bazel", "build", ":target", "--flag", "/dev/null", "--flag", "value2", "--flag", "value3"}, "--flag", "/dev/null"));
assert_equal_vector_char_pointer({
"/dev/null"
},
GetAllUnaryOptionValues({
"bazel",
"build",
":target",
"--flag",
"/dev/null",
"--flag",
"value2",
"--flag",
"value3"
}, "--flag", "/dev/null")
);
}

} // namespace blaze

0 comments on commit f8f5b4b

Please sign in to comment.