Merge pull request #37 from joshbeck/master

Added support for reading file lists from stdin, correctly this time
This commit is contained in:
Kimmo Varis 2011-09-29 10:50:37 -07:00
commit 24ce170554
3 changed files with 27 additions and 4 deletions

View File

@ -45,11 +45,21 @@ static void AddFilesToList(const std::string& FileList, std::vector<std::string>
// xml is a bonus then, since we can easily extend it // xml is a bonus then, since we can easily extend it
// we need a good parser then -> suggestion : TinyXml // we need a good parser then -> suggestion : TinyXml
// drawback : creates a dependency // drawback : creates a dependency
std::ifstream Files(FileList.c_str()); std::istream *Files;
std::ifstream Infile;
if (FileList.compare("-") == 0) // read from stdin
{
Files = &std::cin;
}
else
{
Infile.open(FileList.c_str());
Files = &Infile;
}
if (Files) if (Files)
{ {
std::string FileName; std::string FileName;
while (std::getline(Files, FileName)) // next line while (std::getline(*Files, FileName)) // next line
{ {
if (!FileName.empty()) if (!FileName.empty())
{ {
@ -720,7 +730,8 @@ void CmdLineParser::PrintHelp()
" Used when certain messages should be displayed but\n" " Used when certain messages should be displayed but\n"
" should not cause a non-zero exitcode.\n" " should not cause a non-zero exitcode.\n"
" --file-list=<file> Specify the files to check in a text file. Add one\n" " --file-list=<file> Specify the files to check in a text file. Add one\n"
" filename per line.\n" " filename per line. When file is -, the file list will\n"
" be read from standard input.\n"
" -f, --force Force checking of all configurations in files that have\n" " -f, --force Force checking of all configurations in files that have\n"
" \"too many\" configurations.\n" " \"too many\" configurations.\n"
" -h, --help Print this help.\n" " -h, --help Print this help.\n"

View File

@ -225,7 +225,7 @@ Example: -DDEBUG=1 -D__cplusplus</para>
<varlistentry> <varlistentry>
<term><option>--file-list=&lt;file&gt;</option></term> <term><option>--file-list=&lt;file&gt;</option></term>
<listitem> <listitem>
<para>Specify the files to check in a text file. One filename per line.</para> <para>Specify the files to check in a text file. One filename per line. When file is -, the file list will be read from standard input.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -71,6 +71,7 @@ private:
TEST_CASE(exitcodeSuppressions); TEST_CASE(exitcodeSuppressions);
TEST_CASE(exitcodeSuppressionsNoFile); TEST_CASE(exitcodeSuppressionsNoFile);
TEST_CASE(fileList); // TODO: Create and test real file listing file TEST_CASE(fileList); // TODO: Create and test real file listing file
TEST_CASE(fileListStdin);
TEST_CASE(inlineSuppr); TEST_CASE(inlineSuppr);
TEST_CASE(jobs); TEST_CASE(jobs);
TEST_CASE(jobsMissingCount); TEST_CASE(jobsMissingCount);
@ -530,6 +531,17 @@ private:
CmdLineParser parser(&settings); CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv)); TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(4, argv));
} }
void fileListStdin()
{
// TODO: Give it some stdin to read from, fails because the list of
// files in stdin (_pathnames) is empty
REDIRECT;
const char *argv[] = {"cppcheck", "--file-list=-", "file.cpp"};
Settings settings;
CmdLineParser parser(&settings);
TODO_ASSERT_EQUALS(true, false, parser.ParseFromArgs(3, argv));
}
void inlineSuppr() void inlineSuppr()
{ {