Skip to content

Instantly share code, notes, and snippets.

@stephanos
Last active December 29, 2015 13:39
Show Gist options
  • Save stephanos/7678810 to your computer and use it in GitHub Desktop.
Save stephanos/7678810 to your computer and use it in GitHub Desktop.
convert JUnit assertions to simple Spock comparisions
junit2spock() {
local file="$1"
if [ -e "$file" ]
then
echo "converting file '$file'"
else
echo "file '$file' was not found"
fi
perl -i -pe 's|assertTrue\(([^";]+)\);|\1|g' $file
perl -i -pe 's|assertFalse\(([^";]+)\);|\1 == false|g' $file
perl -i -pe 's|assertNull\(([^";]+)\);|\1 == null|g' $file
perl -i -pe 's|assertNotNull\(([^";]+)\);|\1 != null|g' $file
local varMatch="a-zA-Z0-9_\.\(\)\[\]"
local eqRegex="([$varMatch]+(?:\((?:[$varMatch]+(?:\s*,\s*[$varMatch]+)*)?\))?)"
perl -i -pe "s|assertEquals\(\s*$eqRegex\s*,\s*$eqRegex\s*\);|\2 == \1|g" $file
perl -i -pe "s|assertEquals\(\"([^\"]*)\",\s*$eqRegex\s*\);|\2 == \"\1\""|g
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment