Skip to content

Commit 9b18614

Browse files
Fix up tests
Use predicates for better matching on stdout. Also use include_str instead of having to update the load file output by hand.
1 parent 159ba88 commit 9b18614

File tree

2 files changed

+9
-39
lines changed

2 files changed

+9
-39
lines changed

tests/cli_test.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,9 @@
1-
use std::{fs, process::Command};
1+
use std::process::Command;
22

33
use assert_cmd::prelude::*;
4-
use assert_fs::NamedTempFile;
5-
use indoc::indoc;
64
use predicates::prelude::*;
75

8-
static EXPECTED_OUT: &str = indoc!(
9-
"
10-
MOV.I $0, $1
11-
DAT.F $1, $2
12-
MOV.I $1, $0
13-
JMP.B $16, #0
14-
JMP.B $1, #0
15-
ADD.AB #1, @2
16-
SUB.F $3, $4
17-
MUL.F $5, $6
18-
DIV.F $7, $8
19-
MOD.F $9, $10
20-
JMZ.B $0, #0
21-
JMN.B $0, #0
22-
DJN.B $0, #0
23-
CMP.B $0, #0
24-
SEQ.B $0, #0
25-
SNE.B $0, #0
26-
SLT.B $0, #0
27-
SPL.B $0, #0
28-
NOP.B $0, #0
29-
MOV.A $1, $2
30-
MOV.B $1, $2
31-
MOV.AB $1, $2
32-
MOV.BA $1, $2
33-
MOV.F $1, $2
34-
MOV.X $1, $2
35-
MOV.I $1, $2
36-
JMP.B $-7, #0
37-
"
38-
);
6+
static EXPECTED_OUT: &str = include_str!("data/test_loadfile.red");
397

408
#[test]
419
fn help() {
@@ -73,12 +41,12 @@ fn dump_stdout() {
7341
.arg("-")
7442
.assert()
7543
.success()
76-
.stdout(predicate::str::contains(EXPECTED_OUT));
44+
.stdout(predicate::str::similar(EXPECTED_OUT));
7745
}
7846

7947
#[test]
8048
fn dump_file() {
81-
let out_file = NamedTempFile::new("out.red").expect("Failed to create tempfile");
49+
let out_file = assert_fs::NamedTempFile::new("out.red").expect("Failed to create tempfile");
8250

8351
Command::cargo_bin(assert_cmd::crate_name!())
8452
.unwrap()
@@ -90,6 +58,8 @@ fn dump_file() {
9058
.assert()
9159
.success();
9260

93-
let file_contents = fs::read_to_string(out_file.path()).expect("Failed to read output file");
94-
assert_eq!(file_contents, EXPECTED_OUT);
61+
assert!(predicate::str::similar(EXPECTED_OUT)
62+
.from_utf8()
63+
.from_file_path()
64+
.eval(out_file.path()));
9565
}

tests/dump_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn run_test(input: &str, expected_output: &str) {
1515
eprintln!("Loaded core:");
1616
dbg!(&parsed_core);
1717

18-
assert_eq!(format!("{}", parsed_core), expected_output);
18+
assert_eq!(parsed_core.to_string(), expected_output);
1919
}
2020

2121
#[test]

0 commit comments

Comments
 (0)