Merge pull request #2023 from odeke-em/fix-print-help-to-stdout

compiler/cli: PrintHelpText prints to stdout instead of stderr
pull/2859/head
Joshua Haberman 8 years ago committed by GitHub
commit 4842363ee6
  1. 6
      src/google/protobuf/compiler/command_line_interface.cc
  2. 20
      src/google/protobuf/compiler/command_line_interface_unittest.cc

@ -1452,7 +1452,7 @@ CommandLineInterface::InterpretArgument(const string& name,
void CommandLineInterface::PrintHelpText() {
// Sorry for indentation here; line wrapping would be uglier.
std::cerr <<
std::cout <<
"Usage: " << executable_name_ << " [OPTION] PROTO_FILES\n"
"Parse PROTO_FILES and generate output based on the options given:\n"
" -IPATH, --proto_path=PATH Specify the directory in which to search for\n"
@ -1499,7 +1499,7 @@ void CommandLineInterface::PrintHelpText() {
" occupied fields numbers.\n"
<< std::endl;
if (!plugin_prefix_.empty()) {
std::cerr <<
std::cout <<
" --plugin=EXECUTABLE Specifies a plugin executable to use.\n"
" Normally, protoc searches the PATH for\n"
" plugins, but you may specify additional\n"
@ -1515,7 +1515,7 @@ void CommandLineInterface::PrintHelpText() {
// FIXME(kenton): If the text is long enough it will wrap, which is ugly,
// but fixing this nicely (e.g. splitting on spaces) is probably more
// trouble than it's worth.
std::cerr << " " << iter->first << "=OUT_DIR "
std::cout << " " << iter->first << "=OUT_DIR "
<< string(19 - iter->first.size(), ' ') // Spaces for alignment.
<< iter->second.help_text << std::endl;
}

@ -156,6 +156,11 @@ class CommandLineInterfaceTest : public testing::Test {
// Checks that the captured stdout is the same as the expected_text.
void ExpectCapturedStdout(const string& expected_text);
// Checks that Run() returned zero and the stdout contains the given
// substring.
void ExpectCapturedStdoutSubstringWithZeroReturnCode(
const string& expected_substring);
// Returns true if ExpectErrorSubstring(expected_substring) would pass, but
// does not fail otherwise.
bool HasAlternateErrorSubstring(const string& expected_substring);
@ -488,6 +493,11 @@ void CommandLineInterfaceTest::ExpectCapturedStdout(
EXPECT_EQ(expected_text, captured_stdout_);
}
void CommandLineInterfaceTest::ExpectCapturedStdoutSubstringWithZeroReturnCode(
const string& expected_substring) {
EXPECT_EQ(0, return_code_);
EXPECT_PRED_FORMAT2(testing::IsSubstring, expected_substring, captured_stdout_);
}
void CommandLineInterfaceTest::ExpectFileContent(
const string& filename, const string& content) {
@ -1703,11 +1713,11 @@ TEST_F(CommandLineInterfaceTest, GeneratorPluginNotAllowed) {
TEST_F(CommandLineInterfaceTest, HelpText) {
Run("test_exec_name --help");
ExpectErrorSubstringWithZeroReturnCode("Usage: test_exec_name ");
ExpectErrorSubstringWithZeroReturnCode("--test_out=OUT_DIR");
ExpectErrorSubstringWithZeroReturnCode("Test output.");
ExpectErrorSubstringWithZeroReturnCode("--alt_out=OUT_DIR");
ExpectErrorSubstringWithZeroReturnCode("Alt output.");
ExpectCapturedStdoutSubstringWithZeroReturnCode("Usage: test_exec_name ");
ExpectCapturedStdoutSubstringWithZeroReturnCode("--test_out=OUT_DIR");
ExpectCapturedStdoutSubstringWithZeroReturnCode("Test output.");
ExpectCapturedStdoutSubstringWithZeroReturnCode("--alt_out=OUT_DIR");
ExpectCapturedStdoutSubstringWithZeroReturnCode("Alt output.");
}
TEST_F(CommandLineInterfaceTest, GccFormatErrors) {

Loading…
Cancel
Save