Boost C++ Libraries: Ticket #11825: Parsing command-line arguments on Windows https://svn.boost.org/trac10/ticket/11825 <p> (I originally posted to the mailing list, thread <a class="ext-link" href="http://lists.boost.org/boost-users/2015/11/85342.php"><span class="icon">​</span>Parsing command-line arguments on Windows</a>, but I suspect it is a bug, hence the ticket.) </p> <p> TL;TR: Boost.Test arguments parser is not handling Windows CLI patterns/rules correctly. </p> <p> 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.: <a class="ext-link" href="https://msdn.microsoft.com/en-us/library/17w5ykft.aspx"><span class="icon">​</span>https://msdn.microsoft.com/en-us/library/17w5ykft.aspx</a> </p> <p> Here is simple program to test those rules with 'boost::unit_test::framework::master_test_suite' machinery: </p> <pre class="wiki">///////// Boost.Test program /////////////////////////////////////// #define BOOST_TEST_MAIN #include &lt;boost/test/unit_test.hpp&gt; 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 &lt; argc; ++i) std::printf("%d: %s\n", i, argv[i]); } </pre><p> and the four rules tested: </p> <pre class="wiki">F:\test_boost\Debug&gt;test_boost.exe "abc" d e Running 1 test case... 0: test_boost.exe 1: abc 2: d 3: e F:\test_boost\Debug&gt;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&gt;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&gt;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 </pre><p> Results summary: Boost.Test gives different arguments in the runs, than presented in the MSDN article above. </p> <pre class="wiki">#2 (input: a\\b d"e f"g h) #4 (input: a\\\\"b c" d e) </pre><p> I can't see any caveats mentioned in the documentation <a href="http://www.boost.org/doc/libs/1_59_0/libs/test/doc/html/boost_test/tests_organization/test_suite/master_test_suite.html">http://www.boost.org/doc/libs/1_59_0/libs/test/doc/html/boost_test/tests_organization/test_suite/master_test_suite.html</a> </p> <hr /> <p> Just in case, here is the test confirming what is expected output on Windows for those rules/argument patterns: </p> <pre class="wiki">#include &lt;cstdio&gt; int main(int argc, char* argv[]) { for (int i = 0; i &lt; argc; ++i) std::printf("%d: %s\n", i, argv[i]); } </pre><p> and the four runs </p> <pre class="wiki">F:\test_cpp2015\Debug&gt;test_cpp2015.exe "abc" d e 0: test_cpp2015.exe 1: abc 2: d 3: e F:\test_cpp2015\Debug&gt;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&gt;test_cpp2015.exe a\\\"b c d 0: test_cpp2015.exe 1: a\"b 2: c 3: d F:\test_cpp2015\Debug&gt;test_cpp2015.exe a\\\\"b c" d e 0: test_cpp2015.exe 1: a\\b c 2: d 3: e </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11825 Trac 1.4.3 Raffi Enficiaud Wed, 02 Dec 2015 20:19:46 GMT <link>https://svn.boost.org/trac10/ticket/11825#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11825#comment:1</guid> <description> <p> Hi, </p> <p> 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)? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Mateusz Loskot</dc:creator> <pubDate>Wed, 09 Dec 2015 17:27:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/11825#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11825#comment:2</guid> <description> <p> Hi, </p> <p> 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). </p> <p> Thank you! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Mateusz Loskot</dc:creator> <pubDate>Wed, 09 Dec 2015 17:27:47 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/11825 https://svn.boost.org/trac10/ticket/11825 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost-test-ticket-11825-fixed.png</span> </li> </ul> <p> Parsing of the four sample argument sets works </p> Ticket Mateusz Loskot Wed, 09 Dec 2015 17:31:47 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/11825#comment:3 https://svn.boost.org/trac10/ticket/11825#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> Ticket Raffi Enficiaud Wed, 09 Dec 2015 20:01:18 GMT <link>https://svn.boost.org/trac10/ticket/11825#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11825#comment:4</guid> <description> <p> Thank you for your feedback! </p> </description> <category>Ticket</category> </item> </channel> </rss>