I'm working on a project where we deploy our software to Linux machines. This involves a whole load of Bash, for example, the init scripts (e.g. service foo start
for SysVinit. My big concern is that we don't test these the way we test the application layer code with JUnit, FindBugs etc as part of our CI pipeline. What solutions are usually relied upon here? Is it possible to test and analyse these low level Linux scripts the way we would the app layer code?
Asked
Active
Viewed 504 times
1

Boon
- 1,073
- 1
- 16
- 42
-
See http://shellcheck.net/ for static analysis. – Charles Duffy Jan 31 '16 at 23:16
-
...however, inasmuch as this is a request for pointers to off-site resources, it's explicitly off-topic per the rules. – Charles Duffy Jan 31 '16 at 23:17
-
...see item #4 in the list of always-off-topic items given in http://stackoverflow.com/help/on-topic – Charles Duffy Jan 31 '16 at 23:19
-
There is that, but it's coupled to seeking how others approach this. Perhaps "What solutions..." could be better phrased. – Boon Jan 31 '16 at 23:23
-
Even as "how do you do X?", that's very much close to "What’s your favorite ______?" from http://stackoverflow.com/help/dont-ask. If the question doesn't have a single canonical answer available to be given, that's similarly weighing against being a good fit. Questions of this type tend to become out-of-date over time (as new tools are built or fall out of maintenance), and to attract a large number of answers with none of them being canonical. – Charles Duffy Jan 31 '16 at 23:44
1 Answers
1
I don't know of any Bash unit test setup, but I did work with a man who was a old-school uber-scripter. He would write tests for his scripts. They consisted of turning on the xtrace (set -x) feature in the script being tested. He would then capture the output from xtrace (+ ...) from each test run/test case and he could grep through that, or parse it otherways, to ensure the correct operations were being performed. Hope that helps.

Michael Albers
- 3,721
- 3
- 21
- 32
-
There *absolutely* are xUnit-style test frameworks for bash. See https://github.com/kward/shunit2/tree/master/source/2.1/src – Charles Duffy Jan 31 '16 at 23:17
-
@CharlesDuffy I didn't say there weren't any, I said I didn't know of any. If there are better setups than what I described, that's fantastic. – Michael Albers Jan 31 '16 at 23:19