Wiki

Changeset 2291

Show
Ignore:
Timestamp:
02/27/10 09:18:29 (2 years ago)
Author:
Chuck.Esterbrook
Message:

Use the new Cobra.Lang.Test.TestRunner? for running inline unit tests.
Fix some test cases from the last checkin.

Location:
cobra/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Source/BackEndClr/SharpGenerator.cobra

    r2251 r2291  
    6363                    print '     bool success = false;' 
    6464                    print '     try {' 
    65                 for module in _modules 
    66                     module.writeSharpTestInvocation(f) 
     65                print '     CobraLangInternal.Test.ITestRunListener listener = new CobraLangInternal.Test.TextWriterListener(System.Console.Out);' 
     66                print '     new CobraLangInternal.Test.TestRunner(listener).RunAllTests();' 
    6767                if .hasExceptionReportOption 
    6868                    print '     success = true;' 
     
    583583    is partial 
    584584 
    585     get sharpSuffix as String 
     585    get sharpFullName as String 
    586586        value as Object? 
    587         if not .addOnValues.tryGetValue('sharpSuffix', out value) 
    588             suffix = if(.fullName == 'Cobra.Lang', .compiler.embedRunTimeSuffix, '') 
    589             .addOnValues['sharpSuffix'] = suffix 
    590             return suffix 
     587        if not .addOnValues.tryGetValue('sharpFullName', out value) 
     588            fullName = .fullName 
     589            if fullName == 'Cobra.Lang' 
     590                name = 'Cobra.Lang' + .compiler.embedRunTimeSuffix 
     591            else if fullName.startsWith('Cobra.Lang.') 
     592                name = 'Cobra.Lang[.compiler.embedRunTimeSuffix].' + fullName['Cobra.Lang.'.length:] 
     593            else 
     594                name = fullName 
     595            .addOnValues['sharpFullName'] = name 
     596            return name 
    591597        else 
    592598            return value to String 
     
    600606            return 'global::' 
    601607        else 
    602             return .fullName + .sharpSuffix 
     608            return .sharpFullName 
    603609 
    604610    get sharpQualifier as String 
     
    607613            return 'global::' 
    608614        else 
    609             return .fullName + .sharpSuffix + '.' 
     615            return .sharpFullName + '.' 
    610616     
    611617    def writeSharpDef(sw as CurlyWriter) is override 
     
    613619        base.writeSharpDef(sw) 
    614620        if not .isRoot 
    615             sw.writeAndIndent('namespace [.name][.sharpSuffix] {\n\n') 
     621            suffix = if(.fullName == 'Cobra.Lang', .compiler.embedRunTimeSuffix, '') 
     622            sw.writeAndIndent('namespace [.name][suffix] {\n\n') 
    616623        for ud in _useDirectives 
    617624            ud.writeSharpDef(sw) 
     
    9951002                .compiler.boxMemberStack.push(decl) 
    9961003                try 
    997 /# 
    998 delme 
    999                     if decl inherits BoxMember 
    1000                         if decl.parentBox is not this  # skip extension methods that were not declared in this box 
    1001                             continue 
    1002 #/ 
    10031004                    decl.writeSharpDef(sw) 
    10041005                finally 
     
    10781079 
    10791080    def writeSharpTest(sw as CurlyWriter) 
    1080         # Running tests from the static initializer seems like a good idea, but has been problematic at various times on both .NET and Mono, so no more: 
    1081         # sw.write('\nstatic [.rootName]() { RunTestsIfNeeded(); }\n') 
    1082         # -- er, it turned out that the problem was likely -dst on SourceSite. Consequently we could try returning to static initializers to trigger tests. 
    1083         sw.write('\nprivate static bool __didStartTests = false;\n') 
    1084         newWord = .newForSharpTest 
    1085         sw.write('\npublic static[newWord] void RunTestsIfNeeded() { if (!__didStartTests) RunTests(); }\n') 
    1086         sw.write('\npublic static[newWord] void RunTests()') 
    1087         sw.writeAndIndent(' {\n') 
    1088         sw.write('__didStartTests = true;\n') 
    1089         sw.write('CobraLangInternal.CobraImp.TestBegan("[.name]");\n') 
    1090         if _testMethod 
    1091             sw.write('[_testMethod.sharpName]();\n') 
    1092         for decl in _declsInOrder 
    1093             decl.writeSharpTestInvocation(sw) 
    1094         sw.write('CobraLangInternal.CobraImp.TestEnded("[.name]");\n') 
    1095         sw.dedentAndWrite('}\n') 
    1096  
    1097     var _didWriteSharpTestInvocation = false 
     1081        pass 
    10981082 
    10991083    def writeSharpTestInvocation(sw as CurlyWriter) is override 
    1100         # used by the test option 
    1101         if _didWriteSharpTestInvocation 
    1102             return 
    1103         if .isExtern 
    1104             return 
    1105         if .isGenericDef  # sorry, but static methods always require a type arg even if you don't need it. workaround. make another class with a 'test' section that tests the generic class TODO: make Cobra do this, but then watch for use of the generic param! 
    1106             return 
    1107         #assert .parentNameSpace  # suppress for nested classes  
    1108         sw.write('\t\t[.sharpRef].RunTestsIfNeeded();\n') 
    1109         _didWriteSharpTestInvocation = true 
     1084        pass 
    11101085 
    11111086    get newForSharpTest as String 
     
    28242799            sw.write('try') 
    28252800            _tryBlock.writeSharpDef(sw, false) 
    2826             # delme sw.write('[helperName] = true;\n') 
    28272801            sw.dedent 
    28282802            sw.write('}\n') 
  • cobra/trunk/Source/Cobra.Lang/CobraCore.cobra

    r2229 r2291  
    138138                Run all Cobra `test` sections in all assemblies using reflection to locate them. 
    139139                """ 
    140                 # start = DateTime.now 
    141                 _runAllTests(Assembly.getEntryAssembly, Dictionary<of String, String>()) 
    142                 # duration = DateTime.now.subtract(start) 
    143                 # trace duration 
    144  
    145             def _runAllTests(ass as Assembly, found as Dictionary<of String, String>)  # CC: found should be Set<of String> 
    146                 name = ass.getName.toString 
    147                 if found.containsKey(name) 
    148                     return 
    149                 found.add(name, name) 
    150                 if _skipAssemblyNameForTesting(name)  # saves some time 
    151                     return 
    152  
    153                 # print 'Testing assembly:', ass 
    154                 for type in ass.getExportedTypes 
    155                     members = type.getMember('RunTestsIfNeeded') 
    156                     if members and members.length and members[0] inherits MethodInfo 
    157                         method = members[0] to MethodInfo 
    158                         # trace type, method 
    159                         if type.containsGenericParameters 
    160                             # TODO: this is quite awful. tests in generic types are being skipped! 
    161                             # potential solution 1: move type test out of the type into a "sister" type: private __FooTest 
    162                             # 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 
    163                             continue 
    164                         method.invoke(type, nil) 
    165  
    166                 # traverse further assemblies 
    167                 for assName in ass.getReferencedAssemblies 
    168                     subAss = Assembly.load(assName) 
    169                     _runAllTests(subAss to !, found) 
     140                # listener = Cobra.Lang.Test.TextWriterListener(Console.out) 
     141                listener = Cobra.Lang.Test.TextWriterOnlyOnFailureListener(Console.out) 
     142                tr = Cobra.Lang.Test.TestRunner(listener) 
     143                tr.runAllTests 
    170144 
    171145            var _skipPrefixes = @['System.', 'Mono.', 'mscorlib,', 'System,'] 
  • cobra/trunk/Source/CommandLine.cobra

    r2275 r2291  
    714714            print 'Not running tests due to errors above.' 
    715715            return 
    716         testInvoker = c.modules[c.modules.count-1]  # CC: .last 
     716        testInvoker = c.modules.last 
    717717        assert testInvoker inherits NativeModule 
    718718        assert testInvoker.fileName.startsWith('test-') 
  • cobra/trunk/Source/Phases/BindRunTimeLibraryPhase.cobra

    r2101 r2291  
    3232        c = .compiler 
    3333        pathsToCompile = c.pathsToCompile 
    34         runTimePaths = c.commandLineArgParser.readFilesFile(Path.combine(Path.combine(.cobraExeDir, 'Cobra.Lang'), 'files.text')) 
     34        filesPath = Path.combine(Path.combine(.cobraExeDir, 'Cobra.Lang'), 'files.text') 
     35        runTimePaths = c.commandLineArgParser.readFilesFile(filesPath) 
    3536        runTimePaths.reverse 
    3637        for runTimePath in runTimePaths 
  • cobra/trunk/Tests/120-classes/920-type-decl-clauses.cobra

    r1944 r2291  
    44use System.Collections 
    55 
    6 class TestAttribute inherits Attribute 
     6class FooAttribute inherits Attribute 
    77    pass 
    88 
    9 class Test2Attribute inherits Attribute 
     9class Foo2Attribute inherits Attribute 
    1010    pass 
    1111 
     
    4242    pass 
    4343 
    44 class H inherits Object implements IDisposable has Test 
     44class H inherits Object implements IDisposable has Foo 
    4545    def dispose 
    4646        pass 
    4747 
    48 class I inherits Object implements IDisposable has Test is public 
     48class I inherits Object implements IDisposable has Foo is public 
    4949    def dispose 
    5050        pass 
    5151 
    52 class J inherits Object implements IDisposable, IEnumerable has Test, Test2 is public 
     52class J inherits Object implements IDisposable, IEnumerable has Foo, Foo2 is public 
    5353    def dispose 
    5454        pass 
     
    5959    inherits Object 
    6060    implements IDisposable 
    61     has Test 
     61    has Foo 
    6262    is public 
    6363    def dispose 
  • cobra/trunk/Tests/140-structs/300-type-decl-clauses.cobra

    r1946 r2291  
    44use System.Collections 
    55 
    6 class TestAttribute inherits Attribute 
     6class FooAttribute inherits Attribute 
    77    pass 
    88 
    9 class Test2Attribute inherits Attribute 
     9class Foo2Attribute inherits Attribute 
    1010    pass 
    1111 
     
    1818        pass 
    1919 
    20 struct C has Test is internal 
     20struct C has Foo is internal 
    2121 
    2222    pass 
    2323 
    24 struct D is internal has Test 
     24struct D is internal has Foo 
    2525    pass 
    2626 
    2727struct E is internal 
    2828 
    29     has Test 
     29    has Foo 
    3030     
    3131    pass 
     
    3434 
    3535 
    36     has Test 
     36    has Foo 
    3737    pass 
    3838 
    39 struct G is internal implements IDisposable has Test 
     39struct G is internal implements IDisposable has Foo 
    4040    def dispose 
    4141        pass 
    4242 
    43 struct H implements IDisposable, IEnumerable has Test, Test2 is public 
     43struct H implements IDisposable, IEnumerable has Foo, Foo2 is public 
    4444    def dispose 
    4545        pass 
     
    4949struct I 
    5050    implements IDisposable 
    51     has Test 
     51    has Foo 
    5252    is public 
    5353    def dispose 
  • cobra/trunk/Tests/320-misc-two/250-qualified/200-qual-generic.cobra

    r1224 r2291  
    33    class Referer 
    44 
    5         def stuff as A.B.C.Container<of String>  # dotted generic name use to confound compiler 
     5        def stuff as A.B.C.Container<of String>  # dotted generic name used to confound compiler 
    66            return nil to passthrough 
    77