Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

1.6 Testing : Test should pass rather than fail

Aperta
#243 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
rust

Direzione di ricerca

Inizia con il tutorial sui test collegato nell’issue e con il test CLI mostrato, quindi esegui cargo test --test cli per riprodurre la discrepanza. Confronta l’asserzione con lo stderr riportato dal comando e modifica l’esempio in modo che il test corrisponda all’errore documentato; il lavoro è concluso quando il test segnala un test superato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Below test with more description can be found at

use assert_cmd::prelude::*; // Add methods on commands
use predicates::prelude::*; // Used for writing assertions
use std::process::Command; // Run programs

#[test]
fn file_doesnt_exist() -> Result<(), Box<dyn std::error::Error>> {
    let mut cmd = Command::cargo_bin("grrs")?;

    cmd.arg("foobar").arg("test/file/doesnt/exist");
    cmd.assert()
        .failure()
        .stderr(predicate::str::contains("could not read file"));

    Ok(())
}

My Expectation:
grss rightly throws the exception when file does not exist. This test should capture the exception and should be pass as it has captured the right exception. But on running 'cargo test', this test is reported as failure.

Current Result:
test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.55s
IMO Expected Result
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.55s

Output of cargo test:
` Running tests/cli.rs (target/debug/deps/cli-5cefbff21b07bd9f)

running 1 test
test file_doesnt_exist ... FAILED

failures:

---- file_doesnt_exist stdout ----
thread 'file_doesnt_exist' panicked at /rustc/07dca489ac2d933c78d3c5158e3f43beefeb02ce/library/core/src/ops/function.rs:250:5:
Unexpected stderr, failed var.contains(could not read file)
├── var: Error: Could not read file 'test/file/doesnt/exists'
│
│ Caused by:
│ No such file or directory (os error 2)
└── var as str: Error: Could not read file 'test/file/doesnt/exists'

Caused by:
    No such file or directory (os error 2)

command="/Users/admin/Kishor/SxT/repos/grrs/target/debug/grrs" "foobar" "test/file/doesnt/exists"
code=1
stdout=""
stderr=```
Error: Could not read file 'test/file/doesnt/exists'

Caused by:
No such file or directory (os error 2)



note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    file_doesnt_exist

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.55s

error: test failed, to rerun pass `--test cli`
`
Lingua principale
Rust
Stelle
1.1k
Fork
122
Merge medio
10h 37m
PR unite (30g)
2

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rust-cli/book

Tutte le issue di rust-cli/book

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.