Skip to content

Commit bf8904e

Browse files
Merge #88
88: Test the README.md examples r=matthiasbeyer a=matthiasbeyer Inspired by #86 We can actually test the `README.md`! Here is a PR that implements that. Co-authored-by: Matthias Beyer <mail@beyermatthias.de>
2 parents 72e8e0d + 086b0d6 commit bf8904e

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ jobs:
5959
with:
6060
command: test
6161
args: --all --all-features
62+
- name: cargo-test-doc
63+
uses: actions-rs/cargo@v1
64+
with:
65+
command: test
66+
args: --doc
6267

6368

6469
deny:

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ rexpect = "0.5"
3333

3434
Simple example for interacting via ftp:
3535

36-
```rust
36+
```rust,no_run
3737
use rexpect::spawn;
3838
use rexpect::error::*;
3939
40-
fn do_ftp() -> Result<()> {
40+
fn do_ftp() -> Result<(), Error> {
4141
let mut p = spawn("ftp speedtest.tele2.net", Some(30_000))?;
4242
p.exp_regex("Name \\(.*\\):")?;
4343
p.send_line("anonymous")?;
@@ -60,11 +60,11 @@ fn main() {
6060

6161
### Example with bash and reading from programs
6262

63-
```rust
63+
```rust,no_run
6464
use rexpect::spawn_bash;
6565
use rexpect::error::*;
6666
67-
fn do_bash() -> Result<()> {
67+
fn do_bash() -> Result<(), Error> {
6868
let mut p = spawn_bash(Some(2000))?;
6969
7070
// case 1: wait until program is done
@@ -110,11 +110,11 @@ goes into nirvana. There are two functions to ensure that:
110110

111111

112112

113-
```rust
113+
```rust,no_run
114114
use rexpect::spawn_bash;
115115
use rexpect::error::*;
116116
117-
fn do_bash_jobcontrol() -> Result<()> {
117+
fn do_bash_jobcontrol() -> Result<(), Error> {
118118
let mut p = spawn_bash(Some(1000))?;
119119
p.execute("ping 8.8.8.8", "bytes of data")?;
120120
p.send_control('z')?;

src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,7 @@ pub mod session;
7171

7272
pub use reader::ReadUntil;
7373
pub use session::{spawn, spawn_bash, spawn_python, spawn_stream};
74+
75+
// include the README.md here to test its doc
76+
#[doc = include_str!("../README.md")]
77+
mod test {}

0 commit comments

Comments
 (0)