about summary refs log tree commit diff
path: root/tvix/cli/tests/repl.rs
diff options
context:
space:
mode:
authorAspen Smith <root@gws.fyi>2024-07-06T13·00-0400
committerclbot <clbot@tvl.fyi>2024-07-07T14·19+0000
commit0ad986169d06922945d035aab8d82266e798bffc (patch)
tree683e4633d8fee9636aa14bf5c329281e0b3733a9 /tvix/cli/tests/repl.rs
parent3a79f937951d34c7293bb093e4c21ddc3c2d88fc (diff)
test(tvix/cli): Make the REPL testable r/8353
Juggle around the internals of the tvix-cli crate so that we expose the
Repl as a public type with a `send` method, that sends a string to the
repl and *captures all output* so that it can be subsequently asserted
on in tests. Then, demonstrate that this works with a single (for now)
REPL test using expect-test to assert on the output of a single command
sent to the REPL.

As the REPL gets more complicated, this will allow us to make tests that
cover that complex behavior.

Change-Id: I88175bd72d8760c79faade95ebb1d956f08a7b83
Reviewed-on: https://cl.tvl.fyi/c/depot/+/11958
Autosubmit: aspen <root@gws.fyi>
Tested-by: BuildkiteCI
Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/cli/tests/repl.rs')
-rw-r--r--tvix/cli/tests/repl.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/tvix/cli/tests/repl.rs b/tvix/cli/tests/repl.rs
new file mode 100644
index 000000000000..8d49e7771db3
--- /dev/null
+++ b/tvix/cli/tests/repl.rs
@@ -0,0 +1,27 @@
+use std::ffi::OsString;
+
+use clap::Parser;
+use expect_test::expect;
+use tvix_cli::init_io_handle;
+
+macro_rules! test_repl {
+    ($name:ident() {$($send:expr => $expect:expr;)*}) => {
+        #[test]
+        fn $name() {
+            let tokio_runtime = tokio::runtime::Runtime::new().unwrap();
+            let args = tvix_cli::Args::parse_from(Vec::<OsString>::new());
+            let mut repl = tvix_cli::Repl::new(init_io_handle(&tokio_runtime, &args), &args);
+            $({
+                let result = repl.send($send.into());
+                $expect.assert_eq(result.output())
+                ;
+            })*
+        }
+    }
+}
+
+test_repl!(simple_expr_eval() {
+    "1" => expect![[r#"
+        => 1 :: int
+    "#]];
+});