forked from OSchip/llvm-project
[lldb] Clear all settings during a test's setUp
Global properties are shared between debugger instances and if a test doesn't clear changes in settings it made, this leads to side effects in other tests. Differential Revision: https://reviews.llvm.org/D75537
This commit is contained in:
parent
8ec7158571
commit
df90a15b1a
|
@ -687,6 +687,9 @@ class Base(unittest2.TestCase):
|
|||
@classmethod
|
||||
def setUpCommands(cls):
|
||||
commands = [
|
||||
# First of all, clear all settings to have clean state of global properties.
|
||||
"settings clear -all",
|
||||
|
||||
# Disable Spotlight lookup. The testsuite creates
|
||||
# different binaries with the same UUID, because they only
|
||||
# differ in the debug info, which is not being hashed.
|
||||
|
|
|
@ -1043,13 +1043,16 @@ protected:
|
|||
};
|
||||
|
||||
// CommandObjectSettingsClear
|
||||
#define LLDB_OPTIONS_settings_clear
|
||||
#include "CommandOptions.inc"
|
||||
|
||||
class CommandObjectSettingsClear : public CommandObjectParsed {
|
||||
public:
|
||||
CommandObjectSettingsClear(CommandInterpreter &interpreter)
|
||||
: CommandObjectParsed(
|
||||
interpreter, "settings clear",
|
||||
"Clear a debugger setting array, dictionary, or string.", nullptr) {
|
||||
"Clear a debugger setting array, dictionary, or string. "
|
||||
"If '-a' option is specified, it clears all settings.", nullptr) {
|
||||
CommandArgumentEntry arg;
|
||||
CommandArgumentData var_name_arg;
|
||||
|
||||
|
@ -1077,11 +1080,53 @@ public:
|
|||
request, nullptr);
|
||||
}
|
||||
|
||||
Options *GetOptions() override { return &m_options; }
|
||||
|
||||
class CommandOptions : public Options {
|
||||
public:
|
||||
CommandOptions() = default;
|
||||
|
||||
~CommandOptions() override = default;
|
||||
|
||||
Status SetOptionValue(uint32_t option_idx, llvm::StringRef option_arg,
|
||||
ExecutionContext *execution_context) override {
|
||||
const int short_option = m_getopt_table[option_idx].val;
|
||||
switch (short_option) {
|
||||
case 'a':
|
||||
m_clear_all = true;
|
||||
break;
|
||||
default:
|
||||
llvm_unreachable("Unimplemented option");
|
||||
}
|
||||
return Status();
|
||||
}
|
||||
|
||||
void OptionParsingStarting(ExecutionContext *execution_context) override {
|
||||
m_clear_all = false;
|
||||
}
|
||||
|
||||
llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
|
||||
return llvm::makeArrayRef(g_settings_clear_options);
|
||||
}
|
||||
|
||||
bool m_clear_all = false;
|
||||
};
|
||||
|
||||
protected:
|
||||
bool DoExecute(Args &command, CommandReturnObject &result) override {
|
||||
result.SetStatus(eReturnStatusSuccessFinishNoResult);
|
||||
const size_t argc = command.GetArgumentCount();
|
||||
|
||||
if (m_options.m_clear_all) {
|
||||
if (argc != 0) {
|
||||
result.AppendError("'settings clear --all' doesn't take any arguments");
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
return false;
|
||||
}
|
||||
GetDebugger().GetValueProperties()->Clear();
|
||||
return result.Succeeded();
|
||||
}
|
||||
|
||||
if (argc != 1) {
|
||||
result.AppendError("'settings clear' takes exactly one argument");
|
||||
result.SetStatus(eReturnStatusFailed);
|
||||
|
@ -1106,6 +1151,9 @@ protected:
|
|||
|
||||
return result.Succeeded();
|
||||
}
|
||||
|
||||
private:
|
||||
CommandOptions m_options;
|
||||
};
|
||||
|
||||
// CommandObjectMultiwordSettings
|
||||
|
|
|
@ -39,6 +39,11 @@ let Command = "settings read" in {
|
|||
Desc<"The file from which to read the settings.">;
|
||||
}
|
||||
|
||||
let Command = "settings clear" in {
|
||||
def setclear_all : Option<"all", "a">,
|
||||
Desc<"Clear all settings.">;
|
||||
}
|
||||
|
||||
let Command = "breakpoint list" in {
|
||||
// FIXME: We need to add an "internal" command, and then add this sort of
|
||||
// thing to it. But I need to see it for now, and don't want to wait.
|
||||
|
|
|
@ -520,6 +520,32 @@ class SettingsCommandTestCase(TestBase):
|
|||
self.expect("settings remove ''", error=True,
|
||||
substrs=["'settings remove' command requires a valid variable name"])
|
||||
|
||||
def test_settings_clear_all(self):
|
||||
# Change a dictionary.
|
||||
self.runCmd("settings set target.env-vars a=1 b=2 c=3")
|
||||
# Change an array.
|
||||
self.runCmd("settings set target.run-args a1 b2 c3")
|
||||
# Change a single boolean value.
|
||||
self.runCmd("settings set auto-confirm true")
|
||||
# Change a single integer value.
|
||||
self.runCmd("settings set tab-size 2")
|
||||
|
||||
# Clear everything.
|
||||
self.runCmd("settings clear --all")
|
||||
|
||||
# Check that settings have their default values after clearing.
|
||||
self.expect("settings show target.env-vars", patterns=['^target.env-vars \(dictionary of strings\) =\s*$'])
|
||||
self.expect("settings show target.run-args", patterns=['^target.run-args \(arguments\) =\s*$'])
|
||||
self.expect("settings show auto-confirm", substrs=["false"])
|
||||
self.expect("settings show tab-size", substrs=["4"])
|
||||
|
||||
# Check that the command fails if we combine '--all' option with any arguments.
|
||||
self.expect(
|
||||
"settings clear --all auto-confirm",
|
||||
COMMAND_FAILED_AS_EXPECTED,
|
||||
error=True,
|
||||
substrs=["'settings clear --all' doesn't take any arguments"])
|
||||
|
||||
def test_all_settings_exist(self):
|
||||
self.expect("settings show",
|
||||
substrs=["auto-confirm",
|
||||
|
|
Loading…
Reference in New Issue