1 /* 2 This file is part of solidity. 3 4 solidity is free software: you can redistribute it and/or modify 5 it under the terms of the GNU General Public License as published by 6 the Free Software Foundation, either version 3 of the License, or 7 (at your option) any later version. 8 9 solidity is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 GNU General Public License for more details. 13 14 You should have received a copy of the GNU General Public License 15 along with solidity. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 // SPDX-License-Identifier: GPL-3.0 18 19 /// Utilities shared by multiple tests for code in solc/. 20 21 #include <solc/CommandLineParser.h> 22 23 #include <boost/test/unit_test.hpp> 24 25 #include <optional> 26 #include <string> 27 #include <vector> 28 29 BOOST_TEST_DONT_PRINT_LOG_VALUE(solidity::frontend::CommandLineOptions) BOOST_TEST_DONT_PRINT_LOG_VALUE(solidity::frontend::InputMode)30BOOST_TEST_DONT_PRINT_LOG_VALUE(solidity::frontend::InputMode) 31 32 namespace solidity::frontend::test 33 { 34 35 struct OptionsReaderAndMessages 36 { 37 bool success; 38 CommandLineOptions options; 39 FileReader reader; 40 std::optional<std::string> standardJsonInput; 41 std::string stdoutContent; 42 std::string stderrContent; 43 }; 44 45 std::vector<char const*> makeArgv(std::vector<std::string> const& _commandLine); 46 47 /// Runs only command-line parsing, without compilation, assembling or any other input processing. 48 /// Lets through any @a CommandLineErrors throw by the CLI. 49 /// Note: This uses the @a CommandLineInterface class and does not actually spawn a new process. 50 /// @param _commandLine Arguments in the form of strings that would be specified on the command-line. 51 /// You must specify the program name as the first item. 52 /// @param _standardInputContent Content that the CLI will be able to read from its standard input. 53 OptionsReaderAndMessages parseCommandLineAndReadInputFiles( 54 std::vector<std::string> const& _commandLine, 55 std::string const& _standardInputContent = "" 56 ); 57 58 /// Runs all stages of command-line interface processing, including error handling. 59 /// Never throws @a CommandLineError - validation errors are included in the returned stderr content. 60 /// Note: This uses the @a CommandLineInterface class and does not actually spawn a new process. 61 /// @param _commandLine Arguments in the form of strings that would be specified on the command-line. 62 /// You must specify the program name as the first item. 63 /// @param _standardInputContent Content that the CLI will be able to read from its standard input. 64 OptionsReaderAndMessages runCLI( 65 std::vector<std::string> const& _commandLine, 66 std::string const& _standardInputContent = "" 67 ); 68 69 std::string stripPreReleaseWarning(std::string const& _stderrContent); 70 71 } // namespace solidity::frontend::test 72