www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13316] New: std.getopt: implicit help option breaks the next

https://issues.dlang.org/show_bug.cgi?id=13316

          Issue ID: 13316
           Summary: std.getopt: implicit help option breaks the next
                    argument
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: nilsbossung googlemail.com

---
cat > test1.d << code
import std.getopt;
void main()
{
    string[] args = ["program", "--help", "--", "something"];
    getopt(args, config.passThrough /* because of issue 13315 */);
    assert(args == ["program", "something"]);
}
code
dmd test1.d
./test1
---
core.exception.AssertError test.d(6): Assertion failure
---

---
cat > test2.d << code
import std.getopt;
void main()
{
    string[] args = ["program", "--help", "--"];
    getopt(args, config.passThrough /* because of issue 13315 */);
    assert(args == ["program"]);
}
code
dmd test2.d
./test2
---
core.exception.AssertError /home/nils/d/dmd/dmd2/linux/bin64/../../src/phobos/std/range.d(4153):
range is smaller than amount of items to pop
---

When issue 13315 is fixed, this should be tested, too:
---
cat > test3.d << code
import std.getopt;
void main()
{
    bool b;
    string[] args = ["program", "--help", "nonoption", "--option"];
    getopt(args, config.stopOnFirstNonOption, "option", &b);
    assert(args == ["program", "nonoption", "--option"]);
}
code
dmd test3.d
./test3
---

Going to add the fix for this to the pull request I opened for 13315:
https://github.com/D-Programming-Language/phobos/pull/2433

--
Aug 17 2014