Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Ruby Hack Challenge #4 カバレッジ特別回 資料
Search
Yusuke Endoh
June 21, 2018
Programming
66
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ruby Hack Challenge #4 カバレッジ特別回 資料
https://cookpad.connpass.com/event/88471/
Yusuke Endoh
June 21, 2018
More Decks by Yusuke Endoh
See All by Yusuke Endoh
Practical TypeProf: Lessons from Analyzing Optcarrot
mame
1
3.3k
型システムを知りたい人のための型検査器作成入門
mame
15
5.4k
TRICK 2025 Results
mame
0
5.8k
Writing Ruby Scripts with TypeProf
mame
1
1.6k
An Invitation to TRICK: How to write weird Ruby programs
mame
1
1.4k
TypeProf進捗
mame
0
130
12年前の『型システム入門』翻訳の思い出話
mame
14
2.9k
Good first issues of TypeProf
mame
4
10k
Revisiting TypeProf - IDE support as a primary feature
mame
1
4k
Other Decks in Programming
See All in Programming
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1k
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
150
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
480
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
410
How I Stole PSI from Android Studio - DroidKaigi2026
worker8
0
130
Vue Fes Japan 2026 タイムテーブル徹底解説
448jp
1
230
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
180
WebRTC映像をAirPlayに対応させる挑戦.pdf
monolithic_adam
0
280
アクセシビリティから考える情報設計
high_g_engineer
0
380
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
240
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
600
Jetpack Compose メカニズム
skydoves
0
440
Featured
See All Featured
The Curse of the Amulet
leimatthew05
3
15k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Abbi's Birthday
coloredviolet
4
10k
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
530
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
The Pragmatic Product Professional
lauravandoore
37
7.4k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
230
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.2k
Transcript
Cookpad Ruby Hack Challenge #4 カバレッジ特別回 2018/06/23 (Sat.)
事務連絡 • Gitter にお入りください – https://gitter.im/rubyhackchallenge/Lobby – URL やテキストの共有にお使いください •
この資料は slideshare にあります – (あとでリンクにする) • 今日の資料は github にあります – https://github.com/ko1/rubyhackchallenge /blob/master/JA/6_coverage.md
今日の予定 • 13:00~ オープニングと自己紹介 • 13:20~ 講義 • 14:00~ 実習
• 16:30~ 成果発表 • 17:00 解散 ※すでに資料を読んできた人は講義を聞かずに実習を 始めても大丈夫です
今日の内容 • コードカバレッジを参考に Ruby のテストを書く – カバレッジ:どのコードを実行したか・していないか – 例:lib/irb/context.rb –
https://rubyci.s3.amazonaws.com/debian8-coverage/ruby-trunk/lcov/ruby/lib/irb/context.rb.gcov.html 青:実行されている行 赤:実行されていない行 青:elseに 進んだ 赤:thenに 進んでない
今日の内容 • コードカバレッジを参考に Ruby のテストを書く – つまりどういうことかというと…… verbose? メソッド自体は 呼ばれているが
@verbose = nil の 状態で呼ぶテストが 足りない模様
今日の内容 • コードカバレッジを参考に Ruby のテストを書く – 適当にテストを書き足してみる IRB.conf[:VERBOSE] = nil
で @verbose = nil にできるらしい この条件下で verbose? メソッドを呼ぶテスト
今日の内容 • コードカバレッジを参考に Ruby のテストを書く – カバレッジの変化 @verbose.nil? の分岐が then
節に進んだ! then 節に 進んでいなかったのが まだ実行されてない 部分はあるけれども
目次 • Ruby のビルドとテストのやりかた(特急版) • カバレッジの測定方法 – C 言語コード(処理系本体)の部分 –
Ruby コード(標準添付ライブラリ)の部分 • Ruby テストの構成と書き足し方
Ruby のビルドとテストのやり方(特急版) • 依存関係を入れる(Debian 系の場合) – sudo apt-get install git
ruby autoconf bison gcc make zlib1g-dev libffi-dev libreadline-dev libgdbm-dev libssl-dev lcov • ソースを取ってくる – git https://git.ruby-lang.org/ruby.git • ビルドする – cd ruby – autoconf – ./configure --prefix=`pwd`/local – make • テストを実行する – make test-all
カバレッジの測定方法(C言語) • 古いビルド結果を全部消す(重要) – git clean -fxd • ビルド時の configure
にオプションをつける – autoconf – ./configure --prefix=`pwd`/local --enable-gcov – make • テストを実行する – make test-all • カバレッジを可視化する – make lcov – ブラウザで lcov-c-out/index.html を開く
カバレッジの測定方法(Ruby) • 古いビルド結果を全部消す(重要) – git clean –fxd • ビルドは普通にやる –
autoconf – ./configure --prefix=`pwd`/local – make • テストを COVERAGE=true 付きで実行する – make test-all COVERAGE=true – (coverage/index.html で可視化したものが見えるはず) • オプション:LCOV でカバレッジを可視化する – make lcov – ブラウザで lcov-rb-out/index.html を開く
Ruby テストの構成 • Ruby にはいっぱいテストスイートがある – make btest / make
test-all / make test-spec – 遠藤は test-all しかよく知らない • make test-all の実態は test/ ディレクトリ – test/ruby: コアのテスト – test/(標準添付ライブラリ名): ライブラリのテスト – 他にも雰囲気でいろいろ置いてある • 特定のテストファイルだけを実行する方法 – make test-all TESTS=test/irb/test_context.rb – 指定しないと全部実行して遅いので、 テストを書き足したらそのファイルだけ実行してみるとよい
Ruby テストの書き足し方 • カバレッジを見て実行したい箇所の狙いをつける • 試行錯誤を繰り返していろいろ考える – ライブラリのコードを読解し、どうすれば実行できるか – 既存テストを読解し、どのようなテストを書けば良いか
– テストを書いて実行し、当該箇所に徐々に迫っていく • make test-all TESTS=テストファイル で、テストを書き 足したファイルだけ実行すると速い • 毎回カバレッジをとっても良いが、当該箇所付近に出力 コードを突っ込んで print デバッグしたほうが速いかも – (マニュアル化したやり方はない、基本的に気合い)
ポイント:古いビルド結果を消す • C言語コードのテストを書く場合 – C言語コードのカバレッジは、gcc(C コンパイラ)に カバレッジ測定用バイナリを生成させて測定している – ソースコードを編集・リビルドすると、測定結果が おかしなことになる
– C言語コードのテストを書くときは、ハマりたくなければビル ド結果を消す方がよい • Rubyコードのテストを書く場合 – ビルド全体を消す必要はないが、テスト実行のたびに test-coverage.dat ファイルを消す • Ruby のカバレッジデータを蓄積しているファイル