Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
まだ間に合う! Agentic AI on AWSの現在地をやさしく一挙おさらい
minorun365
17
2.4k
AgentCore BrowserとClaude Codeスキルを活用した 『初手AI』を実現する業務自動化AIエージェント基盤
ruzia
7
1.2k
【U/Day Tokyo 2025】Cygames流 最新スマートフォンゲームの技術設計 〜『Shadowverse: Worlds Beyond』におけるアーキテクチャ再設計の挑戦~
cygames
PRO
2
1.4k
M&Aで拡大し続けるGENDAのデータ活用を促すためのDatabricks権限管理 / AEON TECH HUB #22
genda
0
230
『君の名は』と聞く君の名は。 / Your name, you who asks for mine.
nttcom
1
110
20251218_AIを活用した開発生産性向上の全社的な取り組みの進め方について / How to proceed with company-wide initiatives to improve development productivity using AI
yayoi_dd
0
630
意外と知らない状態遷移テストの世界
nihonbuson
PRO
1
220
2025年のデザインシステムとAI 活用を振り返る
leveragestech
0
130
フィッシュボウルのやり方 / How to do a fishbowl
pauli
2
360
ESXi のAIOps だ!2025冬
unnowataru
0
310
[Neurogica] 採用ポジション/ Recruitment Position
neurogica
1
110
2025-12-18_AI駆動開発推進プロジェクト運営について / AIDD-Promotion project management
yayoi_dd
0
150
Featured
See All Featured
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
Applied NLP in the Age of Generative AI
inesmontani
PRO
3
2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.6k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.2k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
33
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
0
22
Heart Work Chapter 1 - Part 1
lfama
PRO
3
35k
We Have a Design System, Now What?
morganepeng
54
7.9k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
260
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
New Earth Scene 8
popppiees
0
1.2k
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, }