dimanche 17 février 2019

Testing bash scripts function by function

I'm maintaining one huge bash script, written by many people over time. The whole script is set of many functions that are executed one after another when the script is run ( some logic before determining on what OS its running, some variables and so on ).

I'm looking for a way to test each function ( without going over it manually each time ), some framework that would load the whole script, and allow me to write test s for each function passing to it different variables, manipulating variables and so on..

For example. There is a function "check_file" this function go over files ( that are stored in variable at start of the script ), and do some changes to a file ( adds a word after specific word, adds a whole line with parameters if its not there and so on ) and than moves on to another function... this function also use another "helper" functions that are somewhere in the script... ( so it can't be taken out on its own )

I would need to make a test, that would pass different files ( set of test files with possible variations that could occur ) and observe output if the files were changed correctly

above is just and example but something like that. I really would not like to start inventing wheel again if something like that exist already.

Aucun commentaire:

Enregistrer un commentaire