[lldb][NFC] Fix all formatting errors in .cpp file headers
Summary:
A *.cpp file header in LLDB (and in LLDB) should like this:
```
//===-- TestUtilities.cpp -------------------------------------------------===//
```
However in LLDB most of our source files have arbitrary changes to this format and
these changes are spreading through LLDB as folks usually just use the existing
source files as templates for their new files (most notably the unnecessary
editor language indicator `-*- C++ -*-` is spreading and in every review
someone is pointing out that this is wrong, resulting in people pointing out that this
is done in the same way in other files).
This patch removes most of these inconsistencies including the editor language indicators,
all the different missing/additional '-' characters, files that center the file name, missing
trailing `===//` (mostly caused by clang-format breaking the line).
Reviewers: aprantl, espindola, jfb, shafik, JDevlieghere
Reviewed By: JDevlieghere
Subscribers: dexonsmith, wuzish, emaste, sdardis, nemanjai, kbarton, MaskRay, atanasyan, arphaman, jfb, abidh, jsji, JDevlieghere, usaxena95, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D73258
2020-01-24 15:23:27 +08:00
|
|
|
//===-- ArgsTest.cpp ------------------------------------------------------===//
|
2015-03-15 07:39:42 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2015-03-15 07:39:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2018-04-18 02:53:35 +08:00
|
|
|
#include "lldb/Utility/Args.h"
|
2017-12-11 22:22:30 +08:00
|
|
|
#include "lldb/Utility/StringList.h"
|
2015-03-15 07:39:42 +08:00
|
|
|
|
2016-09-23 00:00:01 +08:00
|
|
|
#include <limits>
|
|
|
|
#include <sstream>
|
|
|
|
|
2015-03-15 07:39:42 +08:00
|
|
|
using namespace lldb_private;
|
|
|
|
|
|
|
|
TEST(ArgsTest, TestSingleArg) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("arg");
|
2015-03-17 11:32:21 +08:00
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
2015-03-15 07:39:42 +08:00
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, TestSingleQuotedArgWithSpace) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("\"arg with space\"");
|
2015-03-17 11:32:21 +08:00
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
2015-03-15 07:39:42 +08:00
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg with space");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, TestSingleArgWithQuotedSpace) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("arg\\ with\\ space");
|
2015-03-17 11:32:21 +08:00
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
2015-03-15 07:39:42 +08:00
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg with space");
|
|
|
|
}
|
|
|
|
|
2019-09-06 16:39:53 +08:00
|
|
|
TEST(ArgsTest, TestTrailingBackslash) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("arg\\");
|
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg\\");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, TestQuotedTrailingBackslash) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("\"arg\\");
|
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg\\");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, TestUnknownEscape) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("arg\\y");
|
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg\\y");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, TestQuotedUnknownEscape) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("\"arg\\y");
|
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg\\y");
|
|
|
|
}
|
|
|
|
|
2015-03-15 07:39:42 +08:00
|
|
|
TEST(ArgsTest, TestMultipleArgs) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("this has multiple args");
|
2015-03-17 11:32:21 +08:00
|
|
|
EXPECT_EQ(4u, args.GetArgumentCount());
|
2015-03-15 07:39:42 +08:00
|
|
|
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");
|
2015-03-17 11:32:21 +08:00
|
|
|
EXPECT_EQ(4u, args.GetArgumentCount());
|
2015-03-15 07:39:42 +08:00
|
|
|
args.SetCommandString("arg");
|
2015-03-17 11:32:21 +08:00
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
2015-03-15 07:39:42 +08:00
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "arg");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, TestAppendArg) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("first_arg");
|
2015-03-17 11:32:21 +08:00
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
2016-09-20 01:54:06 +08:00
|
|
|
args.AppendArgument(llvm::StringRef("second_arg"));
|
2015-03-17 11:32:21 +08:00
|
|
|
EXPECT_EQ(2u, args.GetArgumentCount());
|
2015-03-15 07:39:42 +08:00
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "first_arg");
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(1), "second_arg");
|
|
|
|
}
|
2016-09-17 03:09:12 +08:00
|
|
|
|
2016-10-04 06:51:09 +08:00
|
|
|
TEST(ArgsTest, TestInsertArg) {
|
|
|
|
Args args;
|
|
|
|
args.AppendArgument("1");
|
|
|
|
args.AppendArgument("2");
|
|
|
|
args.AppendArgument("3");
|
|
|
|
args.InsertArgumentAtIndex(1, "1.5");
|
|
|
|
args.InsertArgumentAtIndex(4, "3.5");
|
|
|
|
|
|
|
|
ASSERT_EQ(5u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ("1", args.GetArgumentAtIndex(0));
|
|
|
|
EXPECT_STREQ("1.5", args.GetArgumentAtIndex(1));
|
|
|
|
EXPECT_STREQ("2", args.GetArgumentAtIndex(2));
|
|
|
|
EXPECT_STREQ("3", args.GetArgumentAtIndex(3));
|
|
|
|
EXPECT_STREQ("3.5", args.GetArgumentAtIndex(4));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, TestArgv) {
|
|
|
|
Args args;
|
|
|
|
EXPECT_EQ(nullptr, args.GetArgumentVector());
|
|
|
|
|
|
|
|
args.AppendArgument("1");
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[0]);
|
|
|
|
EXPECT_EQ(nullptr, args.GetArgumentVector()[1]);
|
|
|
|
|
|
|
|
args.AppendArgument("2");
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[0]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[1]);
|
|
|
|
EXPECT_EQ(nullptr, args.GetArgumentVector()[2]);
|
|
|
|
|
|
|
|
args.AppendArgument("3");
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[0]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[1]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[2]);
|
|
|
|
EXPECT_EQ(nullptr, args.GetArgumentVector()[3]);
|
|
|
|
|
|
|
|
args.InsertArgumentAtIndex(1, "1.5");
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[0]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[1]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[2]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[3]);
|
|
|
|
EXPECT_EQ(nullptr, args.GetArgumentVector()[4]);
|
|
|
|
|
|
|
|
args.InsertArgumentAtIndex(4, "3.5");
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[0]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[1]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[2]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[3]);
|
|
|
|
EXPECT_NE(nullptr, args.GetArgumentVector()[4]);
|
|
|
|
EXPECT_EQ(nullptr, args.GetArgumentVector()[5]);
|
|
|
|
}
|
|
|
|
|
2017-12-11 22:22:30 +08:00
|
|
|
TEST(ArgsTest, StringListConstructor) {
|
|
|
|
StringList list;
|
2018-04-18 02:53:35 +08:00
|
|
|
list << "foo"
|
|
|
|
<< "bar"
|
|
|
|
<< "baz";
|
2017-12-11 22:22:30 +08:00
|
|
|
Args args(list);
|
|
|
|
ASSERT_EQ(3u, args.GetArgumentCount());
|
2019-09-13 19:26:48 +08:00
|
|
|
EXPECT_EQ("foo", args[0].ref());
|
|
|
|
EXPECT_EQ("bar", args[1].ref());
|
|
|
|
EXPECT_EQ("baz", args[2].ref());
|
2017-12-11 22:22:30 +08:00
|
|
|
}
|
|
|
|
|
2016-10-04 06:51:09 +08:00
|
|
|
TEST(ArgsTest, GetQuotedCommandString) {
|
|
|
|
Args args;
|
|
|
|
const char *str = "process launch -o stdout.txt -- \"a b c\"";
|
|
|
|
args.SetCommandString(str);
|
|
|
|
|
|
|
|
std::string stdstr;
|
|
|
|
ASSERT_TRUE(args.GetQuotedCommandString(stdstr));
|
|
|
|
EXPECT_EQ(str, stdstr);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, BareSingleQuote) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("a\\'b");
|
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
|
|
|
|
|
|
|
EXPECT_STREQ("a'b", args.GetArgumentAtIndex(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, DoubleQuotedItem) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("\"a b c\"");
|
|
|
|
EXPECT_EQ(1u, args.GetArgumentCount());
|
|
|
|
|
|
|
|
EXPECT_STREQ("a b c", args.GetArgumentAtIndex(0));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, AppendArguments) {
|
|
|
|
Args args;
|
|
|
|
const char *argv[] = {"1", "2", nullptr};
|
|
|
|
const char *argv2[] = {"3", "4", nullptr};
|
|
|
|
|
|
|
|
args.AppendArguments(argv);
|
|
|
|
ASSERT_EQ(2u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ("1", args.GetArgumentVector()[0]);
|
|
|
|
EXPECT_STREQ("2", args.GetArgumentVector()[1]);
|
|
|
|
EXPECT_EQ(nullptr, args.GetArgumentVector()[2]);
|
|
|
|
EXPECT_STREQ("1", args.GetArgumentAtIndex(0));
|
|
|
|
EXPECT_STREQ("2", args.GetArgumentAtIndex(1));
|
|
|
|
|
|
|
|
args.AppendArguments(argv2);
|
|
|
|
ASSERT_EQ(4u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ("1", args.GetArgumentVector()[0]);
|
|
|
|
EXPECT_STREQ("2", args.GetArgumentVector()[1]);
|
|
|
|
EXPECT_STREQ("3", args.GetArgumentVector()[2]);
|
|
|
|
EXPECT_STREQ("4", args.GetArgumentVector()[3]);
|
|
|
|
EXPECT_EQ(nullptr, args.GetArgumentVector()[4]);
|
|
|
|
EXPECT_STREQ("1", args.GetArgumentAtIndex(0));
|
|
|
|
EXPECT_STREQ("2", args.GetArgumentAtIndex(1));
|
|
|
|
EXPECT_STREQ("3", args.GetArgumentAtIndex(2));
|
|
|
|
EXPECT_STREQ("4", args.GetArgumentAtIndex(3));
|
|
|
|
}
|
|
|
|
|
2017-03-01 18:08:40 +08:00
|
|
|
TEST(ArgsTest, GetArgumentArrayRef) {
|
|
|
|
Args args("foo bar");
|
|
|
|
auto ref = args.GetArgumentArrayRef();
|
|
|
|
ASSERT_EQ(2u, ref.size());
|
|
|
|
EXPECT_STREQ("foo", ref[0]);
|
|
|
|
EXPECT_STREQ("bar", ref[1]);
|
|
|
|
}
|
2019-03-26 01:27:14 +08:00
|
|
|
|
|
|
|
TEST(ArgsTest, EscapeLLDBCommandArgument) {
|
|
|
|
const std::string foo = "foo'";
|
|
|
|
EXPECT_EQ("foo\\'", Args::EscapeLLDBCommandArgument(foo, '\0'));
|
|
|
|
EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '\''));
|
|
|
|
EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '`'));
|
|
|
|
EXPECT_EQ("foo'", Args::EscapeLLDBCommandArgument(foo, '"'));
|
|
|
|
|
|
|
|
const std::string bar = "bar\"";
|
|
|
|
EXPECT_EQ("bar\\\"", Args::EscapeLLDBCommandArgument(bar, '\0'));
|
|
|
|
EXPECT_EQ("bar\"", Args::EscapeLLDBCommandArgument(bar, '\''));
|
|
|
|
EXPECT_EQ("bar\"", Args::EscapeLLDBCommandArgument(bar, '`'));
|
|
|
|
EXPECT_EQ("bar\\\"", Args::EscapeLLDBCommandArgument(bar, '"'));
|
|
|
|
|
|
|
|
const std::string baz = "baz`";
|
|
|
|
EXPECT_EQ("baz\\`", Args::EscapeLLDBCommandArgument(baz, '\0'));
|
|
|
|
EXPECT_EQ("baz`", Args::EscapeLLDBCommandArgument(baz, '\''));
|
|
|
|
EXPECT_EQ("baz`", Args::EscapeLLDBCommandArgument(baz, '`'));
|
|
|
|
EXPECT_EQ("baz\\`", Args::EscapeLLDBCommandArgument(baz, '"'));
|
|
|
|
|
|
|
|
const std::string quux = "quux\t";
|
|
|
|
EXPECT_EQ("quux\\\t", Args::EscapeLLDBCommandArgument(quux, '\0'));
|
|
|
|
EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '\''));
|
|
|
|
EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '`'));
|
|
|
|
EXPECT_EQ("quux\t", Args::EscapeLLDBCommandArgument(quux, '"'));
|
|
|
|
}
|
2019-09-06 16:39:53 +08:00
|
|
|
|
|
|
|
TEST(ArgsTest, ReplaceArgumentAtIndexShort) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("foo ba b");
|
|
|
|
args.ReplaceArgumentAtIndex(0, "f");
|
|
|
|
EXPECT_EQ(3u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "f");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, ReplaceArgumentAtIndexEqual) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("foo ba b");
|
|
|
|
args.ReplaceArgumentAtIndex(0, "bar");
|
|
|
|
EXPECT_EQ(3u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "bar");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, ReplaceArgumentAtIndexLonger) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("foo ba b");
|
|
|
|
args.ReplaceArgumentAtIndex(0, "baar");
|
|
|
|
EXPECT_EQ(3u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(0), "baar");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, ReplaceArgumentAtIndexOutOfRange) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("foo ba b");
|
|
|
|
args.ReplaceArgumentAtIndex(3, "baar");
|
|
|
|
EXPECT_EQ(3u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(2), "b");
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ArgsTest, ReplaceArgumentAtIndexFarOutOfRange) {
|
|
|
|
Args args;
|
|
|
|
args.SetCommandString("foo ba b");
|
|
|
|
args.ReplaceArgumentAtIndex(4, "baar");
|
|
|
|
EXPECT_EQ(3u, args.GetArgumentCount());
|
|
|
|
EXPECT_STREQ(args.GetArgumentAtIndex(2), "b");
|
|
|
|
}
|