Wiki
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.

Files:
1 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')