Changeset 2295
- Timestamp:
- 02/28/10 21:24:48 (2 years ago)
- Location:
- cobra/trunk
- Files:
-
- 7 modified
-
Developer/IntermediateReleaseNotes.text (modified) (1 diff)
-
Source/BackEndClr/SharpGenerator.cobra (modified) (3 diffs)
-
Source/Cobra.Lang/Test.cobra (modified) (4 diffs)
-
Source/CommandLine.cobra (modified) (3 diffs)
-
Tests/700-command-line/104-cobra-test.cobra (modified) (2 diffs)
-
Tests/700-command-line/106-cobra-test-program.cobra (modified) (1 diff)
-
Tests/700-command-line/108-cobra-test-library.cobra (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
cobra/trunk/Developer/IntermediateReleaseNotes.text
r2290 r2295 72 72 Command Line 73 73 ================================================================================ 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. 74 76 75 77 * Added -testify-results:filename to control the destination file where testify results are written. -
cobra/trunk/Source/BackEndClr/SharpGenerator.cobra
r2294 r2295 62 62 if .hasExceptionReportOption 63 63 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) 66 65 if .hasExceptionReportOption 67 66 print ' } catch (System.Exception e) {' … … 72 71 .mainMethodTypeName = '_GeneratedTestRunner' 73 72 _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) 74 84 75 85 var _didWriteSharpInfoClass as bool … … 1840 1850 sw.indent 1841 1851 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) 1843 1853 1844 1854 def writeSharpImpFooter(sw as CurlyWriter) -
cobra/trunk/Source/Cobra.Lang/Test.cobra
r2292 r2295 1 1 """ 2 Cobra.Lang.Test contains a family of classes for running tests and reporting their results. 3 4 Also, it is the library used by Cobra to run unit tests declared in the language, 5 using the "test" keyword. 6 2 7 EXAMPLE A 3 8 9 # Scans all assemblies for all Cobra-declared tests and runs them. 4 10 TestRunner(TextWriterListener(Console.out)).runAllTests 5 11 … … 33 39 tr.runTestsFor(System.Reflection.Assembly.getEntryAssembly, false) 34 40 # false == do not follow dependencies 41 42 EXAMPLE 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 35 63 36 64 NOTES … … 46 74 [ ] stack trace filtering could be interesting. more experience will be required to see if it's necessary. see 47 75 http://www.google.com/codesearch/p?hl=en#uX1GffpyOZk/test-runner/junit/runner/BaseTestRunner.java&q=testrunner&d=2 48 [ ] more docs 49 76 50 77 There are more TODOs in the code below. 51 78 """ … … 86 113 87 114 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) 88 121 .makeTestRunListenerIfNeeded 89 suite = .collectTestsFor(ass, willFollowReferences)90 122 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 97 124 def makeTestRunListenerIfNeeded 98 125 ensure .listener -
cobra/trunk/Source/CommandLine.cobra
r2291 r2295 73 73 else 74 74 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'] 76 76 if .containsKey('synonyms') 77 77 for syn in this['synonyms'] … … 312 312 'name': 'main', 313 313 'type': 'string', 314 'description': 'Specify the type containing the "main" method, particularly when more than type declarationshas a "main" method.',314 'description': 'Specify the type containing the "main" method, particularly when more than one type declaration has a "main" method.', 315 315 'args': 'TYPENAME', 316 316 }, … … 416 416 { 417 417 '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.', 419 419 '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', 420 427 }, 421 428 { -
cobra/trunk/Tests/700-command-line/104-cobra-test.cobra
r1452 r2295 3 3 class Test 4 4 5 def main is shared 6 Test().run 7 8 def run 5 def main 9 6 bar = '-------------------------------------------------------------------' 10 7 11 8 output = .runCobraExe('-test 106-cobra-test-program.cobra') 12 9 try 10 assert '** Alternate test runner' not in output 13 11 assert '** Test' in output 14 12 assert '** main shared' in output … … 23 21 try 24 22 assert '** Test' in output 25 assert '** run' in output23 assert '** foo' in output 26 24 assert '** Bar' in output 27 25 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 28 50 finally 29 51 print bar -
cobra/trunk/Tests/700-command-line/106-cobra-test-program.cobra
r1177 r2295 14 14 pass 15 15 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 16 22 namespace Foo 17 23 -
cobra/trunk/Tests/700-command-line/108-cobra-test-library.cobra
r1177 r2295 8 8 print '** Test' 9 9 10 def run10 def foo 11 11 test 12 print '** run'12 print '** foo' 13 13 body 14 14 pass



