teach JUnitTestCaseProxy of expected exceptions development
authorMarcel Hlopko <marcel.hlopko@gmail.com>
Sat, 08 Feb 2014 22:13:44 +0100
branchdevelopment
changeset 3011 83579e128194
parent 3010 8b3f1f16a660
child 3012 8a803c26ea93
child 3013 d0cff1393341
teach JUnitTestCaseProxy of expected exceptions
JUnitTestCaseProxy.st
JavaClass.st
JavaExceptionTests.st
JavaLookup.st
JavaMethod.st
Make.proto
abbrev.stc
bc.mak
libjava.rc
stx_libjava.st
--- a/JUnitTestCaseProxy.st	Thu Feb 06 14:06:48 2014 +0100
+++ b/JUnitTestCaseProxy.st	Sat Feb 08 22:13:44 2014 +0100
@@ -164,6 +164,31 @@
 
 !JUnitTestCaseProxy methodsFor:'private'!
 
+handleRaisedException:ex
+   "Some methods are expected to raise an exception, I take care of that. If the exception
+   is not expected, I convert it to something expected by stx tools."    
+
+    | method |
+    method := self javaClass lookupMethodFor: testSelector.
+    method notNil ifTrue:[
+        |annotation|
+        annotation := (method annotations runtimeVisible at:'Lorg/junit/Test;').
+        (annotation values includesKey: 'expected') ifTrue: [
+            |classNameIndex className expectedExceptionClass|
+            classNameIndex :=  (annotation values at: 'expected') classIndex.
+            className := (self javaClass constantPool at: classNameIndex).
+            expectedExceptionClass := Java classForName: className.
+            (ex equalsOrIsSubclassOf: expectedExceptionClass) ifTrue: [
+                "this is the expected exception, just continue"
+                ^ self.
+            ].
+        ].
+    ].
+    TestResult failure sunitSignalWith: ex getMessage.
+
+    "Created: / 08-02-2014 / 21:31:16 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
+!
+
 performTest
 
     <resource: #skipInDebuggersWalkBack>
@@ -171,8 +196,9 @@
     | assertions |
 
     assertions := SignalSet 
-                    with: (Java classForName:'java.lang.AssertionError')
+                    with: (Java classForName:'java.lang.AssertionError')                    
                     with: (Java classForName:'junit.framework.AssertionFailedError')
+                    with: (Java classForName:'java.lang.RuntimeException')
                     "/ JavaVM unimplementedNativeMethodSignal is Signal, not exception.
                     "/ Therefore it MUST be listed here!!!!!!
                     with: (JavaVM unimplementedNativeMethodSignal).
@@ -181,11 +207,12 @@
     ] on: assertions do: [:ex|
         "This is the tricky part. We have to auto-magically convert
          jUnit's AssertionFailedError to sUnits TestFailure's"
-        TestResult failure sunitSignalWith: ex getMessage
+        self handleRaisedException: ex.
     ]
 
     "Created: / 01-03-2011 / 14:50:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 22-01-2014 / 14:40:54 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-02-2014 / 21:31:16 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
 ! !
 
 !JUnitTestCaseProxy class methodsFor:'documentation'!
--- a/JavaClass.st	Thu Feb 06 14:06:48 2014 +0100
+++ b/JavaClass.st	Sat Feb 08 22:13:44 2014 +0100
@@ -1627,11 +1627,6 @@
         ].
     ].
 
-    (JavaVM booted and: [JavaVM eagerResolvingEnabled] )ifTrue: [
-        JavaClassReader classLoaderQuerySignal answer: classLoader
-            do: [ self resolveAll. ]
-    ].
-
     "
      JavaVM instructionTrace:true.
      JavaVM callTrace:true.
@@ -1646,6 +1641,7 @@
     "Modified: / 18-08-2011 / 19:37:33 / jv"
     "Modified: / 08-12-2011 / 21:05:21 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
     "Modified: / 08-12-2013 / 22:28:38 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-02-2014 / 18:08:05 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
 !
 
 classInitInternal
@@ -2773,13 +2769,14 @@
 !
 
 typeName
-    ^ 'L' , self fullName , ';'.
+    ^ 'L' , self binaryName , ';'.
 
     "
      (Java at:'java.util.Stack') typeName"
 
     "Modified: / 10-02-1998 / 17:13:26 / cg"
     "Modified: / 02-03-2011 / 22:48:40 / Marcel Hlopko <hlopik@gmail.com>"
+    "Modified: / 08-02-2014 / 21:58:23 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
 ! !
 
 !JavaClass methodsFor:'queries-protocol'!
