Skip to content

Add message for unknown cbmc option #910

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions regression/cbmc/bad_option/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
int main() {
return 0;
}
7 changes: 7 additions & 0 deletions regression/cbmc/bad_option/test.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.c
-foo
^EXIT=(64|1)$
^SIGNAL=0$
Unknown option: -foo
--
7 changes: 7 additions & 0 deletions regression/cbmc/bad_option/test_multiple.desc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CORE
main.c
--trace --foo --refine-strings
^EXIT=(64|1)$
^SIGNAL=0$
Unknown option: --foo
--
3 changes: 3 additions & 0 deletions src/util/cmdline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ bool cmdlinet::parse(int argc, const char **argv, const char *optstring)
}

if(optnr<0)
{
unknown_arg=argv[i];
return true;
}
options[optnr].isset=true;
if(options[optnr].hasval)
{
Expand Down
1 change: 1 addition & 0 deletions src/util/cmdline.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class cmdlinet

typedef std::vector<std::string> argst;
argst args;
std::string unknown_arg;

cmdlinet();
virtual ~cmdlinet();
Expand Down
9 changes: 9 additions & 0 deletions src/util/parse_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,20 @@ void parse_options_baset::usage_error()
help();
}

/// Print an error message mentioning the option that was not recognized when
/// parsing the command line.
void parse_options_baset::unknown_option_msg()
{
if(!cmdline.unknown_arg.empty())
std::cerr << "Unknown option: " << cmdline.unknown_arg << "\n";
}

int parse_options_baset::main()
{
if(parse_result)
{
usage_error();
unknown_option_msg();
return EX_USAGE;
}

Expand Down
1 change: 1 addition & 0 deletions src/util/parse_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class parse_options_baset
virtual ~parse_options_baset() { }

private:
void unknown_option_msg();
bool parse_result;
};

Expand Down