mirror of
https://github.com/rust-lang/rustlings.git
synced 2024-12-26 00:00:03 +03:00
Compare commits
7 commits
7eca061611
...
5d822b3338
Author | SHA1 | Date | |
---|---|---|---|
5d822b3338 | |||
1937b4bf66 | |||
8beb290842 | |||
8fec5155c7 | |||
3f49decce9 | |||
e2492f65a0 | |||
9f517e4eb8 |
5
.github/workflows/rust.yml
vendored
5
.github/workflows/rust.yml
vendored
|
@ -37,7 +37,10 @@ jobs:
|
|||
- name: Run cargo test
|
||||
run: cargo test --workspace
|
||||
dev-check:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: swatinem/rust-cache@v2
|
||||
|
|
196
Cargo.lock
generated
196
Cargo.lock
generated
|
@ -14,15 +14,6 @@ dependencies = [
|
|||
"zerocopy",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "allocator-api2"
|
||||
version = "0.2.18"
|
||||
|
@ -31,9 +22,9 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f"
|
|||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.14"
|
||||
version = "0.6.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
|
||||
checksum = "64e15c1ab1f89faffbf04a634d5e1962e9074f2741eef6d97f3c4e322426d526"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
|
@ -46,33 +37,33 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.7"
|
||||
version = "1.0.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
|
||||
checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.4"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
|
||||
checksum = "eb47de1e80c2b463c735db5b217a0ddc39d612e7ac9e2e96a5aed1f57616c1cb"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.0"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391"
|
||||
checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a"
|
||||
dependencies = [
|
||||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.3"
|
||||
version = "3.0.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
|
||||
checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"windows-sys 0.52.0",
|
||||
|
@ -84,21 +75,6 @@ version = "1.0.86"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
|
||||
|
||||
[[package]]
|
||||
name = "assert_cmd"
|
||||
version = "2.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"bstr",
|
||||
"doc-comment",
|
||||
"predicates",
|
||||
"predicates-core",
|
||||
"predicates-tree",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.3.0"
|
||||
|
@ -117,17 +93,6 @@ version = "2.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "1.9.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05efc5cfd9110c8416e471df0e96702d58690178e206e61b7173706673c93706"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cassowary"
|
||||
version = "0.3.0"
|
||||
|
@ -151,9 +116,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.9"
|
||||
version = "4.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462"
|
||||
checksum = "35723e6a11662c2afb578bcf0b88bf6ea8e21282a953428f240574fcc3a2b5b3"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
|
@ -161,9 +126,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.9"
|
||||
version = "4.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942"
|
||||
checksum = "49eb96cbfa7cfa35017b7cd548c75b14c3118c98b423041d70562665e07fb0fa"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
|
@ -173,9 +138,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.8"
|
||||
version = "4.5.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bac35c6dafb060fd4d275d9a4ffae97917c13a6327903a8be2153cd964f7085"
|
||||
checksum = "5d029b67f89d30bbb547c89fd5161293c0aec155fc691d7924b64550662db93e"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
|
@ -185,15 +150,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.1"
|
||||
version = "0.7.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70"
|
||||
checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.1"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
|
||||
checksum = "d3fd119d74b830634cea2a0f58bbd0d54540518a14397557951e79340abc28c0"
|
||||
|
||||
[[package]]
|
||||
name = "compact_str"
|
||||
|
@ -248,18 +213,6 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "difflib"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
||||
|
||||
[[package]]
|
||||
name = "doc-comment"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.13.0"
|
||||
|
@ -284,15 +237,6 @@ dependencies = [
|
|||
"windows-sys 0.52.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "float-cmp"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fsevent-sys"
|
||||
version = "4.1.0"
|
||||
|
@ -350,9 +294,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.0"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
|
@ -438,12 +382,6 @@ dependencies = [
|
|||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "normalize-line-endings"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
|
||||
|
||||
[[package]]
|
||||
name = "notify"
|
||||
version = "6.1.1"
|
||||
|
@ -473,15 +411,6 @@ dependencies = [
|
|||
"notify",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.19.0"
|
||||
|
@ -527,36 +456,6 @@ version = "1.0.15"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"difflib",
|
||||
"float-cmp",
|
||||
"normalize-line-endings",
|
||||
"predicates-core",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b794032607612e7abeb4db69adb4e33590fa6cf1149e95fd7cb00e634b92f174"
|
||||
|
||||
[[package]]
|
||||
name = "predicates-tree"
|
||||
version = "1.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "368ba315fb8c5052ab692e68a0eefec6ec57b23a36959c14496f0b0df2c0cecf"
|
||||
dependencies = [
|
||||
"predicates-core",
|
||||
"termtree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.86"
|
||||
|
@ -614,47 +513,15 @@ dependencies = [
|
|||
"bitflags 2.6.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.10.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
|
||||
|
||||
[[package]]
|
||||
name = "rustlings"
|
||||
version = "6.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
"clap",
|
||||
"crossterm",
|
||||
"hashbrown",
|
||||
"notify-debouncer-mini",
|
||||
"os_pipe",
|
||||
"predicates",
|
||||
"ratatui",
|
||||
"rustlings-macros",
|
||||
"serde",
|
||||
|
@ -829,12 +696,6 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termtree"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76"
|
||||
|
||||
[[package]]
|
||||
name = "toml_datetime"
|
||||
version = "0.6.6"
|
||||
|
@ -898,15 +759,6 @@ version = "0.9.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "walkdir"
|
||||
version = "2.5.0"
|
||||
|
@ -1095,9 +947,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
|||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.6.14"
|
||||
version = "0.6.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "374ec40a2d767a3c1b4972d9475ecd557356637be906f2cb3f7fe17a6eb5e22f"
|
||||
checksum = "557404e450152cd6795bb558bca69e43c585055f4606e3bcae5894fc6dac9ba0"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
|
11
Cargo.toml
11
Cargo.toml
|
@ -1,9 +1,7 @@
|
|||
[workspace]
|
||||
resolver = "2"
|
||||
exclude = [
|
||||
"tests/fixture/failure",
|
||||
"tests/fixture/state",
|
||||
"tests/fixture/success",
|
||||
"tests/test_exercises",
|
||||
"dev",
|
||||
]
|
||||
|
||||
|
@ -47,8 +45,7 @@ include = [
|
|||
|
||||
[dependencies]
|
||||
anyhow = "1.0.86"
|
||||
clap = { version = "4.5.9", features = ["derive"] }
|
||||
crossterm = "0.27.0"
|
||||
clap = { version = "4.5.11", features = ["derive"] }
|
||||
hashbrown = "0.14.5"
|
||||
notify-debouncer-mini = { version = "0.4.1", default-features = false }
|
||||
os_pipe = "1.2.0"
|
||||
|
@ -58,10 +55,6 @@ serde_json = "1.0.120"
|
|||
serde.workspace = true
|
||||
toml_edit.workspace = true
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "2.0.14"
|
||||
predicates = "3.1.0"
|
||||
|
||||
[profile.release]
|
||||
panic = "abort"
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::{bail, Context, Result};
|
||||
use crossterm::style::Stylize;
|
||||
use ratatui::crossterm::style::Stylize;
|
||||
use serde::Deserialize;
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use crossterm::style::{style, StyledContent, Stylize};
|
||||
use ratatui::crossterm::style::{style, StyledContent, Stylize};
|
||||
use std::{
|
||||
fmt::{self, Display, Formatter},
|
||||
io::Write,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::{bail, Context, Result};
|
||||
use crossterm::style::Stylize;
|
||||
use ratatui::crossterm::style::Stylize;
|
||||
use std::{
|
||||
env::set_current_dir,
|
||||
fs::{self, create_dir},
|
||||
|
|
13
src/list.rs
13
src/list.rs
|
@ -1,10 +1,13 @@
|
|||
use anyhow::Result;
|
||||
use crossterm::{
|
||||
event::{self, Event, KeyCode, KeyEventKind},
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
ExecutableCommand,
|
||||
use ratatui::{
|
||||
backend::CrosstermBackend,
|
||||
crossterm::{
|
||||
event::{self, Event, KeyCode, KeyEventKind},
|
||||
terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen},
|
||||
ExecutableCommand,
|
||||
},
|
||||
Terminal,
|
||||
};
|
||||
use ratatui::{backend::CrosstermBackend, Terminal};
|
||||
use std::io;
|
||||
|
||||
use crate::app_state::AppState;
|
||||
|
|
|
@ -95,10 +95,6 @@ fn main() -> Result<()> {
|
|||
|
||||
match args.command {
|
||||
Some(Subcommands::Init) => {
|
||||
if DEBUG_PROFILE {
|
||||
bail!("Disabled in the debug build");
|
||||
}
|
||||
|
||||
{
|
||||
let mut stdout = io::stdout().lock();
|
||||
stdout.write_all(b"This command will create the directory `rustlings/` which will contain the exercises.\nPress ENTER to continue ")?;
|
||||
|
|
|
@ -14,7 +14,7 @@ const PROGRESS_EXCEEDS_MAX_ERR: &str =
|
|||
|
||||
/// Terminal progress bar to be used when not using Ratataui.
|
||||
pub fn progress_bar(progress: u16, total: u16, line_width: u16) -> Result<String> {
|
||||
use crossterm::style::Stylize;
|
||||
use ratatui::crossterm::style::Stylize;
|
||||
|
||||
if progress > total {
|
||||
bail!(PROGRESS_EXCEEDS_MAX_ERR);
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::{bail, Result};
|
||||
use crossterm::style::{style, Stylize};
|
||||
use ratatui::crossterm::style::{style, Stylize};
|
||||
use std::io::{self, Write};
|
||||
|
||||
use crate::{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use anyhow::Result;
|
||||
use crossterm::{
|
||||
use ratatui::crossterm::{
|
||||
style::{style, Stylize},
|
||||
terminal,
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
|
||||
use ratatui::crossterm::event::{self, Event, KeyCode, KeyEventKind, KeyModifiers};
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
use super::WatchEvent;
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
[package]
|
||||
name = "failure"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "compFailure"
|
||||
path = "exercises/compFailure.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "compNoExercise"
|
||||
path = "exercises/compNoExercise.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "testFailure"
|
||||
path = "exercises/testFailure.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "testNotPassed"
|
||||
path = "exercises/testNotPassed.rs"
|
|
@ -1,6 +0,0 @@
|
|||
fn main() {}
|
||||
|
||||
#[test]
|
||||
fn passing() {
|
||||
asset!(true);
|
||||
}
|
|
@ -1,6 +0,0 @@
|
|||
fn main() {}
|
||||
|
||||
#[test]
|
||||
fn not_passing() {
|
||||
assert!(false);
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
format_version = 1
|
||||
|
||||
[[exercises]]
|
||||
name = "compFailure"
|
||||
test = false
|
||||
hint = ""
|
||||
|
||||
[[exercises]]
|
||||
name = "testFailure"
|
||||
hint = "Hello!"
|
|
@ -1,16 +0,0 @@
|
|||
[package]
|
||||
name = "state"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "pending_exercise"
|
||||
path = "exercises/pending_exercise.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "pending_test_exercise"
|
||||
path = "exercises/pending_test_exercise.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "finished_exercise"
|
||||
path = "exercises/finished_exercise.rs"
|
|
@ -1 +0,0 @@
|
|||
fn main() {}
|
|
@ -1,4 +0,0 @@
|
|||
fn main() {}
|
||||
|
||||
#[test]
|
||||
fn it_works() {}
|
|
@ -1,15 +0,0 @@
|
|||
format_version = 1
|
||||
|
||||
[[exercises]]
|
||||
name = "pending_exercise"
|
||||
test = false
|
||||
hint = """"""
|
||||
|
||||
[[exercises]]
|
||||
name = "pending_test_exercise"
|
||||
hint = """"""
|
||||
|
||||
[[exercises]]
|
||||
name = "finished_exercise"
|
||||
test = false
|
||||
hint = """"""
|
|
@ -1,12 +0,0 @@
|
|||
[package]
|
||||
name = "success"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "compSuccess"
|
||||
path = "exercises/compSuccess.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "testSuccess"
|
||||
path = "exercises/testSuccess.rs"
|
|
@ -1 +0,0 @@
|
|||
fn main() {}
|
|
@ -1,7 +0,0 @@
|
|||
fn main() {}
|
||||
|
||||
#[test]
|
||||
fn passing() {
|
||||
println!("THIS TEST TOO SHALL PASS");
|
||||
assert!(true);
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
format_version = 1
|
||||
|
||||
[[exercises]]
|
||||
name = "compSuccess"
|
||||
test = false
|
||||
hint = """"""
|
||||
|
||||
[[exercises]]
|
||||
name = "testSuccess"
|
||||
hint = """"""
|
|
@ -1,134 +1,182 @@
|
|||
use assert_cmd::prelude::*;
|
||||
use std::process::Command;
|
||||
use std::{
|
||||
env::{self, consts::EXE_SUFFIX},
|
||||
fs,
|
||||
process::{Command, Stdio},
|
||||
str::from_utf8,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn fails_when_in_wrong_dir() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.current_dir("tests/")
|
||||
.assert()
|
||||
.code(1);
|
||||
enum Output<'a> {
|
||||
FullStdout(&'a str),
|
||||
PartialStdout(&'a str),
|
||||
PartialStderr(&'a str),
|
||||
}
|
||||
|
||||
use Output::*;
|
||||
|
||||
#[derive(Default)]
|
||||
struct Cmd<'a> {
|
||||
current_dir: Option<&'a str>,
|
||||
args: &'a [&'a str],
|
||||
output: Option<Output<'a>>,
|
||||
}
|
||||
|
||||
impl<'a> Cmd<'a> {
|
||||
#[inline]
|
||||
fn current_dir(&mut self, current_dir: &'a str) -> &mut Self {
|
||||
self.current_dir = Some(current_dir);
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn args(&mut self, args: &'a [&'a str]) -> &mut Self {
|
||||
self.args = args;
|
||||
self
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn output(&mut self, output: Output<'a>) -> &mut Self {
|
||||
self.output = Some(output);
|
||||
self
|
||||
}
|
||||
|
||||
fn assert(&self, success: bool) {
|
||||
let rustlings_bin = {
|
||||
let mut path = env::current_exe().unwrap();
|
||||
// Pop test binary name
|
||||
path.pop();
|
||||
// Pop `/deps`
|
||||
path.pop();
|
||||
|
||||
path.push("rustlings");
|
||||
let mut path = path.into_os_string();
|
||||
path.push(EXE_SUFFIX);
|
||||
path
|
||||
};
|
||||
|
||||
let mut cmd = Command::new(rustlings_bin);
|
||||
|
||||
if let Some(current_dir) = self.current_dir {
|
||||
cmd.current_dir(current_dir);
|
||||
}
|
||||
|
||||
cmd.args(self.args).stdin(Stdio::null());
|
||||
|
||||
let status = match self.output {
|
||||
None => cmd
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
.unwrap(),
|
||||
Some(FullStdout(stdout)) => {
|
||||
let output = cmd.stderr(Stdio::null()).output().unwrap();
|
||||
assert_eq!(from_utf8(&output.stdout).unwrap(), stdout);
|
||||
output.status
|
||||
}
|
||||
Some(PartialStdout(stdout)) => {
|
||||
let output = cmd.stderr(Stdio::null()).output().unwrap();
|
||||
assert!(from_utf8(&output.stdout).unwrap().contains(stdout));
|
||||
output.status
|
||||
}
|
||||
Some(PartialStderr(stderr)) => {
|
||||
let output = cmd.stdout(Stdio::null()).output().unwrap();
|
||||
assert!(from_utf8(&output.stderr).unwrap().contains(stderr));
|
||||
output.status
|
||||
}
|
||||
};
|
||||
|
||||
assert_eq!(status.success(), success, "{cmd:?}");
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn success(&self) {
|
||||
self.assert(true);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn fail(&self) {
|
||||
self.assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_single_compile_success() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["run", "compSuccess"])
|
||||
.current_dir("tests/fixture/success/")
|
||||
.assert()
|
||||
fn run_compilation_success() {
|
||||
Cmd::default()
|
||||
.current_dir("tests/test_exercises")
|
||||
.args(&["run", "compilation_success"])
|
||||
.success();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_single_compile_failure() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["run", "compFailure"])
|
||||
.current_dir("tests/fixture/failure/")
|
||||
.assert()
|
||||
.code(1);
|
||||
fn run_compilation_failure() {
|
||||
Cmd::default()
|
||||
.current_dir("tests/test_exercises")
|
||||
.args(&["run", "compilation_failure"])
|
||||
.fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_single_test_success() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["run", "testSuccess"])
|
||||
.current_dir("tests/fixture/success/")
|
||||
.assert()
|
||||
fn run_test_success() {
|
||||
Cmd::default()
|
||||
.current_dir("tests/test_exercises")
|
||||
.args(&["run", "test_success"])
|
||||
.output(PartialStdout("\nOutput from `main` function\n"))
|
||||
.success();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_single_test_failure() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["run", "testFailure"])
|
||||
.current_dir("tests/fixture/failure/")
|
||||
.assert()
|
||||
.code(1);
|
||||
fn run_test_failure() {
|
||||
Cmd::default()
|
||||
.current_dir("tests/test_exercises")
|
||||
.args(&["run", "test_failure"])
|
||||
.fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_single_test_not_passed() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["run", "testNotPassed.rs"])
|
||||
.current_dir("tests/fixture/failure/")
|
||||
.assert()
|
||||
.code(1);
|
||||
fn run_exercise_not_in_info() {
|
||||
Cmd::default()
|
||||
.current_dir("tests/test_exercises")
|
||||
.args(&["run", "not_in_info"])
|
||||
.fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_single_test_no_exercise() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["run", "compNoExercise.rs"])
|
||||
.current_dir("tests/fixture/failure")
|
||||
.assert()
|
||||
.code(1);
|
||||
fn reset_without_exercise_name() {
|
||||
Cmd::default().args(&["reset"]).fail();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_single_exercise() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["reset", "intro1"])
|
||||
.assert()
|
||||
.code(0);
|
||||
fn hint() {
|
||||
Cmd::default()
|
||||
.current_dir("tests/test_exercises")
|
||||
.args(&["hint", "test_failure"])
|
||||
.output(FullStdout("The answer to everything: 42\n"))
|
||||
.success();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reset_no_exercise() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.arg("reset")
|
||||
.assert()
|
||||
.code(2)
|
||||
.stderr(predicates::str::contains(
|
||||
"required arguments were not provided",
|
||||
));
|
||||
}
|
||||
fn init() {
|
||||
let _ = fs::remove_dir_all("tests/rustlings");
|
||||
|
||||
#[test]
|
||||
fn get_hint_for_single_test() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["hint", "testFailure"])
|
||||
.current_dir("tests/fixture/failure")
|
||||
.assert()
|
||||
.code(0)
|
||||
.stdout("Hello!\n");
|
||||
}
|
||||
Cmd::default().current_dir("tests").fail();
|
||||
|
||||
#[test]
|
||||
fn run_compile_exercise_does_not_prompt() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["run", "pending_exercise"])
|
||||
.current_dir("tests/fixture/state")
|
||||
.assert()
|
||||
.code(0);
|
||||
}
|
||||
Cmd::default()
|
||||
.current_dir("tests")
|
||||
.args(&["init"])
|
||||
.success();
|
||||
|
||||
#[test]
|
||||
fn run_test_exercise_does_not_prompt() {
|
||||
Command::cargo_bin("rustlings")
|
||||
.unwrap()
|
||||
.args(["run", "pending_test_exercise"])
|
||||
.current_dir("tests/fixture/state")
|
||||
.assert()
|
||||
.code(0);
|
||||
}
|
||||
// Running `init` after a successful initialization.
|
||||
Cmd::default()
|
||||
.current_dir("tests")
|
||||
.args(&["init"])
|
||||
.output(PartialStderr("`cd rustlings`"))
|
||||
.fail();
|
||||
|
||||
#[test]
|
||||
fn run_single_test_success_with_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"));
|
||||
// Running `init` in the initialized directory.
|
||||
Cmd::default()
|
||||
.current_dir("tests/rustlings")
|
||||
.args(&["init"])
|
||||
.output(PartialStderr("already initialized"))
|
||||
.fail();
|
||||
|
||||
fs::remove_dir_all("tests/rustlings").unwrap();
|
||||
}
|
||||
|
|
11
tests/test_exercises/Cargo.toml
Normal file
11
tests/test_exercises/Cargo.toml
Normal file
|
@ -0,0 +1,11 @@
|
|||
bin = [
|
||||
{ name = "compilation_success", path = "exercises/compilation_success.rs" },
|
||||
{ name = "compilation_failure", path = "exercises/compilation_failure.rs" },
|
||||
{ name = "test_success", path = "exercises/test_success.rs" },
|
||||
{ name = "test_failure", path = "exercises/test_failure.rs" },
|
||||
]
|
||||
|
||||
[package]
|
||||
name = "test_exercises"
|
||||
edition = "2021"
|
||||
publish = false
|
9
tests/test_exercises/exercises/test_failure.rs
Normal file
9
tests/test_exercises/exercises/test_failure.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
fn main() {}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn fails() {
|
||||
assert!(false);
|
||||
}
|
||||
}
|
9
tests/test_exercises/exercises/test_success.rs
Normal file
9
tests/test_exercises/exercises/test_success.rs
Normal file
|
@ -0,0 +1,9 @@
|
|||
fn main() {
|
||||
println!("Output from `main` function");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn passes() {}
|
||||
}
|
19
tests/test_exercises/info.toml
Normal file
19
tests/test_exercises/info.toml
Normal file
|
@ -0,0 +1,19 @@
|
|||
format_version = 1
|
||||
|
||||
[[exercises]]
|
||||
name = "compilation_success"
|
||||
test = false
|
||||
hint = ""
|
||||
|
||||
[[exercises]]
|
||||
name = "compilation_failure"
|
||||
test = false
|
||||
hint = ""
|
||||
|
||||
[[exercises]]
|
||||
name = "test_success"
|
||||
hint = ""
|
||||
|
||||
[[exercises]]
|
||||
name = "test_failure"
|
||||
hint = "The answer to everything: 42"
|
Loading…
Reference in a new issue