aboutsummaryrefslogtreecommitdiffstats
path: root/tests/cli.rs
diff options
context:
space:
mode:
authorElvis Claros Castro <elvis@claros.ar>2026-09-26 19:00:45 -0300
committerElvis Claros Castro <elvis@claros.ar>2026-09-26 19:00:45 -0300
commita946ba81f7a6089713337644053b00b825824a98 (patch)
treedf7c98401b3a879a0283e940afa3fecc9453d9d4 /tests/cli.rs
downloaddrae-cli-a946ba81f7a6089713337644053b00b825824a98.tar.gz
drae-cli-a946ba81f7a6089713337644053b00b825824a98.zip
drae: the RAE Spanish dictionary in the terminalHEADmain
Diffstat (limited to 'tests/cli.rs')
-rw-r--r--tests/cli.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/cli.rs b/tests/cli.rs
new file mode 100644
index 0000000..4d54a55
--- /dev/null
+++ b/tests/cli.rs
@@ -0,0 +1,62 @@
+//! Command-line contract. Everything here runs offline: real lookups are
+//! tested against the fixtures in the unit tests.
+
+use assert_cmd::Command;
+use predicates::prelude::PredicateBooleanExt;
+use predicates::str::contains;
+
+fn drae() -> Command {
+ let mut c = Command::cargo_bin("drae").unwrap();
+ // A separate cache, so the user's is neither touched nor relied upon.
+ c.env("XDG_CACHE_HOME", env!("CARGO_TARGET_TMPDIR"));
+ c.env("NO_COLOR", "1");
+ c
+}
+
+#[test]
+fn prints_help_without_arguments() {
+ drae()
+ .assert()
+ .success()
+ .stdout(contains("Diccionario de la lengua española"))
+ .stdout(contains("conjugar"));
+}
+
+#[test]
+fn reports_its_version() {
+ drae()
+ .arg("--version")
+ .assert()
+ .success()
+ .stdout(contains(env!("CARGO_PKG_VERSION")));
+}
+
+#[test]
+fn search_needs_the_cache() {
+ drae()
+ .args(["buscar", "edificio", "--sin-cache"])
+ .assert()
+ .failure()
+ .stderr(contains("está desactivada"));
+}
+
+#[test]
+fn cache_commands_work_on_an_empty_cache() {
+ drae().args(["cache", "info"]).assert().success();
+ drae()
+ .args(["cache", "listar"])
+ .assert()
+ .success()
+ .stdout(contains("vacía").or(contains("rae-api")));
+}
+
+#[test]
+fn definir_exists_for_words_that_clash_with_command_names() {
+ // `drae sin` is the synonyms command, so the word «sin» is looked up
+ // with `drae definir sin`.
+ drae()
+ .args(["definir", "--help"])
+ .assert()
+ .success()
+ .stdout(contains("PALABRA"));
+}