Wiki

Changeset 2295

Show
Ignore:
Timestamp:
02/28/10 21:24:48 (2 years ago)
Author:
Chuck.Esterbrook
Message:

Added -test-runner command line option to specify the method to invoke to run the unit tests.

Location:
cobra/trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • cobra/trunk/Developer/IntermediateReleaseNotes.text

    r2290 r2295  
    7272Command Line 
    7373================================================================================ 
     74 
     75* Added -test-runner to specify the method to invoke to run the unit tests. The method must be "shared". Typically the method will make use of classes in Cobra.Lang.Test to set up and initiate the test run. 
    7476 
    7577* Added -testify-results:filename to control the destination file where testify results are written. 
  • cobra/trunk/Source/BackEndClr/SharpGenerator.cobra

    r2294 r2295  
    6262                if .hasExceptionReportOption 
    6363                    print '     try {' 
    64                 print '     CobraLangInternal.Test.ITestRunListener listener = new CobraLangInternal.Test.TextWriterListener(System.Console.Out);' 
    65                 print '     new CobraLangInternal.Test.TestRunner(listener).RunAllTests();' 
     64                .writeSharpRunAllTests(f) 
    6665                if .hasExceptionReportOption 
    6766                    print '     } catch (System.Exception e) {' 
     
    7271        .mainMethodTypeName = '_GeneratedTestRunner' 
    7372        _modules.add(SharpModule(fileName, _verbosity)) 
     73 
     74    def writeSharpRunAllTests(cw as CurlyWriter) 
     75        runner = .options['test-runner'] to String  # ex: Cobra.Lang.CobraCore.runAllTests, ex: MyProgram.runTests 
     76        if runner <> 'nil' 
     77            if runner.endsWith('()'), runner = runner[:-2] 
     78            if runner.startsWith('Cobra.Lang.'), runner = 'CobraLangInternal.' + runner['Cobra.Lang.'.length:] 
     79            parts = List<of String>(runner.split(c'.')) 
     80            if parts.count > 1 
     81                parts[parts.count-1] = parts.last[0].toUpper.toString + parts.last[1:] 
     82            stmt = parts.join('.') + '();' 
     83            cw.writeLine(stmt) 
    7484 
    7585    var _didWriteSharpInfoClass as bool 
     
    18401850                sw.indent 
    18411851        if .isMain and .compiler.options.boolValue('include-tests') 
    1842             sw.writeLine('CobraLangInternal.CobraCore.RunAllTests();  // turn off with -include-tests:no (see cobra -h)') 
     1852            (.compiler to Compiler).writeSharpRunAllTests(sw) 
    18431853 
    18441854    def writeSharpImpFooter(sw as CurlyWriter) 
  • cobra/trunk/Source/Cobra.Lang/Test.cobra

    r2292 r2295  
    11""" 
     2Cobra.Lang.Test contains a family of classes for running tests and reporting their results. 
     3 
     4Also, it is the library used by Cobra to run unit tests declared in the language, 
     5using the "test" keyword. 
     6 
    27EXAMPLE A 
    38 
     9    # Scans all assemblies for all Cobra-declared tests and runs them. 
    410    TestRunner(TextWriterListener(Console.out)).runAllTests 
    511 
     
    3339    tr.runTestsFor(System.Reflection.Assembly.getEntryAssembly, false) 
    3440    # false == do not follow dependencies 
     41 
     42EXAMPLE G 
     43 
     44    @args -test-runner:P.runTests 
     45     
     46    class P 
     47     
     48        def main 
     49            print 'Hello from main.' 
     50 
     51        def runTests is shared 
     52            # Due to the @args above, Cobra will invoke this method for running tests instead of 
     53            # Cobra.Lang.CobraCore.runAllTests. This allows you to customize the test runner, 
     54            # including setting parameters, adding listeners, using a custom subclass, etc.  
     55            # 
     56            # When customizing the test run, you will find it useful to read the interface to 
     57            # Cobra.Lang.Test, and possibly even the implementation. 
     58            # 
     59            # Alternatively, you can bypass Cobra.Lang.Test entirely and write whatever code 
     60            # you like here. 
     61            tr = Cobra.Lang.Test.TestRunner() 
     62            tr.runAllTests 
    3563 
    3664NOTES 
     
    4674    [ ] stack trace filtering could be interesting. more experience will be required to see if it's necessary. see 
    4775        http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/test-runner/junit/runner/BaseTestRunner.java&q=testrunner&d=2 
    48     [ ] more docs 
    49      
     76 
    5077    There are more TODOs in the code below. 
    5178""" 
     
    86113 
    87114        def runTestsFor(ass as Assembly, willFollowReferences as bool) 
     115            .runTestsFor(.collectTestsFor(ass, willFollowReferences)) 
     116     
     117        def runTestsFor(type as Type) 
     118            .runTestsFor(.collectTestsFor(type)) 
     119         
     120        def runTestsFor(suite as TestSuite) 
    88121            .makeTestRunListenerIfNeeded 
    89             suite = .collectTestsFor(ass, willFollowReferences) 
    90122            suite.run(.params, .listener to !) 
    91      
    92         def runTestsFor(type as Type) 
    93             .makeTestRunListenerIfNeeded 
    94             suite = .collectTestsFor(type) 
    95             suite.run(.params, .listener to !) 
    96      
     123             
    97124        def makeTestRunListenerIfNeeded 
    98125            ensure .listener 
  • cobra/trunk/Source/CommandLine.cobra

    r2291 r2295  
    7373            else 
    7474                this['type'] = 'string' 
    75         assert _type in ['accumulator', 'args-list', 'bool', 'int','main', 'menu', 'set', 'string'] 
     75        assert _type in ['accumulator', 'args-list', 'bool', 'int', 'main', 'menu', 'set', 'string'] 
    7676        if .containsKey('synonyms') 
    7777            for syn in this['synonyms'] 
     
    312312            'name': 'main', 
    313313            'type': 'string', 
    314             'description': 'Specify the type containing the "main" method, particularly when more than type declarations has a "main" method.', 
     314            'description': 'Specify the type containing the "main" method, particularly when more than one type declaration has a "main" method.', 
    315315            'args': 'TYPENAME', 
    316316        }, 
     
    416416        { 
    417417            'name': 'test', 
    418             'description': 'Run the unit tests in the code.', 
     418            'description': 'Run the unit tests in the code without running .main. Works for libraries too.', 
    419419            'type': 'main', 
     420        }, 
     421        { 
     422            'name': 'test-runner', 
     423            'type': 'string', 
     424            'description': 'Specify the method to invoke to run the unit tests. The method must be "shared". Typically the method will make use of classes in Cobra.Lang.Test to set up and initiate the test run.', 
     425            'default': 'Cobra.Lang.CobraCore.runAllTests', 
     426            'args': 'QUALIFIED-METHOD-NAME|nil', 
    420427        }, 
    421428        { 
  • cobra/trunk/Tests/700-command-line/104-cobra-test.cobra

    r1452 r2295  
    33class Test 
    44 
    5     def main is shared 
    6         Test().run 
    7  
    8     def run 
     5    def main 
    96        bar = '-------------------------------------------------------------------' 
    107 
    118        output = .runCobraExe('-test 106-cobra-test-program.cobra') 
    129        try 
     10            assert '** Alternate test runner' not in output 
    1311            assert '** Test' in output 
    1412            assert '** main shared' in output 
     
    2321        try 
    2422            assert '** Test' in output 
    25             assert '** run' in output 
     23            assert '** foo' in output 
    2624            assert '** Bar' in output 
    2725            assert '** baz' in output 
     26        finally 
     27            print bar 
     28            print output 
     29            print bar 
     30 
     31        output = .runCobraExe('-test-runner:Test.alternateTestRunner -test 106-cobra-test-program.cobra') 
     32        try 
     33            assert '** Alternate test runner' in output 
     34            assert '** Test' in output 
     35            assert '** main shared' in output 
     36            assert '** Bar' in output 
     37            assert '** baz' in output 
     38        finally 
     39            print bar 
     40            print output 
     41            print bar 
     42 
     43        output = .runCobraExe('-test-runner:nil 106-cobra-test-program.cobra') 
     44        try 
     45            assert '** Alternate test runner' not in output 
     46            assert '** Test' not in output 
     47            assert '** main shared' not in output 
     48            assert '** Bar' not in output 
     49            assert '** baz' not in output 
    2850        finally 
    2951            print bar 
  • cobra/trunk/Tests/700-command-line/106-cobra-test-program.cobra

    r1177 r2295  
    1414            pass 
    1515 
     16    def alternateTestRunner is shared 
     17        # -test-runner:Test.alternateTestRunner 
     18        print '** Alternate test runner' 
     19        tr = Cobra.Lang.Test.TestRunner() 
     20        tr.runAllTests 
     21 
    1622namespace Foo 
    1723 
  • cobra/trunk/Tests/700-command-line/108-cobra-test-library.cobra

    r1177 r2295  
    88        print '** Test' 
    99 
    10     def run 
     10    def foo 
    1111        test 
    12             print '** run' 
     12            print '** foo' 
    1313        body 
    1414            pass