Forums

Shorter error message for failed assertions

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Shorter error message for failed assertions

Postby Gameday » Wed May 12, 2010 9:00 am

Is it possible to get a shorter error message for failed assertions? Like just the number of the line that failed, and maybe the parameters?
Gameday
 
Posts: 27

Re: Shorter error message for failed assertions

Postby Charles » Wed May 12, 2010 12:09 pm

There's no current option for that. What exactly did you have in mind? Maybe you can show a before-and-after output.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Shorter error message for failed assertions

Postby Gameday » Wed May 12, 2010 12:23 pm

Say this is the code:

Code: Select all
class A
   def even(a as int) as bool is shared
      test
         assert .even(2) == true
         assert .even(3) == true
         assert .even(4) == true
      body
         return a % 2 == 0
   def main
      pass


Of course, we're expecting line 5 to fail:

Code: Select all
Running 6 tests at 5/12/2010 10:18:16 PM
>> lib aaa, Version=0.0.0.0
    >> class A
        >> test 1: .even
            Fail with exception:
            System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. --->
Cobra.Lang.AssertException:
            sourceSite = F:\Documents and Settings\john\Desktop\aaa.cobra:5 in A.test_Even for object A (RuntimeType)
            info       = nil
            this       = A (RuntimeType)
                (.even(3) == true) = false
                    .even(3) = false

               at A.test_Even()
               --- End of inner exception stack trace ---
               at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig,
MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner)
               at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAt
tributes methodAttributes, RuntimeTypeHandle typeOwner)
               at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[
] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
               at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[
] parameters, CultureInfo culture)
               at Cobra.Lang.Test.MethodInfoTest._run(TestRunParams params)
               at Cobra.Lang.Test.Test.Run(TestRunParams params, ITestRunListener listener)
        << test 1: .even
    << class A
    >> lib Cobra.Lang, Version=0.8.0.1, Culture=neutral, PublicKeyToken=0a4783a5c7c9616e
        >> class Cobra.Lang.TestIEnumerableExtensions
            >> test 2: class level
            << test 2: class level
        << class Cobra.Lang.TestIEnumerableExtensions
        >> class Cobra.Lang.TestIListExtensions
            >> test 3: class level
            << test 3: class level
        << class Cobra.Lang.TestIListExtensions
        >> class Cobra.Lang.TestIDictionaryExtensions
            >> test 4: class level
            << test 4: class level
        << class Cobra.Lang.TestIDictionaryExtensions
        >> class Cobra.Lang.ObjectCatalog
            >> test 5: class level
            << test 5: class level
        << class Cobra.Lang.ObjectCatalog
        >> class Cobra.Lang.TestSet
            >> test 6: class level
            << test 6: class level
        << class Cobra.Lang.TestSet
    << lib Cobra.Lang, Version=0.8.0.1, Culture=neutral, PublicKeyToken=0a4783a5c7c9616e
<< lib aaa, Version=0.0.0.0
Finished at 5/12/2010 10:18:16 PM.
6 tests run in 00:00:00.3906250.
5 successes.
1 failure.


I was thinking of something like:

Code: Select all
Line 5, assert failed: expected true, got false.
Gameday
 
Posts: 27

Re: Shorter error message for failed assertions

Postby Charles » Thu May 13, 2010 9:51 am

Well first let me say that I would like to add hooks so that the output from assertion failures could be customized. However, this is a low priority right now.

If you want to get rid of the test runner output where it shows you all of the tests, that is currently possible. Search the Cobra code for "TestRunner" and do some research. If you have questions let me know.

In terms of the default output, I think it's appropriate to show the filename as there could be multiple files. Also Cobra shows the expression breakdown which is actually a feature! In a simple expression, it doesn't contribute much, but in more complex expressions, it's very useful to have the value of each subexpression.

Finally, you never need say "b == true" where "b" is a boolean. That's akin to say "i+0" or "f*1.0"--it doesn't do anything at all. I have actually been meaning to make that a warning, but haven't gotten around to it yet.

HTH
Charles
 
Posts: 2515
Location: Los Angeles, CA


Return to Discussion

Who is online

Users browsing this forum: No registered users and 39 guests