Skip to content

Commit

Permalink
polkadot-sdk-docs: Use command_macro! (#6624)
Browse files Browse the repository at this point in the history
# Description

**Understood assignment:**
Initial assignment description is in #6194.
In order to Simplify the display of commands and ensure they are tested
for chain spec builder's `polkadot-sdk` reference docs, find every
occurrence of `#[docify::export]` where `process:Command` is used, and
replace the use of `process:Command` by `run_cmd!` from the `cmd_lib
crate`.

---------

Co-authored-by: Iulian Barbu <[email protected]>
  • Loading branch information
ndkazu and iulianbarbu authored Dec 10, 2024
1 parent c808a00 commit 19bc578
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 166 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions docs/sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,5 @@ first-pallet = { workspace = true, default-features = true }

[dev-dependencies]
assert_cmd = "2.0.14"
cmd_lib = { workspace = true }
rand = "0.8"
24 changes: 9 additions & 15 deletions docs/sdk/src/guides/your_first_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
#[cfg(test)]
mod tests {
use assert_cmd::Command;
use cmd_lib::*;
use rand::Rng;
use sc_chain_spec::{DEV_RUNTIME_PRESET, LOCAL_TESTNET_RUNTIME_PRESET};
use sp_genesis_builder::PresetId;
Expand Down Expand Up @@ -173,13 +174,10 @@ mod tests {
println!("Building polkadot-sdk-docs-first-runtime...");
#[docify::export_content]
fn build_runtime() {
Command::new("cargo")
.arg("build")
.arg("--release")
.arg("-p")
.arg(FIRST_RUNTIME)
.assert()
.success();
run_cmd!(
cargo build --release -p $FIRST_RUNTIME
)
.expect("Failed to run command");
}
build_runtime()
}
Expand Down Expand Up @@ -274,14 +272,10 @@ mod tests {
let chain_spec_builder = find_release_binary(&CHAIN_SPEC_BUILDER).unwrap();
let runtime_path = find_wasm(PARA_RUNTIME).unwrap();
let output = "/tmp/demo-chain-spec.json";
Command::new(chain_spec_builder)
.args(["-c", output])
.arg("create")
.args(["--para-id", "1000", "--relay-chain", "dontcare"])
.args(["-r", runtime_path.to_str().unwrap()])
.args(["named-preset", "development"])
.assert()
.success();
let runtime_str = runtime_path.to_str().unwrap();
run_cmd!(
$chain_spec_builder -c $output create --para-id 1000 --relay-chain dontcare -r $runtime_str named-preset development
).expect("Failed to run command");
std::fs::remove_file(output).unwrap();
}
build_para_chain_spec_works();
Expand Down
8 changes: 4 additions & 4 deletions docs/sdk/src/reference_docs/chain_spec_genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@
//! ```
//! Here are some examples in the form of rust tests:
//! ## Listing available preset names:
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", list_presets)]
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", cmd_list_presets)]
//! ## Displaying preset with given name
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", get_preset)]
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", cmd_get_preset)]
//! ## Building a solo chain-spec (the default) using given preset
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", generate_chain_spec)]
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", cmd_generate_chain_spec)]
//! ## Building a parachain chain-spec using given preset
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", generate_para_chain_spec)]
#![doc = docify::embed!("./src/reference_docs/chain_spec_runtime/tests/chain_spec_builder_tests.rs", cmd_generate_para_chain_spec)]
//!
//! [`RuntimeGenesisConfig`]:
//! chain_spec_guide_runtime::runtime::RuntimeGenesisConfig
Expand Down
1 change: 1 addition & 0 deletions docs/sdk/src/reference_docs/chain_spec_runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ substrate-wasm-builder = { optional = true, workspace = true, default-features =

[dev-dependencies]
chain-spec-builder = { workspace = true, default-features = true }
cmd_lib = { workspace = true }
sc-chain-spec = { workspace = true, default-features = true }

[features]
Expand Down
Loading

0 comments on commit 19bc578

Please sign in to comment.