Skip to content

Commit f43cb12

Browse files
committed
add tests
1 parent 11875ae commit f43cb12

File tree

7 files changed

+90
-0
lines changed

7 files changed

+90
-0
lines changed

Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ console = "0.6.2"
1111
syntect = "3.0.2"
1212
notify = "4.0.0"
1313
toml = "0.4.10"
14+
15+
[[bin]]
16+
name = "rustlings"
17+
path = "src/main.rs"
18+
19+
[dev-dependencies]
20+
assert_cmd = "0.11.0"

src/util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@ use std::fs::remove_file;
33
pub fn clean() {
44
let _ignored = remove_file("temp");
55
}
6+
7+
#[test]
8+
fn test_clean() {
9+
std::fs::File::create("temp").unwrap();
10+
clean();
11+
assert!(!std::path::Path::new("temp").exists());
12+
}

tests/fixture/compNoExercise.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fn main() {
2+
}

tests/fixture/compSuccess.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fn main() {
2+
}

tests/fixture/info.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[[exercises]]
2+
path = "compSuccess.rs"
3+
mode = "compile"
4+
5+
[[exercises]]
6+
path = "testSuccess.rs"
7+
mode = "test"

tests/fixture/testSuccess.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[test]
2+
fn passing() {
3+
assert!(true);
4+
}

tests/integration_tests.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use std::process::Command;
2+
use assert_cmd::prelude::*;
3+
4+
#[test]
5+
fn runs_without_arguments() {
6+
let mut cmd = Command::cargo_bin("rustlings").unwrap();
7+
cmd.assert().success();
8+
}
9+
10+
#[test]
11+
fn fails_when_in_wrong_dir() {
12+
Command::cargo_bin("rustlings").unwrap()
13+
.current_dir("tests/")
14+
.assert()
15+
.failure();
16+
}
17+
18+
#[test]
19+
fn verify_all_success() {
20+
Command::cargo_bin("rustlings").unwrap()
21+
.arg("v")
22+
.current_dir("tests/fixture/")
23+
.assert()
24+
.success();
25+
}
26+
27+
#[test]
28+
fn run_single_compile_success() {
29+
Command::cargo_bin("rustlings").unwrap()
30+
.args(&["r", "compSuccess.rs"])
31+
.current_dir("tests/fixture/")
32+
.assert()
33+
.success();
34+
}
35+
36+
#[test]
37+
fn run_single_test_success() {
38+
Command::cargo_bin("rustlings").unwrap()
39+
.args(&["r", "testSuccess.rs"])
40+
.current_dir("tests/fixture/")
41+
.assert()
42+
.success();
43+
}
44+
45+
#[test]
46+
fn run_single_test_no_filename() {
47+
Command::cargo_bin("rustlings").unwrap()
48+
.arg("r")
49+
.current_dir("tests/fixture/")
50+
.assert()
51+
.failure();
52+
}
53+
54+
#[test]
55+
fn run_single_test_no_exercise() {
56+
Command::cargo_bin("rustlings").unwrap()
57+
.args(&["r", "compNoExercise.rs"])
58+
.current_dir("tests/fixture/")
59+
.assert()
60+
.failure();
61+
}

0 commit comments

Comments
 (0)