lots of exercises in java... from https://github.com/exercism/java

insert-ignores.sh 864B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env bash
  2. for file in `find . -name "*Test.java"`; do
  3. tempfile="/tmp/insert-ignores.tmp"
  4. echo -e "\n\n\n*** $file ******************************"
  5. #ignoreFound variable will check if already Ignore is imported or not.
  6. ignoreFound=`grep -q 'import org.junit.Ignore;' $file ; echo $?` > /dev/null
  7. #if ignore is not imported then add line for import
  8. if [ $ignoreFound -ne 0 ]
  9. then
  10. cat $file | sed 's/import org.junit.Test;/import org.junit.Test;\
  11. import org.junit.Ignore;/' > $tempfile
  12. mv "$tempfile" "$file"
  13. pwd
  14. fi
  15. # This AWK code will check for missing Ignore with the @Test and add it
  16. awk 'BEGIN{igonreset=0;firsttest=1}{if($0~/.*@Ignore.*/){igonreset=1}if($0 ~ /^.*@Test/){if(igonreset!=1 && firsttest==0){print " @Ignore(\"Remove to run test\")";}firsttest=0;igonreset=0}print $0}' $file > $tempfile
  17. mv "$tempfile" "$file"
  18. done