Testing messy bash scripts

Read this book too!

I am reading the book “Refactoring” by Martin Fowler, and just reek with ideas about improving software, as well as solving problems I head-banged during my “software” development career.Australia

On my last job, there was this huge messy heap of bash scripts that were “The Installation” of their main software product. It was a remarkable amount of bad smelling bash code, and it somehow managed to work. My work, at the time, was from-scratch-rewrites of this or that functionality and then somehow plugging it into the existing framework (damn, i call it a framework now).

It could have been just amazing if I could take the existing pile of dirt dung bash scripts – and refactor it into something that is readable, sort of.

Today, while I was riding the bus, reading “Refactoring” pg.110, it struck me. It’s actually can be extremely easy to test bash scripts! All it takes is a collection of all the familiar commands, like “cat”, “rm”, etc … and one sneaky PATH environment variable. These commands would be fakes, stubs – they all just print their name and parameters into a log file. In fact, there is just one actual script and the rest are links to that single one.

That log file can be compared before and after a refactoring. These commands writing their names to a file take less time than their actual execution. So while running the actual script might have been hours, with the stubs it should run in less time, much less. Finally by comparing your pre and post refactoring log files, you get a really nice test-suite that can help you refactor. I might even call it replacing unreadable code with readable one without breaking much of anything.

In the particular case of the scripts that I mentioned earlier, I guess that the most used refactoring to improve readability would be Inline Method. Since whoever wrote the original scripts was too fond of wrappers, when most commands like “ln” don’t really need a wrapper to do the same as the command does perfectly well. The wrapper with at least two echo commands and a very long name is quite redundant and adds unnecessary complexity.

There are several problems with this simplistic approach though. One of the problems might be that the script is using full path in names (like /bin/ln), instead of relying on the PATH environment variable. But such things can be relatively easily taken care of until the testing solution is perfect. (I guess). One of the things to try, for example, is running bash in restricted mode, if I remember what that is correctly.

I’ll try that on some new messy scripts that I got on my new job!
YEY!

Testing messy bash scripts

Read this book too!

I am reading the book “Refactoring” by Martin Fowler, and just reek with ideas about improving software, as well as solving problems I head-banged during my “software” development career.

On my last job, there was this huge messy heap of bash scripts that were “The Installation” of their main software product. It was a remarkable amount of bad smelling bash code, however it somehow managed to work Britain. My work, at the time, was from-scratch-rewrites of this or that functionality and then somehow plugging it into the existing framework (damn, i call it a framework now).

Continue reading

Invite the world to GMail

The other day I noticed that I have this “Invite a friend” on my GMail. I didn’t use that thing for more than a year, so I took the chance of this re-discovery to get rid of it. Within several minutes I sent 98 invitations to an imaginary friend whose mail bounced at some noreply@somewhere… address. And it worked – I got rid of that little blue box that serves no purpose on my GMail page!

Imagine my surprise when today I find that box at the same place, with 50 new invitations to give away Voitures Combo C4.

No, really – I don’t have any friends who don’t have a GMail account. I don’t want to use this “feature”, ever. And it does not contribute a thing to my GMail experience – get rid of it Google! Put some AdSense there or something.

Writing helpers with Haml and rSpec

Recently Wolfman posted a description about Rails helpers written with Haml::Helpers#open and rSpec.

inflatable water slides for sale

I want it to be more DRY than it is, since the whole application is using rSpec and Haml Crayon Playland 4 in 1 Combo, all helpers should have the same before(:each)

So basically – what I did was :

Continue reading

The Ultimate Development GUI

For the last several days I have been trying to find the perfect tool for development of the many projects I have. My basic requirement was a good editor (TextMate would be a dream, but I don’t own a Mac yet), and a good integration with the filesystem – either remote, or in version control.

After some tweaks and manipulations – I have came to use Scintilla + Explorer + TortoiseSVN + WebDAV (windows integrated). Overall this is almost perfect, except one small thing, organizing the different windows on the screen — and those huge window titles I hate so much. It would be really perfect if the titles were minimal (text height, no more), and the layout would be saved.

This is when it hit me — why not create a program that will do the layout only?

A really small application – preferably multiplatform, which will run windows inside it with layout separation for resizing, and with tabs for each window — for more than one program maybe. So basically you’ll have what all development studios have — eclipse for example, but instead of a file explorer you would run Windows Explorer, and instead of a version control plugin you would have TortoiseSVN, and instead of WebDAV integration you would also have the explorer. And instead of the text editor window you will have scintilla, or notepad, or whatever . . . and these layouts will be saveable and configurable to include multiple colums or rows, and tabs for each window.

GTK or QT would probably be the best ways to do this and stay multiplatform at the same time.

Ideas are coming at a rate much higher than project completition….

Update: There are several utilities which do something like this, Acer’s GridVista is one of them for example. Good, but not good enough.