-<!doctype html><html lang=en><head><meta content="IE=edge" http-equiv=X-UA-Compatible><meta content="text/html; charset=utf-8" http-equiv=content-type><meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name=viewport><title>A short and satisfying bug hunt</title><link href=https://learnbyexample.github.io/atom.xml rel=alternate title=RSS type=application/atom+xml><script src=https://cdnjs.cloudflare.com/ajax/libs/slideout/1.0.1/slideout.min.js></script><link href=https://learnbyexample.github.io/site.css rel=stylesheet><meta content=learnbyexample property=og:title><meta content=website property=og:type><meta content="Learn Python, Regex, Linux, Scripting, Vim, Ebooks, Self-Publishing and Interesting Tech Nuggets." property=og:description><meta content=https://learnbyexample.github.io property=og:url><meta content=https://learnbyexample.github.io/images/learnbyexample.png property=og:image><meta content=1280 property=og:image:width><meta content=640 property=og:image:height><meta content=summary_large_image property=twitter:card><meta content=@learn_byexample property=twitter:site><link href=https://learnbyexample.github.io/favicon.svg rel=icon><link rel="shortcut icon" href=https://learnbyexample.github.io/favicon.png><body><div class=container><div class=mobile-navbar id=mobile-navbar><div class=mobile-header-logo><a class=logo href=/>learnbyexample</a></div><div class="mobile-navbar-icon icon-out"><span></span><span></span><span></span></div></div><nav class="mobile-menu slideout-menu slideout-menu-left" id=mobile-menu><ul class=mobile-menu-list><li class=mobile-menu-item><a href=https://learnbyexample.github.io/books> Books </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/mini> Mini </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tips> Tips </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/tags> Tags </a><li class=mobile-menu-item><a href=https://learnbyexample.github.io/about> About </a></ul></nav><header id=header><div class=logo><a href=https://learnbyexample.github.io>learnbyexample</a></div><nav class=menu><ul><li><a href=https://learnbyexample.github.io/books> Books </a><li><a href=https://learnbyexample.github.io/mini> Mini </a><li><a href=https://learnbyexample.github.io/tips> Tips </a><li><a href=https://learnbyexample.github.io/tags> Tags </a><li><a href=https://learnbyexample.github.io/about> About </a></ul></nav></header><main><div class=content id=mobile-panel><div class=post-toc id=post-toc><h2 class=post-toc-title>Contents</h2><div class="post-toc-content always-active"><nav id=TableOfContents><ul><li><a class=toc-link href=https://learnbyexample.github.io/a-short-and-satisfying-bug-hunt/#the-surprise>The surprise</a><li><a class=toc-link href=https://learnbyexample.github.io/a-short-and-satisfying-bug-hunt/#creating-minimal-failing-case>Creating minimal failing case</a><li><a class=toc-link href=https://learnbyexample.github.io/a-short-and-satisfying-bug-hunt/#tl-dr>TL;DR</a></ul></nav></div></div><article class=post><header class=post__header><h1 class=post__title><a href=https://learnbyexample.github.io/a-short-and-satisfying-bug-hunt/>A short and satisfying bug hunt</a></h1><div class=post__meta><span class=post__time>2019-03-06</span></div></header><div class=post-content><h2 id=the-surprise>The surprise<a aria-label="Anchor link for: the-surprise" class=zola-anchor href=#the-surprise>🔗</a></h2><p>So, a pleasant surprise awaited me last Sunday. As is my usual habit, I opened my <a href=https://github.com/learnbyexample>github</a> account after breakfast to see if I've got any sudden spurt in traffic. And as usual, things were normal. Except for the blue notification, which was rare. I hoped it wasn't a silly pull request and thankfully it was a <a href=https://github.com/learnbyexample/Command-line-text-processing/issues/24>new issue</a> that was opened.</p><span id=continue-reading></span><p>I gave the issue a cursory glance and wrongly guessed it was probably some line ending issue (user was on Windows OS). As someone who has seen plenty of bugs in previous job, I wasn't ruling out anything though. I first cloned the repo so as to try to recreate the working environment without possible interference from my local working copy. As the user had provided detailed information while opening the issue, I was able to quickly replicate it. Sure enough, I was seeing the same problem. I only wondered why it wasn't brought to my attention before. Either past users chose not to or things weren't interesting enough to reach that far in the exercises.<h2 id=creating-minimal-failing-case>Creating minimal failing case<a aria-label="Anchor link for: creating-minimal-failing-case" class=zola-anchor href=#creating-minimal-failing-case>🔗</a></h2><p>As I had written the <a href=https://github.com/learnbyexample/Command-line-text-processing/blob/master/exercises/GNU_grep/solve>solution checker script</a> about 2 years back, the script looked alien. Right from cloning the repo, I had to fight the urge to improve things. By the time I spotted the issue, all such fantasies were thrown out. Replaced by a todo note to <em>someday</em> write automated testing script to check that my script is indeed working properly for all the exercises.<p>To put it simply, the role of <code>solve</code> script is to check if the previous command executed by the user solves the current exercise question. To do so, the script gets the previous command from history and compares the output of that command and a reference solution present in the exercise directory. Sounds simple right? Yeah, I thought so too. I do remember testing few cases before I first published it and no one had submitted an issue so far. So, why was it failing now?<p>As mentioned before, I thought it could be some weird line ending issue. But that was effectively ruled out as it was failing for me as well on Linux. Still, I did check for funny characters with <code>cat -A</code>. Nope, no issues there.<pre class=language-bash data-lang=bash style=background-color:#f5f5f5;color:#1f1f1f;><code class=language-bash data-lang=bash><span style=color:#5597d6;>$</span><span> grep</span><span style=color:#5597d6;> -o </span><span style=color:#d07711;>'^[^=]*'</span><span> sample.txt
0 commit comments