Internal: Add UI tests for CLIs
ohsayan opened this issue · comments
While work is being done on improving the CLI experience, there is currently no way to test what the CLIs output and this makes it a possible source of bugs. We can follow rustc
's way of having UI tests and implement it as a kind of test inside our build tool harness
. We can also directly have it within each binary crate, wherein we check the ArgMatches
inside tests.
If there are any other possible options, feel free to discuss here. This should be relatively uncomplicated to achieve, so feel free to take this up and I'm open to mentoring.
Could you provide me with a reference implementation link or a head start so I can start working on this?
when you talk about add UI tests for CLIs, you talk about commands like these below, or about the REPL?
use assert_cmd::Command;
#[test]
fn base_clap_args_test() {
let message = r"skysh 0.8.0
Sayan Nandan <ohsayan@outlook.com>
The Skytable Shell (skysh)
Usage: skysh [OPTIONS]
Options:
-C, --sslcert <CERT> Sets the PEM certificate to use for SSL connections
-e, --eval [<EXPRESSION>...] Run one or more expressions without REPL
-h, --host <HOST> Sets the remote host to connect to [default: 127.0.0.1]
-p, --port <PORT> Sets the remote port to connect to [default: 2003]
--help Print help information
-V, --version Print version information
";
let mut cmd = Command::cargo_bin("skysh").unwrap();
let assert = cmd.arg("--help").assert();
assert.success().code(0).stdout(message);
}
#[test]
fn null_arg_on_host() {
let mut cmd = Command::cargo_bin("skysh").unwrap();
let assert = cmd.arg("-h").assert();
assert
.failure()
.code(2)
.stderr("error: The argument \'--host <HOST>\' requires a value but none was supplied\n");
}
Thanks for taking a look at this! By this I do mean both REPL and CLI "menu tests." I should've specified this more precisely
Now that we use a custom implementation for argument parsing, this is no longer needed.