Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#11825 closed Bugs (fixed)

Parsing command-line arguments on Windows

Reported by: Mateusz Loskot Owned by: Gennadiy Rozental
Milestone: To Be Determined Component: test
Version: Boost 1.59.0 Severity: Problem
Keywords: Cc:

Description

(I originally posted to the mailing list, thread Parsing command-line arguments on Windows, but I suspect it is a bug, hence the ticket.)

TL;TR: Boost.Test arguments parser is not handling Windows CLI patterns/rules correctly.

Here is table with four example of command-line input on Windows and expected values of 'argv' elements, according to the rules when interpreting arguments, escape sequences etc.: https://msdn.microsoft.com/en-us/library/17w5ykft.aspx

Here is simple program to test those rules with 'boost::unit_test::framework::master_test_suite' machinery:

///////// Boost.Test program ///////////////////////////////////////
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(argv_parsing)
{
    auto argc = boost::unit_test::framework::master_test_suite().argc;
    auto argv = boost::unit_test::framework::master_test_suite().argv;
    for (int i = 0; i < argc; ++i) std::printf("%d: %s\n", i, argv[i]);
}

and the four rules tested:

F:\test_boost\Debug>test_boost.exe "abc" d e
Running 1 test case...
0: test_boost.exe
1: abc
2: d
3: e

F:\test_boost\Debug>test_boost.exe a\\b d"e f"g h
Running 1 test case...
0: test_boost.exe
1: a\\b
2: de
3: fg
4: h

F:\test_boost\Debug>test_boost.exe a\\\"b c d
Running 1 test case...
0: test_boost.exe
1: a\"b
2: c
3: d

F:\test_boost\Debug>test_boost.exe a\\\\"b c" d e
Running 1 test case...
0: test_boost.exe
1: a\\b
2: c
3: d
4: e

Results summary: Boost.Test gives different arguments in the runs, than presented in the MSDN article above.

#2 (input: a\\b d"e f"g h)
#4 (input: a\\\\"b c" d e)

I can't see any caveats mentioned in the documentation http://www.boost.org/doc/libs/1_59_0/libs/test/doc/html/boost_test/tests_organization/test_suite/master_test_suite.html


Just in case, here is the test confirming what is expected output on Windows for those rules/argument patterns:

#include <cstdio>
int main(int argc, char* argv[])
{
    for (int i = 0; i < argc; ++i) std::printf("%d: %s\n", i, argv[i]);
}

and the four runs

F:\test_cpp2015\Debug>test_cpp2015.exe "abc" d e
0: test_cpp2015.exe
1: abc
2: d
3: e

F:\test_cpp2015\Debug>test_cpp2015.exe a\\b d"e f"g h
0: test_cpp2015.exe
1: a\\b
2: de fg
3: h

F:\test_cpp2015\Debug>test_cpp2015.exe a\\\"b c d
0: test_cpp2015.exe
1: a\"b
2: c
3: d

F:\test_cpp2015\Debug>test_cpp2015.exe a\\\\"b c" d e
0: test_cpp2015.exe
1: a\\b c
2: d
3: e 

Attachments (1)

boost-test-ticket-11825-fixed.png (13.5 KB ) - added by Mateusz Loskot 7 years ago.
Parsing of the four sample argument sets works

Download all attachments as: .zip

Change History (5)

comment:1 by Raffi Enficiaud, 7 years ago

Hi,

There are a lot of bug fixes on the command line parsing scheduled for boost 1.60. Would you please try the master branch (should work on VC 2013/2015)?

comment:2 by Mateusz Loskot, 7 years ago

Hi,

I'm happy to confirmed the bug has been fixed in the current master. Boost.Test now parses the sample arguments above correctly (tested with VS2015).

Thank you!

by Mateusz Loskot, 7 years ago

Parsing of the four sample argument sets works

comment:3 by Mateusz Loskot, 7 years ago

Resolution: fixed
Status: newclosed

comment:4 by Raffi Enficiaud, 7 years ago

Thank you for your feedback!

Note: See TracTickets for help on using tickets.