[OT] svnfind tool (was: Re: [classlib][test] fail statements omitted in many exception catching test cases)

2006-09-28 Thread Mark Hindess

Testing this script reminded me that I'd not mentioned the small script
I wrote after getting feed up typing:

  find path -name .svn -prune -o ...

The script takes:

  svnfind path [path2 ...] ...

and converts it to the previous form so that .svn directories are ignored.

Others might find it useful so I've included it below.

-Mark.

#!/bin/sh

while [ -n $1 ]; do
case $1 in
-*)
break
;;
*)
[EMAIL PROTECTED]$1
;;
esac
shift
done

while [ -n $1 ]; do
[EMAIL PROTECTED]$1
shift
done

if [ -z ${args[0]} ]; then
  args[0]=-print
fi

exec find [EMAIL PROTECTED] -name .svn -prune -o [EMAIL PROTECTED]

On 27 September 2006 at 9:44, Mark Hindess [EMAIL PROTECTED] wrote:
 
 This perl script does a marginally better job by being slightly stricter
 on matching context around 'catch'/'fail', by handling comments slightly
 better and by handling 'catch (...) { }' appearing on a single line.
 
 It also finds a few more hits such as:
 
   sql/src/test/java/org/apache/harmony/sql/tests/java/sql/TimeTest.java +208
 
 which is a false positive but which uses assertTrue(false); which 
 should be fixed anyway.
 
 -Mark.
 
 #!/usr/bin/perl -w
 use strict;
 
 my $previous_line = ;
 my $possible_line_number;
 while () {
   next if (/^\s*$/); # skip blank lines
   if ($possible_line_number) {
 if (m!^\s*(//|/\*|})!) {
   print $ARGV, ' +', $possible_line_number, \n;
 }
 undef $possible_line_number;
   }
   if (!m!^\s*(/?\*|//)!  /\bcatch\s*\(/  $previous_line !~ /\bfail\s*\(/)
  {
 $possible_line_number = $.;
 if (/catch\s*\([^\)]+\)\s*{\s*}/) {
   print $ARGV, ' +', $possible_line_number, \n;
   undef $possible_line_number;
 }
   }
   $previous_line = $_;
 }
 
 On 27 September 2006 at 15:02, Robert Hu [EMAIL PROTECTED] wrote:
  --090601000506020908060004
  Content-Transfer-Encoding: 7bit
  Content-Type: text/plain; charset=GB2312
  
  Hi All,
  
  In our unit test of classlib, there are huge number of test cases about exc
 ep
  tion catching. The typical style of those cases is like that:
  
  try {
  someStatementShouldThrowAnException;
  * fail(Expected an exception);*
  } catch (SomeException e){
  // Expected
  }
  
  If we omit the fail statement, the test case is wrong because the excepti
 on
  -throwing checking is disabled.
  
  I've found that the fail statement is omitted in many test cases of our H
 ar
  mony classlib. So I set some rules to find out all lines of code related wi
 th
   it. If a line of code comform all the 5 rules, it may be a bug:
  1.in a *Test.java file
  2.does not start with //
  3.contains catch
  4.its previous line does not contains fail
  5.its next line contains // or }
  
  
  Then I found out 1711 lines of code in 309 files comform all the 5 rules in
  r
  450321. (Attachment file is the result.)
  Of course not all of them are bug, because some test cases are not of above
  s
  tyle.
  
  And I also find out some real bugs, we can fix them easilly:
  trunk\modules\awt\src\test\api\java\common\java\awt\font\TextLayoutTest.jav
 a:
  652\658\664\670\676\685\698\704\711(line number)
  trunk\modules\luni\src\test\java\org\apache\harmony\tests\java\lang\EnumTes
 t.
  java:57
  trunk\modules\luni\src\test\java\org\apache\harmony\luni\tests\java\io\File
 In
  putStreamTest.java:36
  trunk\modules\luni\src\test\java\org\apache\harmony\luni\tests\java\io\File
 Ou
  tputStreamTest.java:35
  more..
  
  *I must say frankly that it's hard to find out all bugs of this kind withou
 t 
  any victims automatically, we must find out real bugs ourselves.*
  
  Hope the result in attachment file can help us to find out more bugs.
  
  Anybody has better search rules or better solution to find out those bugs? 
 Pl
  s. share with us, thanks a lot.
  
  -- 
  Robert Hu
  China Software Development Lab, IBM
  
  
  --090601000506020908060004
  Content-Type: text/plain;
   name=result.txt
  Content-Disposition: inline;
   filename=result.txt
  Content-Transfer-Encoding: quoted-printable
  
  current position is trunk\modules
  .\archive\src\test\java\org\apache\harmony\archive\tests\java\util\jar\JarF
 =
  ileTest.java:66\79\190
  .\archive\src\test\java\org\apache\harmony\archive\tests\java\util\zip\Defl
 =
  aterOutputStreamTest.java:220\230
  .\archive\src\test\java\org\apache\harmony\archive\tests\java\util\zip\Defl
 =
  aterTest.java:188\619\724\785\792\859\1006\1013\1070\1077\1091\1092\1098\10
 =
  99\1105\1106\1113\1114\1120\1121\1127\1128\1134\1135\1143\1179
  .\archive\src\test\java\org\apache\harmony\archive\tests\java\util\zip\ZipF
 =
  ileTest.java:67\291
  .\archive\src\test\java\org\apache\harmony\archive\tests\java\util\zip\ZipI
 =
  nputStreamTest.java:200
  .\auth\src\test\java\common\javax\security\auth\callback\ConfirmationCallba
 =
  ckTest.java:60\147
  

Re: [OT] svnfind tool (was: Re: [classlib][test] fail statements omitted in many exception catching test cases)

2006-09-28 Thread Geir Magnusson Jr.
can you stuff this somewhere like the wiki or patch for website or  
stuff somewhere in SVN? :)


geir

On Sep 28, 2006, at 7:53 AM, Mark Hindess wrote:



Testing this script reminded me that I'd not mentioned the small  
script

I wrote after getting feed up typing:

  find path -name .svn -prune -o ...

The script takes:

  svnfind path [path2 ...] ...

and converts it to the previous form so that .svn directories are  
ignored.


Others might find it useful so I've included it below.

-Mark.

#!/bin/sh

while [ -n $1 ]; do
case $1 in
-*)
break
;;
*)
[EMAIL PROTECTED]$1
;;
esac
shift
done

