Skip to content

Commit a0f9106

Browse files
hgvanpariyasjwarner-bp
authored andcommitted
Update insert-ignores.sh to current requirements exercism#1450 (exercism#1455)
1 parent 121e726 commit a0f9106

1 file changed

Lines changed: 33 additions & 11 deletions

File tree

‎scripts/insert-ignores.sh‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,37 @@
11
#!/usr/bin/env bash
22

3+
# This script will add @Ignore for all the testcases except first testcase. It will also add import org.junit.Ignore;, if it will be missing
4+
# post adding @Ignore.
5+
6+
37
for file in `find . -name "*Test.java"`; do
4-
tempfile="/tmp/insert-ignores.tmp"
5-
6-
echo -e "\n\n\n*** $file ******************************"
7-
cat $file | \
8-
sed 's/import org.junit.Test;/import org.junit.Test;\
9-
import org.junit.Ignore;/' | \
10-
sed 's/@Test/@Ignore\
11-
@Test/' | \
12-
sed '1,/@Ignore/s/.*@Ignore//' > "$tempfile" \
13-
&& mv "$tempfile" "$file"
14-
done
158

9+
tempfile="/tmp/insert-ignores.tmp"
10+
11+
echo -e "\n\n\n*** $file ******************************"
12+
13+
14+
## This AWK code will check for missing Ignore with the @Test and add it
15+
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+
19+
## Checking if @Ignore is added. If @Ignore is added then only import org.junit.Ignore; will be added
20+
ignoreAdded=`grep -q '@Ignore' $file ; echo $?` > /dev/null
21+
22+
if [ $ignoreAdded -eq 0 ]
23+
then
24+
#ignoreFound variable will check if already Ignore is imported or not.
25+
ignoreFound=`grep -q 'import org.junit.Ignore;' $file ; echo $?` > /dev/null
26+
27+
#if ignore is not imported then add line for import
28+
if [ $ignoreFound -ne 0 ]
29+
then
30+
cat $file | sed 's/import org.junit.Test;/import org.junit.Test;\
31+
import org.junit.Ignore;/' > $tempfile
32+
mv "$tempfile" "$file"
33+
pwd
34+
fi
35+
fi
36+
37+
done

0 commit comments

Comments
 (0)