Fix REPL test parser nits

Follow-up to https://gerrit.lix.systems/c/lix/+/546

Change-Id: Ie603f01e5520329bf879e061cea9e3fba45213fd
This commit is contained in:
Rebecca Turner 2024-04-06 14:39:01 -07:00
parent b323340538
commit 4a49a497eb
4 changed files with 7 additions and 14 deletions

View file

@ -123,11 +123,6 @@ public:
{ {
runReplTestPath(nameBase, {}); runReplTestPath(nameBase, {});
} }
void runDebuggerTest(const std::string_view & nameBase)
{
runReplTestPath(nameBase, {"--debugger"});
}
}; };
TEST_F(ReplSessionTest, round_trip) TEST_F(ReplSessionTest, round_trip)

View file

@ -121,7 +121,7 @@ bool TestSession::readOutThen(ReadOutThenCallback cb)
bool TestSession::waitForPrompt() bool TestSession::waitForPrompt()
{ {
bool notEof = readOutThen([&](std::span<char> s) -> ReadOutThenCallbackResult { bool notEof = readOutThen([&](std::span<const char> s) -> ReadOutThenCallbackResult {
bool foundPrompt = false; bool foundPrompt = false;
for (auto ch : s) { for (auto ch : s) {
@ -147,7 +147,7 @@ bool TestSession::waitForPrompt()
void TestSession::wait() void TestSession::wait()
{ {
readOutThen([&](std::span<char> s) { readOutThen([&](std::span<const char> s) {
for (auto ch : s) { for (auto ch : s) {
eater.feed(ch, [&](char c) { eater.feed(ch, [&](char c) {
outputParser.feed(c); outputParser.feed(c);

View file

@ -76,7 +76,7 @@ private:
void wait(); void wait();
enum class ReadOutThenCallbackResult { Stop, Continue }; enum class ReadOutThenCallbackResult { Stop, Continue };
using ReadOutThenCallback = std::function<ReadOutThenCallbackResult(std::span<char>)>; using ReadOutThenCallback = std::function<ReadOutThenCallbackResult(std::span<const char>)>;
/** Reads some chunks of output, calling the callback provided for each /** Reads some chunks of output, calling the callback provided for each
* chunk and stopping if it returns Stop. * chunk and stopping if it returns Stop.
* *

View file

@ -35,7 +35,7 @@ struct Parser
: input(input) : input(input)
, rest(this->input) , rest(this->input)
, prompt(config.prompt) , prompt(config.prompt)
, indentString(std::string(config.indent, ' ')) , indentString(config.indent, ' ')
, lastWasOutput(false) , lastWasOutput(false)
, syntax{} , syntax{}
{ {
@ -260,12 +260,11 @@ struct Parser
std::vector<Node> newSyntax; std::vector<Node> newSyntax;
auto shouldStart = true; auto shouldStart = true;
for (auto it = syntax.begin(); it != syntax.end(); ++it) { for (auto & node : syntax) {
Node node = std::move(*it);
std::visit( std::visit(
overloaded{ overloaded{
[&](Args & e) { [&](Args & e) {
auto split = shell_split(std::string(e.text)); auto split = shell_split(e.text);
args.insert(args.end(), split.begin(), split.end()); args.insert(args.end(), split.begin(), split.end());
}, },
[&](ShouldStart & e) { shouldStart = e.shouldStart; }, [&](ShouldStart & e) { shouldStart = e.shouldStart; },
@ -293,8 +292,7 @@ auto tidySyntax(View syntax) -> std::vector<Node>
auto lastWasCommand = true; auto lastWasCommand = true;
std::vector<Node> newSyntax; std::vector<Node> newSyntax;
for (auto it = syntax.begin(); it != syntax.end(); ++it) { for (auto & node : syntax) {
Node node = *it;
// Only compare `Command` and `Output` nodes. // Only compare `Command` and `Output` nodes.
if (std::visit([&](auto && e) { return !e.shouldCompare(); }, node)) { if (std::visit([&](auto && e) { return !e.shouldCompare(); }, node)) {
continue; continue;