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.5k
TRICK 2025 Results
mame
0
5.9k
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
140
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
Simple Storage Service(S3) is not simple
iwatsukayura
0
110
App Storeの外へ──日本のiOSサイドローディング入門 for iOSDC Japan 2026
yuukiw00w
0
280
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
200
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
180
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
260
JRuby: Past, Present, and Future
headius
0
210
Are APIs Still Relevant in the AI Era?
soyuka
0
380
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
320
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
410
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
600
Turning Architecture into Unit Tests in the AI Era (NSSpain XIV)
steliosf
PRO
1
120
巨大モノリシックアプリ モダン化大作戦
ktcryomm
1
1.2k
Featured
See All Featured
How GitHub (no longer) Works
holman
316
150k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
420
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
3
4.3k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
310
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
600
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
66k
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
320
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 のカバレッジデータを蓄積しているファイル