Skip to content

Commit

Permalink
Add Rust readme test (#1241)
Browse files Browse the repository at this point in the history
  • Loading branch information
eike-hass authored Jan 26, 2024
1 parent 2252c8b commit 5e8953e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ jobs:
parallel -k -j 4 --retries 3 --joblog report.log ./target/release/examples/{}
cat report.log
- name: Run Rust Readme examples
# run examples only on ubuntu for now
if: matrix.os == 'ubuntu-latest'
run: |
cd bindings/wasm
npm ci
npm run test:readme:rust
- name: Tear down private tangle
if: matrix.os == 'ubuntu-latest' && always()
uses: './.github/actions/private-tangle/tear-down'
Expand Down
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ See the [instructions](https://github.com/iotaledger/hornet/tree/develop/private

_Cargo.toml_

<!--
Test this example using https://github.com/anko/txm: `txm README.md`
!test program
cd ../..
mkdir tmp
cat | sed -e 's#identity_iota = { version = "[^"]*"#identity_iota = { path = "../identity_iota"#' > tmp/Cargo.toml
echo '[workspace]' >>tmp/Cargo.toml
-->
<!-- !test check Cargo Example -->

```toml
[package]
name = "iota_identity_example"
Expand All @@ -77,10 +88,25 @@ edition = "2021"
identity_iota = {version = "1.0.0", features = ["memstore"]}
iota-sdk = { version = "1.0.2", default-features = true, features = ["tls", "client", "stronghold"] }
tokio = { version = "1", features = ["full"] }
anyhow = "1.0.62"
rand = "0.8.5"
```

_main._<span></span>_rs_

<!--
Test this example using https://github.com/anko/txm: `txm README.md`
!test program
cd ../..
mkdir tmp/src
cat > tmp/src/main.rs
cd tmp
timeout 360 cargo build || (echo "Process timed out after 360 seconds" && exit 1)
-->
<!-- !test check Rust Example -->


```rust,no_run
use identity_iota::core::ToJson;
use identity_iota::iota::IotaClientExt;
Expand Down
1 change: 1 addition & 0 deletions bindings/wasm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"test:browser:parallel": "npm run build:examples:web && cypress-parallel -s test:browser -t 4 -d cypress/e2e -a '\"--quiet\"'",
"test:browser": "cypress run --headless",
"test:readme": "mocha ./tests/txm_readme.js --retries 3 --timeout 180000 --exit",
"test:readme:rust": "mocha ./tests/txm_readme_rust.js --retries 3 --timeout 360000 --exit",
"test:unit:node": "ts-mocha -p tsconfig.node.json ./tests/*.ts --parallel --exit",
"cypress": "cypress open",
"fmt": "dprint fmt"
Expand Down
22 changes: 18 additions & 4 deletions bindings/wasm/tests/txm_readme.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
const { execSync } = require("child_process");
const assert = require("assert");
const spawn = require("child_process").spawn;

describe("Test TXM", function() {
it("README examples pass", async () => {
execSync("txm README.md");
describe("Test TXM", () => {
before((done) => {
let process = spawn("txm", ["README.md"]);
process.stdout.on("data", function(data) {
console.log(data.toString());
});
process.stderr.on("data", function(data) {
console.log(data.toString());
});
process.on("exit", (code) => {
exitCode = code;
done();
});
});
it("exit code should be zero", () => {
assert.equal(exitCode, 0);
});
});
21 changes: 21 additions & 0 deletions bindings/wasm/tests/txm_readme_rust.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const assert = require("assert");
const spawn = require("child_process").spawn;

describe("Test TXM", () => {
before((done) => {
let process = spawn("txm", ["../../README.md"]);
process.stdout.on("data", function(data) {
console.log(data.toString());
});
process.stderr.on("data", function(data) {
console.log(data.toString());
});
process.on("exit", (code) => {
exitCode = code;
done();
});
});
it("exit code should be zero", () => {
assert.equal(exitCode, 0);
});
});

0 comments on commit 5e8953e

Please sign in to comment.