Bläddra i källkod

Added -- as command line argument terminator.

Branimir Karadžić 8 år sedan
förälder
incheckning
057f6b180c
2 ändrade filer med 10 tillägg och 3 borttagningar
  1. 1 1
      src/commandline.cpp
  2. 9 2
      tests/tokenizecmd_test.cpp

+ 1 - 1
src/commandline.cpp

@@ -262,7 +262,7 @@ namespace bx
 
 	const char* CommandLine::find(int32_t _skip, const char _short, const char* _long, int32_t _numParams) const
 	{
-		for (int32_t ii = 0; ii < m_argc; ++ii)
+		for (int32_t ii = 0; ii < m_argc && 0 != strCmp(m_argv[ii], "--"); ++ii)
 		{
 			const char* arg = m_argv[ii];
 			if ('-' == *arg)

+ 9 - 2
tests/tokenizecmd_test.cpp

@@ -15,12 +15,19 @@ TEST_CASE("commandLine", "")
 		"--long",
 		"--platform",
 		"x",
+		"--foo",
+		"--", // it should not parse arguments after argument terminator
+		"--bar",
 	};
 
 	bx::CommandLine cmdLine(BX_COUNTOF(args), args);
 
-	REQUIRE(cmdLine.hasArg("long") );
-	REQUIRE(cmdLine.hasArg('s') );
+	REQUIRE( cmdLine.hasArg("long") );
+	REQUIRE( cmdLine.hasArg('s') );
+
+	// test argument terminator
+	REQUIRE( cmdLine.hasArg("foo") );
+	REQUIRE(!cmdLine.hasArg("bar") );
 
 	// non-existing argument
 	REQUIRE(!cmdLine.hasArg('x') );