Skip to content

Commit

Permalink
Fix a problem in command line option parsing.
Browse files Browse the repository at this point in the history
When a command line option ends with an equal sign, it's argument
is what follows that equal sign, even if it's empty.
  • Loading branch information
antiagainst committed Aug 11, 2015
1 parent 8c77641 commit 764b2b7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
18 changes: 9 additions & 9 deletions glslc/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,10 @@ void PrintHelp(std::ostream* out) {
<< std::endl;
}

// Parses the argument for the option at index in argv. On success, returns
// true and writes the parsed argument into option_argument. Returns false
// if any error occurs. option is the expected option at argv[index].
// After calling this function, index will be at the last command line
// argument consumed.
// Gets the option argument for the option at *index in argv in a way consistent
// with clang/gcc. On success, returns true and writes the parsed argument into
// *option_argument. Returns false if any errors occur. After calling this
// function, *index will the index of the last command line argument consumed.
bool GetOptionArgument(int argc, char** argv, int* index,
const std::string& option,
string_piece* option_argument) {
Expand All @@ -82,12 +81,13 @@ bool GetOptionArgument(int argc, char** argv, int* index,
*option_argument = arg.substr(option.size());
return true;
} else {
if (++(*index) >= argc) {
return false;
} else {
*option_argument = argv[*index];
if (option.back() == '=') {
*option_argument = "";
return true;
}
if (++(*index) >= argc) return false;
*option_argument = argv[*index];
return true;
}
}

Expand Down
24 changes: 24 additions & 0 deletions glslc/test/option_std.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,30 @@ def core_frag_shader_without_version():
return 'void main() { int temp = gl_SampleID; }'


@inside_glslc_testsuite('OptionStd')
class TestStdNoArg(expect.ErrorMessage):
"""Tests -std alone."""

glslc_args = ['-std']
expected_error = ["glslc: error: unknown argument: '-std'\n"]


@inside_glslc_testsuite('OptionStd')
class TestStdEqNoArg(expect.ErrorMessage):
"""Tests -std= with no argument."""

glslc_args = ['-std=']
expected_error = ["glslc: error: invalid value '' in '-std='\n"]


@inside_glslc_testsuite('OptionStd')
class TestStdEqSpaceArg(expect.ErrorMessage):
"""Tests -std= <version-profile>."""

shader = FileShader(core_frag_shader_without_version(), '.frag')
glslc_args = ['-c', '-std=', '450core', shader]
expected_error = ["glslc: error: invalid value '' in '-std='\n"]

@inside_glslc_testsuite('OptionStd')
class TestMissingVersionAndStd(expect.ErrorMessage):
"""Tests that missing both #version and -std results in errors."""
Expand Down

0 comments on commit 764b2b7

Please sign in to comment.