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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
Greatest Disaster Hits in Web Performance
guaca
0
230
SREが向き合う大規模リアーキテクチャ 〜信頼性とアジリティの両立〜
zepprix
0
450
こんなところでも(地味に)活躍するImage Modeさんを知ってるかい?- Image Mode for OpenShift -
tsukaman
0
140
生成AI時代にこそ求められるSRE / SRE for Gen AI era
ymotongpoo
5
3.2k
Kiro IDEのドキュメントを全部読んだので地味だけどちょっと嬉しい機能を紹介する
khmoryz
0
190
StrandsとNeptuneを使ってナレッジグラフを構築する
yakumo
1
120
Agile Leadership Summit Keynote 2026
m_seki
1
610
Amazon Bedrock Knowledge Basesチャンキング解説!
aoinoguchi
0
140
Ruby版 JSXのRuxが気になる
sansantech
PRO
0
150
Azure Durable Functions で作った NL2SQL Agent の精度向上に取り組んだ話/jat08
thara0402
0
180
All About Sansan – for New Global Engineers
sansan33
PRO
1
1.3k
学生・新卒・ジュニアから目指すSRE
hiroyaonoe
2
600
Featured
See All Featured
Optimizing for Happiness
mojombo
379
71k
Abbi's Birthday
coloredviolet
1
4.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
430
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
New Earth Scene 8
popppiees
1
1.5k
Navigating Team Friction
lara
192
16k
Principles of Awesome APIs and How to Build Them.
keavy
128
17k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
750
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.6k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
120
YesSQL, Process and Tooling at Scale
rocio
174
15k
Designing Powerful Visuals for Engaging Learning
tmiket
0
230
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, }