assert

Why are assertions compiled out of production builds (other than performance)?

The typical argument for removing assertions from production code is performance. This doesn't make sense to me. Yes, stripping a few assertions out of the performance-critical 5% or so of your code can be a useful optimization. For the other 95%, though, they probably have no measurable effect, and asserts can only increase the likel...

JRuby and Test::Unit's assert_raise

I'm having trouble making assert_raise recognize java exceptions. I can do assert_raise(NativeException) { @iter.next } which works fine, but if I try to get more specific java_import 'java.util.NoSuchElementException' #... assert_raise(NoSuchElementException) { @iter.next } I get the error Should expect a class of exception, Ja...

How to print additional information when assert fails?

Often one wants to print out additional information if an assert fails. A way to do that is this: assert(vec.size() > i || !(std::cerr << "False: " << vec.size() << ">" << i)) This way the actual sizes are printed when the assert fails. But it's ugly, and also it's easy to forget the ! , which will make the assertion condition true...

C# XNA: Trouble with Dictionaries

I'm new to C#. Perhaps I'm not implementing IEquatable properly, because objects of my type that should be considered the same are not. The class: class CompPoint : IComparable { public int X; public int Y; public CompPoint(int X, int Y) { this.X = X; this.Y = Y; } public ove...

VS2008 attaching a debugger (C++) to handle assert(...)

This is related to regular assert(...) There are two scenarios that I'm interested to improve in my code. 1) a debug build app is started regularly, if there is an assertion I'm getting "Debug assertion failed" dialog box with "Abort", "Retry", "Ignore". Abort and Ignore answers are working fine. The problem with Retry. If I hit retry I'...

Assert.AreEqual question

Hello, I have a test method: [TestMethod()] public void test_chars() { MyBO target = new MyBO() { x = 'S' }; char[] expected = {'D','d','M','m','L','l'}; char actual = target.s; Assert.AreEqual(actual, expected); // ? } How can i check with Assert.AreEqual if target.x is in that char[] ...

Java assert nasty side-effect - compiler bug?

This public class test { public static void main(String[] args) { Object o = null; assert o != null; if(o != null) System.out.println("o != null"); } } prints out "o != null"; both 1.5_22 and 1.6_18. Compiler bug? Commenting out the assert fixes it. The byte code appears to jump directly...

Xcode - Call stack trace on assert?

Right now when one of my asserts is triggered in Xcode, I get the assert message, and a dump of the stack, which is full of numbers that are not very meaningful to me. In order to get a trace of the call stack, it requires me to debug the application, and run it up to the point where the assert occurred, and hope that it asserts again....

How can I assert in VBScript scripts?

What is a good way to use asserts in VBScript scripts? Is there built-in functionality for it or will it have to be emulated? What is best practice? One application is to test for objects being Nothing during development. ...

Why does the "Assert" class have so many seemingly redundant methods? When should each be used?

So I see that Assert has dozens of methods that seem to do essentially the same thing. Assert.IsFalse( a == b ); Assert.IsTrue( a != b ); Assert.AreNotEqual( a, b ); Why? Is it just to be more explicit? When should the various methods be used? Is there an offical best practices document? ...

NUnit conflict with Debug.Assert

I'm using NUnit to write unit tests for a libary a colleague of mine has written. His library contains a lot of Debug.Asserts which triggers on invalid input. When I'm writing the unit tests and give invalid input to his library, his Debug.Assert throws up a message box complaining about the bad input. I feel that it's a good thing that...

Can I use assert on Android devices?

I want to use the assert keyword in my android apps to destroy my app in some cases on the emulator, or my device during testing. Is this possible? It seems that the emulator just ignores my asserts. ...

DirectShow complains I'm running a mixed debug/retail build. What?

C:\Program Files\Microsoft SDKs\Windows\v#.#\Samples\multimedia\directshow\baseclasses\wxdebug.gpp line 890: /* If this fires you have a mixed DEBUG/RETAIL build */ ASSERT(!!szObjectName ^ !!wszObjectName); What does it mean and how can I fix it? If it matters: I've written a managed media player library that wraps DirectShow, and I...

How should one deal with invalid business objects in code?

Lets say that you have a business object whose current state implies that there is some kind of a bug in your code. Or basically any scenario where you are working with your own data but it is in a state that should never occur violating some rules. I like to typically check for such conditions and assumptions because it allows me to c...

Why are assertEquals() parameters in the order (expected, actual) ?

Why do so many assertEquals() or similar function take the expected value as first parameter and the actual one as second ? This seems counter-intuitive to me, so is there a particular reason for this unusual order ? ...

Slow Scala assert

We've been profiling our code recently and we've come across a few annoying hotspots. They're in the form assert(a == b, a + " is not equal to " + b) Because some of these asserts can be in code called a huge amount of times the string concat starts to add up. assert is defined as: def assert(assumption : Boolean, message : Any) = .....

Assert a good practice or not ?

Is it a good practice to use Assert for function parameters to enforce their validity. I was going through the source code of Spring Framework and I noticed that they use Assert.notNull a lot. Here's an example public static ParsedSql parseSqlStatement(String sql) { Assert.notNull(sql, "SQL must not be null");} Here's Another o...

C/C++ full file path in assert macro

hello, I am wondering if it's possible to display full file path using the assert macro? I cannot specify full file path in compilation command, is there still a way to do it? My debug environment is linux/g++ ...

Boost 1.4.0, "assert" identifier not found

I'm trying to compile an old project that was originally written for linux on windows. It uses boost 1.4.0, and whenever I compile it throws error C3961: "assert" : identifier not found. I'm using Visual Studio 208 SP1 When I drill down into assert.hpp it includes this: # include <assert.h> // .h to support old libraries w/o <cassert> ...

IOKit header assert.h gone? [answered]

I want to get the hardware address of my mac's ethernet card. In all samples I saw in include on IOKit/assert.h . Which doesn't seem to exist on my system. GCC throws an error saying he doesn't know the type IOEthernetAddress. Is assert.h necessary for my task? It would be great if someone coud give me a working sample. [edit] here's my ...