3 ms·
Testing Dolt using BATS (Bash Automated Testing System)
- HankB99 7y agoApologies if this is a dumb question. I glanced at the linked document and it is not obvious to me if this is for testing bash or for testing bash scripts.
- dejj 7y agoIt's for writing tests that look like bash scripts. I wonder if `shellcheck` can still save the day on them.
- inopinatus 7y agoNeither. It’s called that because it’s using a dialect/DSL of bash. It’s a general unit test tool, but working in bash orients Bats towards testing of scripted/automated infrastructure. I’ve used it for tests of Chef/Puppet configuration and found Bats a good fit. Seems odd to find it used as the test framework for a data management tool but clearly it floats their boat.
- verdverm 7y agoBATS is a testing framework, written in bash. https://github.com/bats-core/bats-core https://github.com/bats-core/bats-core It's really nice for when you want to run/test a bunch of things in bash and have nice output and test suites.
- dang 7y agoRelated from last year: https://news.ycombinator.com/item?id=19220094 https://news.ycombinator.com/item?id=19220094 2011: https://news.ycombinator.com/item?id=3408934 https://news.ycombinator.com/item?id=3408934 (Links for the curious. Reposts are ok after a year: https://news.ycombinator.com/newsfaq.html https://news.ycombinator.com/newsfaq.html)
- alpb 7y agoI'm a BIG FAN of BATS (https://github.com/bats-core/bats-core https://github.com/bats-core/bats-core) however sadly BATS is no longer being maintained ––good thing it's still working.
- AdmiralAsshat 7y ago>however sadly BATS is no longer being maintained Are you sure? https://github.com/bats-core/bats-core/issues/266 https://github.com/bats-core/bats-core/issues/266
- alpb 7y agoLooks like it was finally forked https://github.com/sstephenson/bats/issues/150 https://github.com/sstephenson/bats/issues/150
- andrewl-hn 7y agoI used it for a big project about two years ago, and between it and Shellcheck I had pretty good time maintaining a relatively large Bash codebase (we're talking tens of thousands of lines of code across several distinct components). Initially I was skeptical, and tried using Node and Mocha for writing tests instead, but calling shell from other languages is pretty cumbersome, and at some point that became very annoying. I gave Bats a try and was pleasantly surprised. Once one gets used to it Shell is a really good language if the large chunk of your work is calling out external processes and passing the outputs between them. Sure, some language design choices of Shell are arcane and subpar, but with tools like Bats and Shellcheck it's possible to reach comparable levels of developer ergonomics that we all got used to with more popular languages.
- kohtatsu 7y agoBless you <3 Lots of bash hate on HN today. Shellcheck is the training wheels bash deserves, if you're learning it's indispensable just to harass you for quoting. https://shellcheck.net/ https://shellcheck.net/
- deforciant 7y agoUsed it many years ago and I must admit that while it's easy to start with you can end up with super weird bugs down the line where the only option can be to fork and fix it (after/if you find the issue) :) wouldn't use it again when there are maintained alternatives. Nowadays I just write these integration tests in Go since quite often it's handy to use api client libs to verify some data or prepare some fixtures.
- oweiler 7y agoWhat I've learned from writing a Bash testing framework: Bash is inherently untestable. The only way to reliably return something besides a status code is via globals. That means that most functions already rely on previously set global state. Which is one of the reasons that Bash scripts don't scale (the other is non-existent error handling). Do yourself a favor and use a proper scripting language.
- kohtatsu 7y agoPass-by-global is awful. Make smaller functions that return (echo) a single string. Your bash is untestable, but that's just because of your chosen abstractions. Bash is just a proper script language with a weird string and implicit IO system. Disclaimer: I stick to POSIX sh but same difference.
- birdyrooster 7y agoOnly very tangentially related: https://batstrafficsolutions.com/ https://batstrafficsolutions.com/
- saagarjha 7y agoBATS also happens to be the name of an Apple internal testing platform, interestingly.