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
82
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
非同期推論システムによるコスト削減と信頼性向上
koki_nishihara
0
250
地理空間データ可視化・解析・活用ソリューション Pacific Spatial Solutions (PSS)
pacificspatialsolutions
0
280
LayerXにおけるLLMプロダクト開発の今までとこれから
layerx
PRO
1
260
ワールドカフェI /チューターを改良する / World Café I and Improving the Tutors
ks91
PRO
0
120
エンジニアのキャリアをちょっと楽しくする3本の軸/Three Pillars to Make an Engineer's Career More Enjoyable
kwappa
0
2.7k
どうするコスト最適化のトレードオフ
tetsuyaooooo
1
520
推しは推せるときに推せ! プロダクトにフィードバックしていこう
nakasho
0
310
AWSに詳しくない人でも始められるコスト最適化ガイド
yuhta28
1
230
サーバー間 GraphQL と webmock-graphql の話 / server-to-server graphql and webmock-graphql
qsona
2
190
競技としてのKaggle、役に立つKaggle
yu4u
3
1.4k
ExaDB-D dbaascli で出来ること
oracle4engineer
PRO
0
2.1k
Cloud Native Java with Spring Boot (CNCF Aarhus, April 2024)
thomasvitale
1
170
Featured
See All Featured
Being A Developer After 40
akosma
57
580k
Happy Clients
brianwarren
92
6.4k
Build your cross-platform service in a week with App Engine
jlugia
225
17k
Building Adaptive Systems
keathley
31
1.9k
Music & Morning Musume
bryan
41
5.6k
The Pragmatic Product Professional
lauravandoore
25
5.8k
jQuery: Nuts, Bolts and Bling
dougneiner
59
7.1k
Making the Leap to Tech Lead
cromwellryan
124
8.5k
Thoughts on Productivity
jonyablonski
58
3.8k
The World Runs on Bad Software
bkeepers
PRO
61
6.7k
StorybookのUI Testing Handbookを読んだ
zakiyama
13
4.6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
20
1.9k
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, }