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
97
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
今この時代に技術とどう向き合うべきか
gree_tech
PRO
2
2.2k
Azureコストと向き合った、4年半のリアル / Four and a half years of dealing with Azure costs
aeonpeople
1
270
JSConf JPのwebsiteをGatsbyからNext.jsに移行した話 - Next.jsの多言語静的サイトと課題
leko
2
180
難しいセキュリティ用語をわかりやすくしてみた
yuta3110
0
380
初めてのDatabricks Apps開発
taka_aki
1
260
それでも私が品質保証プロセスを作り続ける理由 #テストラジオ / Why I still continue to create QA process
pineapplecandy
0
170
Copilot Studio ハンズオン - 生成オーケストレーションモード
tomoyasasakimskk
0
210
AWS UG Grantでグローバル20名に選出されてre:Inventに行く話と、マルチクラウドセキュリティの教科書を執筆した話 / The Story of Being Selected for the AWS UG Grant to Attending re:Invent, and Writing a Multi-Cloud Security Textbook
yuj1osm
1
130
混合雲環境整合異質工作流程工具運行關鍵業務 Job 的經驗分享
yaosiang
0
160
Introduction to Sansan for Engineers / エンジニア向け会社紹介
sansan33
PRO
5
43k
Okta Identity Governanceで実現する最小権限の原則 / Implementing the Principle of Least Privilege with Okta Identity Governance
tatsumin39
0
170
AIエージェント入門 〜基礎からMCP・A2Aまで〜
shukob
1
160
Featured
See All Featured
Building a Modern Day E-commerce SEO Strategy
aleyda
44
7.8k
RailsConf 2023
tenderlove
30
1.3k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.2k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
190
55k
Done Done
chrislema
185
16k
Raft: Consensus for Rubyists
vanstee
140
7.2k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
The Art of Programming - Codeland 2020
erikaheidi
56
14k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.5k
The Straight Up "How To Draw Better" Workshop
denniskardys
238
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, }