Wiki

Ticket #195: test-fail.2.patch

File test-fail.2.patch, 2.3 KB (added by hopscc, 14 years ago)
  • Source/Cobra.Lang/CobraCore.cobra

     
    138138                Run all Cobra `test` sections in all assemblies using reflection to locate them. 
    139139                """ 
    140140                # start = DateTime.now 
    141                 _runAllTests(Assembly.getEntryAssembly, Dictionary<of String, String>()) 
     141                if not _runAllTests(Assembly.getEntryAssembly, Dictionary<of String, String>()) 
     142                    CobraCore.exit(3) # test failed 
    142143                # duration = DateTime.now.subtract(start) 
    143144                # trace duration 
    144145 
    145             def _runAllTests(ass as Assembly, found as Dictionary<of String, String>) # CC: found should be Set<of String> 
     146            def _runAllTests(ass as Assembly, found as Dictionary<of String, String>) as bool # CC: found should be Set<of String> 
    146147                name = ass.getName.toString 
    147148                if found.containsKey(name) 
    148                     return 
     149                    return true 
    149150                found.add(name, name) 
    150151                if _skipAssemblyNameForTesting(name)  # saves some time 
    151                     return 
     152                    return true 
    152153 
     154                result=true 
    153155                # print 'Testing assembly:', ass 
    154156                for type in ass.getExportedTypes 
    155157                    members = type.getMember('RunTestsIfNeeded') 
     
    161163                            # potential solution 1: move type test out of the type into a "sister" type: private __FooTest 
    162164                            # potential solution 2: require a constructed type in Cobra: `test Foo<of int> ...` and then put that in a method attribute in the gen C# and use that type 
    163165                            continue 
    164                         method.invoke(type, nil) 
    165  
     166                        try 
     167                            method.invoke(type, nil) 
     168                        catch exc as Exception 
     169                            print '** Test Failure: Exception in Test clause' 
     170                            print exc.innerException 
     171                            result = false 
    166172                # traverse further assemblies 
    167173                for assName in ass.getReferencedAssemblies 
    168174                    subAss = Assembly.load(assName) 
    169                     _runAllTests(subAss to !, found) 
    170  
     175                    result = _runAllTests(subAss to !, found) and result 
     176                return result 
     177                 
    171178            var _skipPrefixes = @['System.', 'Mono.', 'mscorlib,', 'System,'] 
    172179 
    173180            def _skipAssemblyNameForTesting(name as String) as bool 
     
    176183                        return true 
    177184                return false 
    178185 
    179  
    180186            ## Detailed stack trace 
    181187 
    182188            pro maxStackFrames as int