[Lldb-commits] [lldb] r232288 - Fix a bug related to arg escaping, and add unit tests.

Zachary Turner zturner at google.com
Sat Mar 14 16:39:43 PDT 2015


Author: zturner
Date: Sat Mar 14 18:39:42 2015
New Revision: 232288

URL: http://llvm.org/viewvc/llvm-project?rev=232288&view=rev
Log:
Fix a bug related to arg escaping, and add unit tests.

A recent refactor had introduced a bug where if you escaped a
character, the rest of the string would get processed incorrectly.

This patch fixes that bug and adds some unit tests for Args.

Added:
    lldb/trunk/unittests/Interpreter/
    lldb/trunk/unittests/Interpreter/CMakeLists.txt
    lldb/trunk/unittests/Interpreter/TestArgs.cpp
Modified:
    lldb/trunk/source/Interpreter/Args.cpp
    lldb/trunk/unittests/CMakeLists.txt

Modified: lldb/trunk/source/Interpreter/Args.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Interpreter/Args.cpp?rev=232288&r1=232287&r2=232288&view=diff
==============================================================================
--- lldb/trunk/source/Interpreter/Args.cpp (original)
+++ lldb/trunk/source/Interpreter/Args.cpp Sat Mar 14 18:39:42 2015
@@ -230,7 +230,7 @@ Args::ParseSingleArgument(llvm::StringRe
                 arg += '\\';
 
             arg += command.front();
-            command.drop_front();
+            command = command.drop_front();
 
             break;
 

Modified: lldb/trunk/unittests/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/CMakeLists.txt?rev=232288&r1=232287&r2=232288&view=diff
==============================================================================
--- lldb/trunk/unittests/CMakeLists.txt (original)
+++ lldb/trunk/unittests/CMakeLists.txt Sat Mar 14 18:39:42 2015
@@ -21,5 +21,6 @@ function(add_lldb_unittest test_name)
 endfunction()
 
 add_subdirectory(Host)
+add_subdirectory(Interpreter)
 add_subdirectory(Plugins)
 add_subdirectory(Utility)

Added: lldb/trunk/unittests/Interpreter/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/CMakeLists.txt?rev=232288&view=auto
==============================================================================
--- lldb/trunk/unittests/Interpreter/CMakeLists.txt (added)
+++ lldb/trunk/unittests/Interpreter/CMakeLists.txt Sat Mar 14 18:39:42 2015
@@ -0,0 +1,8 @@
+set(LLDB_USED_LIBS
+  lldbInterpreter
+  ${PYTHON_LIBRARY}
+  )
+
+add_lldb_unittest(InterpreterTests
+  TestArgs.cpp
+  )

Added: lldb/trunk/unittests/Interpreter/TestArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/TestArgs.cpp?rev=232288&view=auto
==============================================================================
--- lldb/trunk/unittests/Interpreter/TestArgs.cpp (added)
+++ lldb/trunk/unittests/Interpreter/TestArgs.cpp Sat Mar 14 18:39:42 2015
@@ -0,0 +1,70 @@
+//===-- ArgsTest.cpp --------------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "gtest/gtest.h"
+
+#include "lldb/Interpreter/Args.h"
+
+using namespace lldb_private;
+
+TEST(ArgsTest, TestSingleArg)
+{
+    Args args;
+    args.SetCommandString("arg");
+    EXPECT_EQ(1, args.GetArgumentCount());
+    EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg");
+}
+
+TEST(ArgsTest, TestSingleQuotedArgWithSpace)
+{
+    Args args;
+    args.SetCommandString("\"arg with space\"");
+    EXPECT_EQ(1, args.GetArgumentCount());
+    EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg with space");
+}
+
+TEST(ArgsTest, TestSingleArgWithQuotedSpace)
+{
+    Args args;
+    args.SetCommandString("arg\\ with\\ space");
+    EXPECT_EQ(1, args.GetArgumentCount());
+    EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg with space");
+}
+
+TEST(ArgsTest, TestMultipleArgs)
+{
+    Args args;
+    args.SetCommandString("this has multiple args");
+    EXPECT_EQ(4, args.GetArgumentCount());
+    EXPECT_STREQ(args.GetArgumentAtIndex(0), "this");
+    EXPECT_STREQ(args.GetArgumentAtIndex(1), "has");
+    EXPECT_STREQ(args.GetArgumentAtIndex(2), "multiple");
+    EXPECT_STREQ(args.GetArgumentAtIndex(3), "args");
+}
+
+TEST(ArgsTest, TestOverwriteArgs)
+{
+    Args args;
+    args.SetCommandString("this has multiple args");
+    EXPECT_EQ(4, args.GetArgumentCount());
+    args.SetCommandString("arg");
+    EXPECT_EQ(1, args.GetArgumentCount());
+    EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg");
+}
+
+TEST(ArgsTest, TestAppendArg)
+{
+    Args args;
+    args.SetCommandString("first_arg");
+    EXPECT_EQ(1, args.GetArgumentCount());
+    args.AppendArgument("second_arg");
+    EXPECT_EQ(2, args.GetArgumentCount());
+    EXPECT_STREQ(args.GetArgumentAtIndex(0), "first_arg");
+    EXPECT_STREQ(args.GetArgumentAtIndex(1), "second_arg");
+}





More information about the lldb-commits mailing list