Page 1 of 1

about tests

PostPosted: Sun Nov 11, 2012 4:30 am
by kobi7
tests are great, having them integrated is really nice
I have questions:

1. Why aren't tests running on compilation, but only on execution?
if I am developing a library, I would run cobra -test, but sometimes forget to.
would be nice to have the default check them on every compilation.

2. when running -test, the tests in the included libraries (use xx) are also run.
isn't it redundant?

Re: about tests

PostPosted: Sun Nov 11, 2012 1:31 pm
by Charles
1. People aren't expecting their code to be executed when they compile. And especially in Cobra where you add -c to get "compilation only", I don't think it would fit. If your project is a library, you could have a build target or script committed to testing.

2. Yeah it is redundant and should probably be eliminated. It might be nice to have an option to run them all though.

Re: about tests

PostPosted: Tue Nov 13, 2012 3:43 am
by kobi7
fair enough, on both points. I guess you're right it is the appropriate behaviour
btw, is there a short or conciser output for tests?
right now I get something of a tree...
coloring would also be a nice feature.

Re: about tests

PostPosted: Fri Nov 16, 2012 8:58 pm
by Charles
I have changed the default behavior of -test to only run the tests of the given program (or library) and not the libraries it references.

Re: about tests

PostPosted: Fri Nov 16, 2012 11:45 pm
by Charles
I'll make a proper wiki page for this, but briefly, to customize the test output:

-- See "cobra -help" for the -test-runner option:

Code: Select all
    -test-runner[:QUALIFIED-METHOD-NAME|nil]  default is Cobra.Core.CobraCore.runAllTests
        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.Core.Test to set up and initiate the test run.

So something like:
Code: Select all
cobra -test -test-running:MyProgram.runTests MyProgram.cobra

-- See CobraCore.cobra for an example implementation:
def runAllTests is shared
"""
Run all Cobra sections in all assemblies using reflection to locate them.
"""
if CobraImp.showTestProgress, listener = Cobra.Core.Test.TextWriterListener(Console.out)
else, listener = Cobra.Core.Test.TextWriterOnlyOnFailureListener(Console.out)
tr = Cobra.Core.Test.TestRunner(listener)
tr.runAllTests
if listener.testFailures, CobraCore.exit(1)


-- Provide your own implementation of ITestRunListener to pass to the TestRunner class. You can find the interface and two implementations in Test.cobra of the Cobra.Core library:
http://cobra-language.com/trac/cobra/br ... Test.cobra

Let us know if you have any problems.

Re: about tests

PostPosted: Mon Nov 19, 2012 2:32 pm
by nerdzero
I'm stoked about the recent change to -test and can't wait to try it out. However, regarding...

Charles wrote:1. People aren't expecting their code to be executed when they compile. And especially in Cobra where you add -c to get "compilation only", I don't think it would fit. If your project is a library, you could have a build target or script committed to testing.


I have to agree with kobi that when I was first trying Cobra, I was surprised that tests were not being run automatically for libraries.