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
100
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
CDKで始めるTypeScript開発のススメ
tsukuboshi
1
400
プロポーザルに込める段取り八分
shoheimitani
1
230
2026年、サーバーレスの現在地 -「制約と戦う技術」から「当たり前の実行基盤」へ- /serverless2026
slsops
2
240
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
180
今日から始めるAmazon Bedrock AgentCore
har1101
4
410
Greatest Disaster Hits in Web Performance
guaca
0
230
15 years with Rails and DDD (AI Edition)
andrzejkrzywda
0
190
Amazon Bedrock Knowledge Basesチャンキング解説!
aoinoguchi
0
140
変化するコーディングエージェントとの現実的な付き合い方 〜Cursor安定択説と、ツールに依存しない「資産」〜
empitsu
4
1.4k
30万人の同時アクセスに耐えたい!新サービスの盤石なリリースを支える負荷試験 / SRE Kaigi 2026
genda
4
1.3k
Contract One Engineering Unit 紹介資料
sansan33
PRO
0
13k
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
3.8k
Featured
See All Featured
Technical Leadership for Architectural Decision Making
baasie
1
240
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
1
440
Into the Great Unknown - MozCon
thekraken
40
2.3k
Faster Mobile Websites
deanohume
310
31k
The untapped power of vector embeddings
frankvandijk
1
1.6k
Building Applications with DynamoDB
mza
96
6.9k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
How Software Deployment tools have changed in the past 20 years
geshan
0
32k
Accessibility Awareness
sabderemane
0
51
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
140
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, }