summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMo <76752051+mo8it@users.noreply.github.com>2024-04-14 17:13:32 +0200
committerGitHub <noreply@github.com>2024-04-14 17:13:32 +0200
commitdc02c38a945fcafacf6d2d35f5d3e317e7185cb0 (patch)
treebd3ad843a575650881b220c4b008fc7509917d24 /tests
parent8c8f30d8ce3b732de649938d8945496bd769ac22 (diff)
parent7526c6b1f92626df6ab8b4853535b73711bfada4 (diff)
Merge pull request #1942 from rust-lang/tui
TUI
Diffstat (limited to 'tests')
-rw-r--r--tests/dev_cargo_bins.rs41
-rw-r--r--tests/fixture/failure/Cargo.toml2
-rw-r--r--tests/fixture/failure/info.toml4
-rw-r--r--tests/fixture/state/Cargo.toml2
-rw-r--r--tests/fixture/state/exercises/pending_exercise.rs2
-rw-r--r--tests/fixture/state/exercises/pending_test_exercise.rs2
-rw-r--r--tests/fixture/state/info.toml7
-rw-r--r--tests/fixture/success/Cargo.toml2
-rw-r--r--tests/fixture/success/info.toml4
-rw-r--r--tests/integration_tests.rs134
10 files changed, 31 insertions, 169 deletions
diff --git a/tests/dev_cargo_bins.rs b/tests/dev_cargo_bins.rs
index 7f1771b..81f48b1 100644
--- a/tests/dev_cargo_bins.rs
+++ b/tests/dev_cargo_bins.rs
@@ -1,38 +1,43 @@
// Makes sure that `dev/Cargo.toml` is synced with `info.toml`.
-// When this test fails, you just need to run `cargo run --bin gen-dev-cargo-toml`.
+// When this test fails, you just need to run `cargo run -p gen-dev-cargo-toml`.
use serde::Deserialize;
use std::fs;
#[derive(Deserialize)]
-struct Exercise {
+struct ExerciseInfo {
name: String,
- path: String,
+ dir: Option<String>,
}
#[derive(Deserialize)]
-struct InfoToml {
- exercises: Vec<Exercise>,
+struct InfoFile {
+ exercises: Vec<ExerciseInfo>,
}
#[test]
fn dev_cargo_bins() {
- let content = fs::read_to_string("exercises/Cargo.toml").unwrap();
+ let cargo_toml = fs::read_to_string("dev/Cargo.toml").unwrap();
- let exercises = toml_edit::de::from_str::<InfoToml>(&fs::read_to_string("info.toml").unwrap())
- .unwrap()
- .exercises;
+ let exercise_infos =
+ toml_edit::de::from_str::<InfoFile>(&fs::read_to_string("info.toml").unwrap())
+ .unwrap()
+ .exercises;
let mut start_ind = 0;
- for exercise in exercises {
- let name_start = start_ind + content[start_ind..].find('"').unwrap() + 1;
- let name_end = name_start + content[name_start..].find('"').unwrap();
- assert_eq!(exercise.name, &content[name_start..name_end]);
-
- // +3 to skip `../` at the begeinning of the path.
- let path_start = name_end + content[name_end + 1..].find('"').unwrap() + 5;
- let path_end = path_start + content[path_start..].find('"').unwrap();
- assert_eq!(exercise.path, &content[path_start..path_end]);
+ for exercise_info in exercise_infos {
+ let name_start = start_ind + cargo_toml[start_ind..].find('"').unwrap() + 1;
+ let name_end = name_start + cargo_toml[name_start..].find('"').unwrap();
+ assert_eq!(exercise_info.name, &cargo_toml[name_start..name_end]);
+
+ let path_start = name_end + cargo_toml[name_end + 1..].find('"').unwrap() + 2;
+ let path_end = path_start + cargo_toml[path_start..].find('"').unwrap();
+ let expected_path = if let Some(dir) = exercise_info.dir {
+ format!("../exercises/{dir}/{}.rs", exercise_info.name)
+ } else {
+ format!("../exercises/{}.rs", exercise_info.name)
+ };
+ assert_eq!(expected_path, &cargo_toml[path_start..path_end]);
start_ind = path_end + 1;
}
diff --git a/tests/fixture/failure/Cargo.toml b/tests/fixture/failure/Cargo.toml
index e111cf2..7ee2f06 100644
--- a/tests/fixture/failure/Cargo.toml
+++ b/tests/fixture/failure/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "tests"
+name = "failure"
edition = "2021"
publish = false
diff --git a/tests/fixture/failure/info.toml b/tests/fixture/failure/info.toml
index 9474ee3..94ec6ea 100644
--- a/tests/fixture/failure/info.toml
+++ b/tests/fixture/failure/info.toml
@@ -1,11 +1,9 @@
[[exercises]]
name = "compFailure"
-path = "exercises/compFailure.rs"
-mode = "compile"
+mode = "run"
hint = ""
[[exercises]]
name = "testFailure"
-path = "exercises/testFailure.rs"
mode = "test"
hint = "Hello!"
diff --git a/tests/fixture/state/Cargo.toml b/tests/fixture/state/Cargo.toml
index c8d74e4..adbd8ab 100644
--- a/tests/fixture/state/Cargo.toml
+++ b/tests/fixture/state/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "tests"
+name = "state"
edition = "2021"
publish = false
diff --git a/tests/fixture/state/exercises/pending_exercise.rs b/tests/fixture/state/exercises/pending_exercise.rs
index f579d0b..016b827 100644
--- a/tests/fixture/state/exercises/pending_exercise.rs
+++ b/tests/fixture/state/exercises/pending_exercise.rs
@@ -1,7 +1,5 @@
// fake_exercise
-// I AM NOT DONE
-
fn main() {
}
diff --git a/tests/fixture/state/exercises/pending_test_exercise.rs b/tests/fixture/state/exercises/pending_test_exercise.rs
index 8756f02..2002ef1 100644
--- a/tests/fixture/state/exercises/pending_test_exercise.rs
+++ b/tests/fixture/state/exercises/pending_test_exercise.rs
@@ -1,4 +1,2 @@
-// I AM NOT DONE
-
#[test]
fn it_works() {}
diff --git a/tests/fixture/state/info.toml b/tests/fixture/state/info.toml
index 8de5d60..e5c4d8f 100644
--- a/tests/fixture/state/info.toml
+++ b/tests/fixture/state/info.toml
@@ -1,17 +1,14 @@
[[exercises]]
name = "pending_exercise"
-path = "exercises/pending_exercise.rs"
-mode = "compile"
+mode = "run"
hint = """"""
[[exercises]]
name = "pending_test_exercise"
-path = "exercises/pending_test_exercise.rs"
mode = "test"
hint = """"""
[[exercises]]
name = "finished_exercise"
-path = "exercises/finished_exercise.rs"
-mode = "compile"
+mode = "run"
hint = """"""
diff --git a/tests/fixture/success/Cargo.toml b/tests/fixture/success/Cargo.toml
index f26a44f..028cf35 100644
--- a/tests/fixture/success/Cargo.toml
+++ b/tests/fixture/success/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "tests"
+name = "success"
edition = "2021"
publish = false
diff --git a/tests/fixture/success/info.toml b/tests/fixture/success/info.toml
index 17ed8c6..674ba26 100644
--- a/tests/fixture/success/info.toml
+++ b/tests/fixture/success/info.toml
@@ -1,11 +1,9 @@
[[exercises]]
name = "compSuccess"
-path = "exercises/compSuccess.rs"
-mode = "compile"
+mode = "run"
hint = """"""
[[exercises]]
name = "testSuccess"
-path = "exercises/testSuccess.rs"
mode = "test"
hint = """"""
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index d1694a3..f81cc94 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -1,17 +1,8 @@
use assert_cmd::prelude::*;
-use glob::glob;
use predicates::boolean::PredicateBooleanExt;
-use std::fs::File;
-use std::io::Read;
use std::process::Command;
#[test]
-fn runs_without_arguments() {
- let mut cmd = Command::cargo_bin("rustlings").unwrap();
- cmd.assert().success();
-}
-
-#[test]
fn fails_when_in_wrong_dir() {
Command::cargo_bin("rustlings")
.unwrap()
@@ -21,26 +12,6 @@ fn fails_when_in_wrong_dir() {
}
#[test]
-fn verify_all_success() {
- Command::cargo_bin("rustlings")
- .unwrap()
- .arg("verify")
- .current_dir("tests/fixture/success")
- .assert()
- .success();
-}
-
-#[test]
-fn verify_fails_if_some_fails() {
- Command::cargo_bin("rustlings")
- .unwrap()
- .arg("verify")
- .current_dir("tests/fixture/failure")
- .assert()
- .code(1);
-}
-
-#[test]
fn run_single_compile_success() {
Command::cargo_bin("rustlings")
.unwrap()
@@ -91,19 +62,6 @@ fn run_single_test_not_passed() {
}
#[test]
-fn run_single_test_no_filename() {
- Command::cargo_bin("rustlings")
- .unwrap()
- .arg("run")
- .current_dir("tests/fixture/")
- .assert()
- .code(2)
- .stderr(predicates::str::contains(
- "required arguments were not provided",
- ));
-}
-
-#[test]
fn run_single_test_no_exercise() {
Command::cargo_bin("rustlings")
.unwrap()
@@ -146,31 +104,6 @@ fn get_hint_for_single_test() {
}
#[test]
-fn all_exercises_require_confirmation() {
- for exercise in glob("exercises/**/*.rs").unwrap() {
- let path = exercise.unwrap();
- if path.file_name().unwrap() == "mod.rs" {
- continue;
- }
- let source = {
- let mut file = File::open(&path).unwrap();
- let mut s = String::new();
- file.read_to_string(&mut s).unwrap();
- s
- };
- source
- .matches("// I AM NOT DONE")
- .next()
- .unwrap_or_else(|| {
- panic!(
- "There should be an `I AM NOT DONE` annotation in {:?}",
- path
- )
- });
- }
-}
-
-#[test]
fn run_compile_exercise_does_not_prompt() {
Command::cargo_bin("rustlings")
.unwrap()
@@ -196,74 +129,9 @@ fn run_test_exercise_does_not_prompt() {
fn run_single_test_success_with_output() {
Command::cargo_bin("rustlings")
.unwrap()
- .args(["--nocapture", "run", "testSuccess"])
- .current_dir("tests/fixture/success/")
- .assert()
- .code(0)
- .stdout(predicates::str::contains("THIS TEST TOO SHALL PASS"));
-}
-
-#[test]
-fn run_single_test_success_without_output() {
- Command::cargo_bin("rustlings")
- .unwrap()
.args(["run", "testSuccess"])
.current_dir("tests/fixture/success/")
.assert()
.code(0)
- .stdout(predicates::str::contains("THIS TEST TOO SHALL PASS").not());
-}
-
-#[test]
-fn run_rustlings_list() {
- Command::cargo_bin("rustlings")
- .unwrap()
- .args(["list"])
- .current_dir("tests/fixture/success")
- .assert()
- .success();
-}
-
-#[test]
-fn run_rustlings_list_no_pending() {
- Command::cargo_bin("rustlings")
- .unwrap()
- .args(["list"])
- .current_dir("tests/fixture/success")
- .assert()
- .success()
- .stdout(predicates::str::contains("Pending").not());
-}
-
-#[test]
-fn run_rustlings_list_both_done_and_pending() {
- Command::cargo_bin("rustlings")
- .unwrap()
- .args(["list"])
- .current_dir("tests/fixture/state")
- .assert()
- .success()
- .stdout(predicates::str::contains("Done").and(predicates::str::contains("Pending")));
-}
-
-#[test]
-fn run_rustlings_list_without_pending() {
- Command::cargo_bin("rustlings")
- .unwrap()
- .args(["list", "--solved"])
- .current_dir("tests/fixture/state")
- .assert()
- .success()
- .stdout(predicates::str::contains("Pending").not());
-}
-
-#[test]
-fn run_rustlings_list_without_done() {
- Command::cargo_bin("rustlings")
- .unwrap()
- .args(["list", "--unsolved"])
- .current_dir("tests/fixture/state")
- .assert()
- .success()
- .stdout(predicates::str::contains("Done").not());
+ .stdout(predicates::str::contains("THIS TEST TOO SHALL PASS"));
}