
Testing Dolt using BATS (Bash Automated Testing System) - timsehn
https://www.dolthub.com/blog/2020-03-23-testing-dolt-bats/
======
oweiler
What 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
Pass-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.

------
alpb
I'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.

~~~
andrewl-hn
I 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
Bless 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/)

------
dang
Related 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))

------
deforciant
Used 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.

------
HankB99
Apologies 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.

~~~
inopinatus
Neither. 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.

------
birdyrooster
Only very tangentially related:
[https://batstrafficsolutions.com/](https://batstrafficsolutions.com/)

------
saagarjha
BATS also happens to be the name of an Apple internal testing platform,
interestingly.

