作者以一场题为"Go Testing By Example"的演讲拉开了 GopherCon Australia 的序幕,由于音视频设备出现问题,该演讲后来在家中重新录制并发布到了网上。这场演讲介绍了改进 Go 测试的 20 条技巧,涵盖诸如让测试用例易于添加、明智地使用覆盖率、将测试用例与测试逻辑分离,以及使用 txtar 和 rsc.io/script 等工具的实践。作者在结尾鼓励开发者不断改进他们的测试,并以持续部署为目标。
I opened GopherCon Australia in early November with the talk “Go Testing By Example”.
Being the first talk, there were some A/V issues, so I re-recorded it at home and have posted it here:
Here are the 20 tips from the talk:
Make it easy to add new test cases.
继续阅读全文
为了尊重作者,这里只展示开头几段。你可以去原文阅读,或者在 HorizonReader 里读:划线做笔记、让 AI 帮忙。
AI 摘要This post proves the correctness of uscale, a fast unrounded scaling algorithm based on a 64×128-bit multiplication and floating-point approximation, which underlies the author's floating-point printing and parsing algorithms (FixedWidth, Short, and Parse). The proof proceeds through a series of lemmas handling exact results, small positive and negative powers, and finally the large-power cases, which cannot be exhaustively tested directly. For those large-power cases, the author uses the Ivy calculator—an APL-inspired language with arbitrary-precision rationals and right-to-left precedence—to implement a two-step approach, loosely following work by Vern Paxson and Tim Peters, that solves a 'modular search' problem to find the first satisfying value and a 'modular minimum' problem to verify all relevant inputs.
AI 摘要This article presents fast floating-point printing and parsing algorithms built on a new primitive called fast unrounded scaling, which approximates scaling by powers of ten, often in a single 64-bit multiplication. These simple algorithms reportedly outperform all prior known methods, including Dragon4, Grisu3, Ryū, Schubfach, and Dragonbox, and the author plans to include a Go implementation in Go 1.27. The post walks through the necessary concepts (fixed-point and floating-point numbers, unrounded numbers) and outlines implementations for fixed-width and shortest-width printing as well as decimal parsing.
AI 摘要This article is a reply to Donald Knuth's 1989 paper on proving the correctness of a program that converts 16-bit fixed-point binary fractions to their shortest accurate decimal representations, written in honor of Knuth's 88th birthday. The author presents what they argue is a better proof of Knuth's program P2 by starting with a simpler program that has a trivial direct correctness proof—implemented in the APL-like Ivy language—and then transforming it into P2 step by step, proving each transformation correct. The post also explores alternative solutions and concludes with reflections on how language and notation shape programs and proofs.
AI 摘要The article introduces the 'Floating Point Formatting' blog series, which began in 2011 and continued with new posts in 2026. It lists four posts covering topics such as floating-point to decimal conversion, a proof inspired by Knuth's fixed-point printer, simple and fast floating-point printing and parsing, and a proof of fast unrounded scaling verified with Ivy.
AI 摘要The article describes 'differential coverage', a debugging technique that compares the code coverage profile of a failing test with those of passing tests to isolate code blocks unique to the failing case. Demonstrating in Go, the author diffs two coverage profiles and views the result with go tool cover -html, successfully narrowing an injected bug down to 10 lines among over 15,000. While not foolproof (e.g., data-dependent bugs or insensitive tests can evade it), the technique is cheap to compute and can save considerable debugging time.