cargo-expand
インストール
code:sh
$ cargo install cargo-expand
使い方
本番コードを展開する : cargo expand
テストコードを展開する : cargo expand --test
ライブラリコードを展開する: cargo expand --lib
実際に動かす radish-miyazaki.icon
展開前
code:rs
mod tests {
use rstest::{fixture, rstest};
fn 任意のフィクスチャ名() -> i32 {
42
}
fn 任意の関数名(任意のフィクスチャ名: i32) {
assert_eq!(任意のフィクスチャ名 * 2, 84);
}
}
展開後
展開後も fn 任意のフィクスチャ名() は残っているので、明示的に呼び出すことが可能
code:rs
use std::prelude::rust_2021::*;
extern crate std;
mod tests {
use rstest::{fixture, rstest};
struct 任意のフィクスチャ名 {}
impl 任意のフィクスチャ名 {
pub fn get() -> i32 {
任意のフィクスチャ名()
}
pub fn default() -> i32 {
Self::get()
}
}
fn 任意のフィクスチャ名() -> i32 {
{ 42 }
}
extern crate test;
pub const 任意の関数名: test::TestDescAndFn = test::TestDescAndFn {
desc: test::TestDesc {
name: test::StaticTestName(
"tests::\u{4efb}\u{610f}\u{306e}\u{95a2}\u{6570}\u{540d}",
),
ignore: false,
ignore_message: ::core::option::Option::None,
source_file: "rstest-example/src/lib.rs",
start_line: 11usize,
start_col: 8usize,
end_line: 11usize,
end_col: 14usize,
compile_fail: false,
no_run: false,
should_panic: test::ShouldPanic::No,
test_type: test::TestType::UnitTest,
},
testfn: test::StaticTestFn(
|| test::assert_test_result(任意の関数名()),
),
};
fn 任意の関数名() {
fn 任意の関数名(任意のフィクスチャ名: i32) {
{
match (&(任意のフィクスチャ名 * 2), &84) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(
kind,
&*left_val,
&*right_val,
::core::option::Option::None,
);
}
}
};
}
}
let 任意のフィクスチャ名 = 任意のフィクスチャ名::default();
任意の関数名(任意のフィクスチャ名)
}
}
pub fn main() -> () {
extern crate test;
}