CommandLineParser: Replace global sout/serr streams with class members

- This removes the global variable and prevents stderr/stdout from being printed in tests
This commit is contained in:
Kamil Śliwak
2021-07-07 12:53:15 +02:00
parent ce11ebb687
commit 6c33fbcb6a
4 changed files with 58 additions and 40 deletions
+11 -29
View File
@@ -34,24 +34,16 @@ namespace po = boost::program_options;
namespace solidity::frontend
{
static bool g_hasOutput = false;
namespace
ostream& CommandLineParser::sout()
{
std::ostream& sout()
{
g_hasOutput = true;
return cout;
m_hasOutput = true;
return m_sout;
}
std::ostream& serr(bool _used = true)
ostream& CommandLineParser::serr()
{
if (_used)
g_hasOutput = true;
return cerr;
}
m_hasOutput = true;
return m_serr;
}
#define cout
@@ -233,8 +225,7 @@ static set<string> const g_metadataHashArgs
g_strNone
};
[[noreturn]]
static void printVersionAndExit()
void CommandLineParser::printVersionAndExit()
{
sout() <<
"solc, the solidity compiler commandline interface" <<
@@ -245,8 +236,7 @@ static void printVersionAndExit()
exit(EXIT_SUCCESS);
}
[[noreturn]]
static void printLicenseAndExit()
void CommandLineParser::printLicenseAndExit()
{
sout() << otherLicenses << endl;
// This is a static variable generated by cmake from LICENSE.txt
@@ -254,10 +244,8 @@ static void printLicenseAndExit()
exit(EXIT_SUCCESS);
}
namespace
{
bool checkMutuallyExclusive(boost::program_options::variables_map const& args, std::string const& _optionA, std::string const& _optionB)
bool CommandLineParser::checkMutuallyExclusive(boost::program_options::variables_map const& args, string const& _optionA, string const& _optionB)
{
if (args.count(_optionA) && args.count(_optionB))
{
@@ -268,8 +256,6 @@ bool checkMutuallyExclusive(boost::program_options::variables_map const& args, s
return true;
}
}
bool CompilerOutputs::operator==(CompilerOutputs const& _other) const noexcept
{
static_assert(
@@ -489,7 +475,7 @@ bool CommandLineParser::parseLibraryOption(string const& _input)
bool CommandLineParser::parse(int _argc, char const* const* _argv, bool interactiveTerminal)
{
g_hasOutput = false;
m_hasOutput = false;
// Declare the supported options.
po::options_description desc((R"(solc, the Solidity commandline compiler.
@@ -1186,11 +1172,6 @@ General Information)").c_str(),
return true;
}
bool CommandLineParser::hasOutput()
{
return g_hasOutput;
}
bool CommandLineParser::parseCombinedJsonOption()
{
if (!m_args.count(g_argCombinedJson))
@@ -1242,4 +1223,5 @@ string CommandLineParser::joinOptionNames(vector<string> const& _optionNames, st
_separator
);
}
} // namespace solidity::frontend