while [ -n $1 ]; do
[EMAIL PROTECTED]$1
shift
done

if [ -z ${args[0]} ]; then
  args[0]=-print
fi

exec find [EMAIL PROTECTED] -name .svn -prune -o [EMAIL PROTECTED]

On 27 September 2006 at 9:44, Mark Hindess  
[EMAIL PROTECTED] wrote:


This perl script does a marginally better job by being slightly  
stricter
on matching context around 'catch'/'fail', by handling comments  
slightly

better and by handling 'catch (...) { }' appearing on a single line.

It also finds a few more hits such as:

  sql/src/test/java/org/apache/harmony/sql/tests/java/sql/ 
TimeTest.java +208


which is a false positive but which uses assertTrue(false); which
should be fixed anyway.

-Mark.

#!/usr/bin/perl -w
use strict;

my $previous_line = ;
my $possible_line_number;
while () {
  next if (/^\s*$/); # skip blank lines
  if ($possible_line_number) {
if (m!^\s*(//|/\*|})!) {
  print $ARGV, ' +', $possible_line_number, \n;
}
undef $possible_line_number;
  }
  if (!m!^\s*(/?\*|//)!  /\bcatch\s*\(/  $previous_line !~ / 
\bfail\s*\(/)

 {
$possible_line_number = $.;
if (/catch\s*\([^\)]+\)\s*{\s*}/) {
  print $ARGV, ' +', $possible_line_number, \n;
  undef $possible_line_number;
}
  }
  $previous_line = $_;
}

On 27 September 2006 at 15:02, Robert Hu [EMAIL PROTECTED]  
wrote:

--090601000506020908060004
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=GB2312

Hi All,

In our unit test of classlib, there are huge number of test cases  
about exc

ep

tion catching. The typical style of those cases is like that:

try {
someStatementShouldThrowAnException;
* fail(Expected an exception);*
} catch (SomeException e){
// Expected
}

If we omit the fail statement, the test case is wrong because  
the excepti

on

-throwing checking is disabled.

I've found that the fail statement is omitted in many test  
cases of our H

ar
mony classlib. So I set some rules to find out all lines of code  
related wi

th

 it. If a line of code comform all the 5 rules, it may be a bug:
1.in a *Test.java file
2.does not start with //
3.contains catch
4.its previous line does not contains fail
5.its next line contains // or }


Then I found out 1711 lines of code in 309 files comform all the  
5 rules in

 r

450321. (Attachment file is the result.)
Of course not all of them are bug, because some test cases are  
not of above

 s

tyle.

And I also find out some real bugs, we can fix them easilly:
trunk\modules\awt\src\test\api\java\common\java\awt\font 
\TextLayoutTest.jav

a:

652\658\664\670\676\685\698\704\711(line number)
trunk\modules\luni\src\test\java\org\apache\harmony\tests\java 
\lang\EnumTes

t.

java:57
trunk\modules\luni\src\test\java\org\apache\harmony\luni\tests 
\java\io\File

In

putStreamTest.java:36
trunk\modules\luni\src\test\java\org\apache\harmony\luni\tests 
\java\io\File

Ou

tputStreamTest.java:35
more..

*I must say frankly that it's hard to find out all bugs of this  
kind withou

t

any victims automatically, we must find out real bugs ourselves.*

Hope the result in attachment file can help us to find out more  
bugs.


Anybody has better search rules or better solution to find out  
those bugs?

Pl

s. share with us, thanks a lot.

--
Robert Hu
China Software Development Lab, IBM


--090601000506020908060004
Content-Type: text/plain;
 name=result.txt
Content-Disposition: inline;
 filename=result.txt
Content-Transfer-Encoding: quoted-printable

current position is trunk\modules
.\archive\src\test\java\org\apache\harmony\archive\tests\java\util 
\jar\JarF

=

ileTest.java:66\79\190
.\archive\src\test\java\org\apache\harmony\archive\tests\java\util 
\zip\Defl

=

aterOutputStreamTest.java:220\230
.\archive\src\test\java\org\apache\harmony\archive\tests\java\util 
\zip\Defl

=
aterTest.java:188\619\724\785\792\859\1006\1013\1070\1077\1091 
\1092\1098\10

=

99\1105\1106\1113\1114\1120\1121\1127\1128\1134\1135\1143\1179
.\archive\src\test\java\org\apache\harmony\archive\tests\java\util 
\zip\ZipF

=

ileTest.java:67\291
.\archive\src\test\java\org\apache\harmony\archive\tests\java\util 
\zip\ZipI

=

nputStreamTest.java:200
.\auth\src\test\java\common\javax\security\auth\callback 
\ConfirmationCallba

=