--- a/JavaExceptionTests.st	Thu Feb 06 14:06:48 2014 +0100
+++ b/JavaExceptionTests.st	Sat Feb 08 22:13:44 2014 +0100
@@ -65,7 +65,6 @@
     "Created: / 30-03-2012 / 13:38:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
-
 !JavaExceptionTests methodsFor:'callbacks'!
 
 call: trhower with: aBoolean 
--- a/JavaLookup.st	Thu Feb 06 14:06:48 2014 +0100
+++ b/JavaLookup.st	Sat Feb 08 22:13:44 2014 +0100
@@ -948,7 +948,6 @@
 
         cls := arg class.
         candidates := candidates select:[:m|
-            self breakPoint:#mh.
             self type: cls matches: (m descriptor parameters at: index) javaClass
         ].
     ].
@@ -964,6 +963,7 @@
     "Created: / 03-01-2012 / 21:40:23 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 03-04-2012 / 13:59:13 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
     "Modified: / 14-09-2013 / 11:54:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-02-2014 / 21:00:53 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
 !
 
 type: actual matches: formal 
--- a/JavaMethod.st	Thu Feb 06 14:06:48 2014 +0100
+++ b/JavaMethod.st	Sat Feb 08 22:13:44 2014 +0100
@@ -268,19 +268,14 @@
     | sig |
 
     sig := ''.
-    arr do:
-            [:el | 
-            | jCLass |
-
-            jCLass := el.
-            jCLass isJavaClass 
-                ifFalse:[ jCLass := JavaVM reflection classForJavaClassObject:el ].
-            jCLass isJavaClass 
-                ifTrue:
-                    [ sig := sig , jCLass typeName.
-                    ]
-                ifFalse:[ self halt. ] ].
-    ^ sig
+    arr do: [:el | 
+        | jClass |
+
+        jClass := el.
+        jClass isJavaClass ifFalse:[ jClass := JavaVM reflection classForJavaClassObject:el ].
+        jClass isJavaClass ifTrue: [ sig := sig , jClass typeName. ] ifFalse:[ self halt. ] 
+    ].
+    ^ sig.
 
     "
      self argSignatureFromArgTypeArray:
@@ -289,6 +284,7 @@
 
     "Modified: / 13-02-1998 / 14:57:58 / cg"
     "Modified: / 02-03-2011 / 22:49:24 / Marcel Hlopko <hlopik@gmail.com>"
+    "Modified (format): / 08-02-2014 / 22:00:20 / Marcel Hlopko <marcel.hlopko@fit.cvut.cz>"
 !
 
 argSpecFromSignature:aSignature withName:name
--- a/Make.proto	Thu Feb 06 14:06:48 2014 +0100
+++ b/Make.proto	Sat Feb 08 22:13:44 2014 +0100
@@ -34,7 +34,7 @@
 # add the path(es) here:,
 # ********** OPTIONAL: MODIFY the next lines ***
 # LOCALINCLUDES=-Ifoo -Ibar
-LOCALINCLUDES=-I$(ZLIB_DIR) -Isupport/fdlibm -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libbasic2 -I$(INCLUDE_TOP)/stx/libbasic3 -I$(INCLUDE_TOP)/stx/libview
+LOCALINCLUDES=-I$(ZLIB_DIR) -Isupport/fdlibm -I$(INCLUDE_TOP)/stx/goodies/sunit -I$(INCLUDE_TOP)/stx/libbasic -I$(INCLUDE_TOP)/stx/libbasic2 -I$(INCLUDE_TOP)/stx/libbasic3 -I$(INCLUDE_TOP)/stx/libview
 
 
 # if you need any additional defines for embedded C code,
@@ -144,6 +144,8 @@
 	cd ../libbasic2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
 	cd ../libbasic3 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
 	cd ../libview && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
+	cd ../libview2 && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
+	cd ../goodies/sunit && $(MAKE) "CFLAGS_LOCAL=$(GLOBALDEFINES)"
 
 
 
--- a/abbrev.stc	Thu Feb 06 14:06:48 2014 +0100
+++ b/abbrev.stc	Sat Feb 08 22:13:44 2014 +0100
@@ -5,7 +5,6 @@
 GroovyEvaluator GroovyEvaluator stx:libjava 'Languages-Groovy-Compiler' 0
 GroovyLanguage GroovyLanguage stx:libjava 'Languages-Groovy-Support' 1
 GroovySourceFileWriter GroovySourceFileWriter stx:libjava 'Languages-Groovy-Support' 0
