In theory, we’re never supposed to reinvent the wheel. In theory, we’re supposed to fix things correctly.
Well, as Yogi Berra allegedly said, the difference between theory and practice is that, in theory, there is no difference…
Some time ago I got involved in the Test262 project (you should too!) and, one thing leading to another, I signed myself up to make the Chromium project’s test runners work with a new version of Test262’s test cases.
The test cases had switched from a custom metadata format to YAML, a well-designed and well-supported format. Well-supported, that is, except in every python installation on each of the thousands of machines that the Chromium project uses to run its distributed testing. Because py-YAML is not distributed with python, it’s not safe to use for the Chromium test runner.
So I wrote a fallback, in case py-YAML is not installed. I wrote my own, very rough, parser that parses a subset of YAML — the subset Test262 uses — and returns the same results. The test suite looks a lot like this:
def test_es5id(self): y = "es5id: 220.127.116.11-4-102" self.assertEqual(monkeyYaml.load(y), yaml.load(y))
Set up a string, and then ensure that my parser (monkeyYaml) returns the same result as the real YAML parser. This way I can ensure that my parser functions as a drop-in replacement.
I’m pleased to say that this hideous hack was recently incorporated into the official test262 repository. Because sometimes a hideous hack that reinvents the wheel is exactly the right thing…