Algo de formato

This commit is contained in:
perro tuerto 2023-02-13 16:57:21 -08:00
parent 04565cb844
commit f88b2601d4
5 changed files with 19 additions and 11 deletions

View File

@ -1,3 +1,3 @@
fn main() {
std::process::abort();
std::process::abort();
}

View File

@ -1,3 +1,3 @@
fn main() {
std::process::exit(0);
std::process::exit(0);
}

View File

@ -2,18 +2,18 @@ use assert_cmd::Command;
#[test]
fn runs() {
let mut cmd = Command::cargo_bin("hello").unwrap();
cmd.assert().success().stdout("Hello, world!\n");
let mut cmd = Command::cargo_bin("hello").unwrap();
cmd.assert().success().stdout("Hello, world!\n");
}
#[test]
fn true_ok() {
let mut cmd = Command::cargo_bin("true").unwrap();
cmd.assert().success();
let mut cmd = Command::cargo_bin("true").unwrap();
cmd.assert().success();
}
#[test]
fn false_not_ok() {
let mut cmd = Command::cargo_bin("false").unwrap();
cmd.assert().failure();
let mut cmd = Command::cargo_bin("false").unwrap();
cmd.assert().failure();
}

View File

@ -21,6 +21,10 @@ fn main() {
.get_matches();
// OJO: unwrap es seguro de llamar porque 'text' está forzado en tener al menos un valor
let text = matches.values_of_lossy("text").unwrap();
let ending = if matches.is_present("omit_newline") { "" } else { "\n"};
let ending = if matches.is_present("omit_newline") {
""
} else {
"\n"
};
print!("{}{}", text.join(" "), ending);
}

View File

@ -1,12 +1,16 @@
use std::fs;
use assert_cmd::Command;
use predicates::prelude::*;
use std::fs;
type TestResult = Result<(), Box<dyn std::error::Error>>;
fn run(args: &[&str], expected_file: &str) -> TestResult {
let expected = fs::read_to_string(format!("{}{}", "tests/expected/", expected_file))?;
Command::cargo_bin("echor")?.args(args).assert().success().stdout(expected);
Command::cargo_bin("echor")?
.args(args)
.assert()
.success()
.stdout(expected);
Ok(())
}