Skip to content

Commit 44a9683

Browse files
Merge #39: ci: Run README examples
255bffb ci: Run README examples (Daniela Brozzoni) Pull request description: Adds a "doctest" feature useful if you want to run the README.md tests. Largely copied from bdk's CI workflow. ACKs for top commit: danielabrozzoni: self-ACK 255bffb Tree-SHA512: c37ee983d7dd43bdb39677facf848eb837b414522d9a8fe46196b9656feb971439a225451329955a2373c2e13488bc1a722077744e319f92aa7d9e003c46778f
2 parents 8285f66 + 255bffb commit 44a9683

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

.github/workflows/main.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,36 @@ jobs:
5555
run: cargo test
5656
- name: Wipe
5757
run: cargo test test_wipe_device -- --ignored
58+
test-readme-examples:
59+
name: Test README.md examples
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: checkout
63+
uses: actions/checkout@v2
64+
- name: cache
65+
uses: actions/cache@v2
66+
with:
67+
path: |
68+
~/.cargo/registry
69+
~/.cargo/git
70+
target
71+
key: ${{ runner.os }}-cargo-test-md-docs-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
72+
- name: Build simulator image
73+
run: docker build -t hwi/ledger_emulator ./ci -f ci/Dockerfile.ledger
74+
- name: Run simulator image
75+
run: docker run --name simulator --network=host hwi/ledger_emulator &
76+
- name: Install Python
77+
uses: actions/setup-python@v4
78+
with:
79+
python-version: '3.9'
80+
cache: 'pip'
81+
- name: Install python dependencies
82+
run: pip install -r requirements.txt
83+
- name: Set default toolchain
84+
run: rustup default nightly
85+
- name: Set profile
86+
run: rustup set profile minimal
87+
- name: Update toolchain
88+
run: rustup update
89+
- name: Test
90+
run: cargo test --features doctest -- doctest::ReadmeDoctests

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ pyo3 = { version = "0.15.1", features = ["auto-initialize"]}
1717

1818
[dev-dependencies]
1919
serial_test = "0.6.0"
20+
21+
[features]
22+
doctest = []

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,37 @@ This library internally uses PyO3 to call HWI's functions. It is not a re-implem
1313
Python 3 is required. The libraries and [udev rules](https://github.com/bitcoin-core/HWI/blob/master/hwilib/udev/README.md) for each device must also be installed. Some libraries will need to be installed
1414

1515
For Ubuntu/Debian:
16-
```
16+
```bash
1717
sudo apt install libusb-1.0-0-dev libudev-dev python3-dev
1818
```
1919

2020
For Centos:
21-
```
21+
```bash
2222
sudo yum -y install python3-devel libusbx-devel systemd-devel
2323
```
2424

2525
For macOS:
26-
```
26+
```bash
2727
brew install libusb
2828
```
2929

3030
## Install
3131

3232
- Clone the repo
33-
```
33+
```bash
3434
git clone https://github.com/bitcoindevkit/rust-hwi.git && cd rust-hwi
3535
```
3636

3737
- Create a virtualenv:
3838

39-
```
39+
```bash
4040
virtualenv -p python3 venv
4141
source venv/bin/activate
4242
```
4343

4444
- Install all the dependencies using pip:
4545

46-
```
46+
```bash
4747
pip install -r requirements.txt
4848
```
4949

@@ -81,4 +81,4 @@ To run the tests, you need to have a hardware wallet plugged in. If you don't ha
8181

8282
Either use a testing device with no funds, or use a simulator.
8383

84-
You can run the tests with `cargo test`.
84+
You can run the tests with `cargo test`.

src/doctest.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Bitcoin Dev Kit
2+
// Written in 2020 by Alekos Filini <alekos.filini@gmail.com>
3+
//
4+
// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers
5+
//
6+
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
7+
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
8+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
9+
// You may not use this file except in accordance with one or both of these
10+
// licenses.
11+
12+
#[doc = include_str!("../README.md")]
13+
#[cfg(doctest)]
14+
pub struct ReadmeDoctests;

src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ extern crate serial_test;
2929

3030
pub use interface::HWIClient;
3131

32+
#[cfg(feature = "doctest")]
33+
pub mod doctest;
3234
pub mod error;
3335
pub mod interface;
3436
pub mod types;

0 commit comments

Comments
 (0)