aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/repl_characterization/test-session.hh
diff options
context:
space:
mode:
authorRebecca Turner <rbt@sent.as>2024-03-22 16:45:05 -0700
committerRebecca Turner <rbt@sent.as>2024-04-05 13:14:21 -0700
commitee423f391d33246801de86c73330c8442df09dc8 (patch)
treeb2be1785079e942098925f414d33848069779281 /tests/functional/repl_characterization/test-session.hh
parent83d720b7304f6479f48dca8f3062e966f359e9b4 (diff)
Rewrite REPL test parser
- Use a recursive descent parser so that it's easy to extend. - Add `@args` to enable customizing command-line arguments - Add `@should-start` to enable `nix repl` tests that error before entering the REPL - Make sure to read all stdout output before comparing. This catches some extra output we were tossing out before! Change-Id: I5522555df4c313024ab15cd10f9f04e7293bda3a
Diffstat (limited to 'tests/functional/repl_characterization/test-session.hh')
-rw-r--r--tests/functional/repl_characterization/test-session.hh22
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/functional/repl_characterization/test-session.hh b/tests/functional/repl_characterization/test-session.hh
index 19636640b..2552542fb 100644
--- a/tests/functional/repl_characterization/test-session.hh
+++ b/tests/functional/repl_characterization/test-session.hh
@@ -1,7 +1,9 @@
#pragma once
///@file
+#include <functional>
#include <sched.h>
+#include <span>
#include <string>
#include "util.hh"
@@ -22,8 +24,7 @@ struct RunningProcess
class ReplOutputParser
{
public:
- ReplOutputParser(std::string prompt)
- : prompt(prompt)
+ ReplOutputParser(std::string prompt) : prompt(prompt)
{
assert(!prompt.empty());
}
@@ -60,10 +61,27 @@ struct TestSession
{
}
+ /** Waits for the prompt and then returns if a prompt was found */
bool waitForPrompt();
+ /** Feeds a line of input into the command */
void runCommand(std::string command);
+ /** Closes the session, closing standard input and waiting for standard
+ * output to close, capturing any remaining output. */
void close();
+
+private:
+ /** Waits until the command closes its output */
+ void wait();
+
+ enum class ReadOutThenCallbackResult { Stop, Continue };
+ using ReadOutThenCallback = std::function<ReadOutThenCallbackResult(std::span<char>)>;
+ /** Reads some chunks of output, calling the callback provided for each
+ * chunk and stopping if it returns Stop.
+ *
+ * @returns false if EOF, true if the callback requested we stop first.
+ * */
+ bool readOutThen(ReadOutThenCallback cb);
};
};