-JUnitTestCaseProxy JUnitTestCaseProxy stx:libjava 'Languages-Java-Tests-Proxies' 3
 JavaAnnotation JavaAnnotation stx:libjava 'Languages-Java-Reader-Support' 0
 JavaAnnotationContainer JavaAnnotationContainer stx:libjava 'Languages-Java-Annotations' 1
 JavaAnnotationDefault JavaAnnotationDefault stx:libjava 'Languages-Java-Annotations' 1
@@ -93,6 +92,7 @@
 TestletTestCaseProxy TestletTestCaseProxy stx:libjava 'Languages-Java-Tests-Proxies' 3
 stx_libjava stx_libjava stx:libjava '* Projects & Packages *' 3
 GroovyMetaclass GroovyMetaclass stx:libjava 'Languages-Groovy-Classes' 0
+JUnitTestCaseProxy JUnitTestCaseProxy stx:libjava 'Languages-Java-Tests-Proxies' 3
 Java Java stx:libjava 'Languages-Java-Support' 0
 JavaAnnotationArrayValue JavaAnnotationArrayValue stx:libjava 'Languages-Java-Reader-Support' 0
 JavaAnnotationClassValue JavaAnnotationClassValue stx:libjava 'Languages-Java-Reader-Support' 0
--- a/bc.mak	Thu Feb 06 14:06:48 2014 +0100
+++ b/bc.mak	Sat Feb 08 22:13:44 2014 +0100
@@ -34,7 +34,7 @@
 
 
 
-LOCALINCLUDES=-I$(ZLIB_DIR) -Isupport\fdlibm -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libbasic2 -I$(INCLUDE_TOP)\stx\libbasic3 -I$(INCLUDE_TOP)\stx\libview
+LOCALINCLUDES=-I$(ZLIB_DIR) -Isupport\fdlibm -I$(INCLUDE_TOP)\stx\goodies\sunit -I$(INCLUDE_TOP)\stx\libbasic -I$(INCLUDE_TOP)\stx\libbasic2 -I$(INCLUDE_TOP)\stx\libbasic3 -I$(INCLUDE_TOP)\stx\libview
 LOCALDEFINES=
 
 STCLOCALOPT=-package=$(PACKAGE) -I. $(LOCALINCLUDES) -headerDir=. $(STCLOCALOPTIMIZATIONS) $(STCWARNINGS) $(LOCALDEFINES)  -varPrefix=$(LIBNAME)
@@ -54,6 +54,8 @@
 	pushd ..\libbasic2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
 	pushd ..\libbasic3 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
 	pushd ..\libview & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
+	pushd ..\libview2 & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
+	pushd ..\goodies\sunit & $(MAKE_BAT) "CFLAGS_LOCAL=$(GLOBALDEFINES) "
 
 
 
--- a/libjava.rc	Thu Feb 06 14:06:48 2014 +0100
+++ b/libjava.rc	Sat Feb 08 22:13:44 2014 +0100
@@ -25,7 +25,7 @@
       VALUE "LegalCopyright", "Copyright Claus Gittinger 1988-2011\nCopyright eXept Software AG 1998-2011\nCopyright Jan Vrany, Jan Kurs and Marcel Hlopko\n          SWING Research Group, Czech Technical University In Prague\0"
       VALUE "ProductName", "Smalltalk/X\0"
       VALUE "ProductVersion", "6.2.3.0\0"
-      VALUE "ProductDate", "Sun, 26 Jan 2014 16:10:03 GMT\0"
+      VALUE "ProductDate", "Sat, 08 Feb 2014 21:06:22 GMT\0"
     END
 
   END
--- a/stx_libjava.st	Thu Feb 06 14:06:48 2014 +0100
+++ b/stx_libjava.st	Sat Feb 08 22:13:44 2014 +0100
@@ -160,7 +160,7 @@
      (the browser has a menu function for that)"
 
     ^ #(
-        #'stx:goodies/sunit'    "TestAsserter - superclass of JavaAntProjectResource "
+        #'stx:goodies/sunit'    "TestAsserter - superclass of JUnitTestCaseProxy "
         #'stx:libbasic'    "AbstractNumberVector - extended "
         #'stx:libbasic2'    "SignedIntegerArray - extended "
         #'stx:libbasic3'    "WrappedMethod - extended "
@@ -311,7 +311,6 @@
         GroovyEvaluator
         GroovyLanguage
         GroovySourceFileWriter
-        (JUnitTestCaseProxy autoload)
         JavaAnnotation
         JavaAnnotationContainer
         JavaAnnotationDefault
@@ -399,6 +398,7 @@
         (TestletTestCaseProxy autoload)
         #'stx_libjava'
         GroovyMetaclass
+        (JUnitTestCaseProxy autoload)
         Java
         JavaAnnotationArrayValue
         JavaAnnotationClassValue