Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
The #[test] attribute
Search
Daichi Mukai
July 20, 2019
Technology
0
93
The #[test] attribute
How to generate test binaries by #[test] attributes in Rust
Daichi Mukai
July 20, 2019
Tweet
Share
Other Decks in Technology
See All in Technology
Evolution on AI Agent and Beyond - AGI への道のりと、シンギュラリティの3つのシナリオ
masayamoriofficial
0
130
生成AI活用のROI、どう測る? DMM.com 開発責任者から学ぶ「AI効果検証のノウハウ」 / ROI of AI
i35_267
4
150
OCI Bastionサービス
oracle4engineer
PRO
1
130
AIドリブンのソフトウェア開発 - うまいやり方とまずいやり方
okdt
PRO
9
540
LLMエージェント時代に適応した開発フロー
hiragram
1
380
我々は雰囲気で仕事をしている / How can we do vibe coding as well
naospon
2
210
サービスロボット最前線:ugoが挑むPhysical AI活用
kmatsuiugo
0
190
AWSの最新サービスでAIエージェント構築に楽しく入門しよう
minorun365
PRO
10
600
モノレポにおけるエラー管理 ~Runbook自動生成とチームメンションの最適化
biwashi
0
540
20250818_KGX・One Hokkaidoコラボイベント
tohgeyukihiro
0
130
つくって納得、つかって実感! 大規模言語モデルことはじめ
recruitengineers
PRO
3
550
RAID6 を楔形文字で組んで現代人を怖がらせましょう(実装編)
mimifuwa
0
290
Featured
See All Featured
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
8
890
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3k
Facilitating Awesome Meetings
lara
55
6.5k
Visualization
eitanlees
146
16k
How STYLIGHT went responsive
nonsquared
100
5.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
50
5.5k
GraphQLとの向き合い方2022年版
quramy
49
14k
Site-Speed That Sticks
csswizardry
10
780
How GitHub (no longer) Works
holman
315
140k
Transcript
The The #[test] #[test] attribute attribute
//! test.rs #[test] fn my_test() { assert!(2 + 2 ==
4); }
$ rustc --test test.rs $ ./test running 1 test test
my_test ... ok test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0
どういう仕組み︖ どういう仕組み︖ $ rustc --emit=asm --test rust.rs $ wc -l
test.rs 4 test.rs $ wc -l test.s 2406 test.s
HIR HIR Rust のコンパイル︓ 1. Rust source 2. HIR 3.
MIR 4. LLVM IR 5. Machine code HIR を⾒てみる $ rustc +nightly --test -Z unpretty=hir test.rs
STEP1. RE-EXPORT STEP1. RE-EXPORT どうやって crate root から test_my_priv_func を⾒
るか︖ mod my_priv_func { fn my_priv_func() -> bool { true } #[test] fn test_my_priv_func() { assert!(my_priv_func()); } }
pub にして re-exportする mod my_priv_func { fn my_priv_func() -> bool
{ true } // 正確には少し違う pub fn test_my_priv_func() { assert!(my_priv_func()); } pub mod __test_reexports { pub use super::test_my_priv_func; } }
STEP2. HARNESS GENERATION STEP2. HARNESS GENERATION テスト⽤の main #[main] pub
fn main() { extern crate test; test::test_main_static(&[&path::to::test1, /*...*/]); }
STEP3. TEST OBJECT STEP3. TEST OBJECT GENERATION GENERATION test::TestDesc で
configuration を指定できる pub struct TestDesc { pub name: TestName, pub ignore: bool, pub should_panic: ShouldPanic, pub allow_fail: bool, }