assert

Is ASSERT redundant?

ASSERT(pointer); pointer->x; In this code, the ASSERT seems to be redundant. If the pointer is NULL, pointer->x will fail anyway. Is my argument correct? ...

Are there any tools for compile time checking of asserts in c++?

I was writing a function in c++ the other day and it occured to me the compiler could do a lot more to help me guard against mistakes. The essentials of my code were like this - void method(SomeType* p) { assert(p != 0); p->something(); } And it was called like this SomeType p = NULL; if (SomeCondition) { p = some_real_va...

Hamcrest equal collections

Hello! Is there a matcher in Hamcrest to compare collections for equality? There is contains and containsInAnyOrder but I need equals not bound to concrete collection type. E.g. I cannot compare Arrays.asList and Map.values with Hamcrest equals. Thanks in advance! ...

PHP and unit testing assertions with decimals

I have a method that returns a float like 1.234567890.I want to test that it really does so. However, it seems that this returned float has different precision on different platforms so how do I assert that the returned value is 1.23456789? If I just do: $this->assertEqual(1.23456789, $float); Then that might fail on some platforms wh...

How to use a C assert to make the code more secure ?

Reading misc. tutorials related to SDL development I've found two different examples, doing the same thing, but in a different manner. I was wondering which of the two are you considering to be correct, judging from the perspective of code "security" and maintainability . In the first example the programmer isn't using assert at all, bu...

Debug.Assert() has stopped working in my project

Hi, For some reason, the following line does nothing in my ASP.NET MVC project: System.Diagnostics.Debug.Assert(false); I have triple-checked that I am using the Debug configuration and "Define Debug constant" is checked in the Debug configuration settings. The same problem also occurs in my unit test project. Implementing my o...

What does this mean in php.ini?

assert.active = On assert.bail = Off How does it work? ...

iPhone: assert just terminates the program

Hi all, I'm debugging a heavily assert()'ed iPhone app (Xcode, Objective C++, device simulator). In some cases, the assert failure would just terminate the app, instead of breaking into the debugger as I'd expect. I made a workaround by implementing my own kinda-assert to the effect of: #define AssertLite(b) if(!(b)) {asm {int 3}} (f...

NSAssert usage in threads

I'm trying to use NSAssert throughout my iPhone app so that if an unexpected condition occurs, the application fails-fast and crashes with a meaningful message in the crash log. This works fine if the failing NSAssert is on the main thread, as it raises NSInternalInconsistencyException by default which is uncaught and stops execution. B...

Safety nets in complex multi-threaded code?

As a developer who has just finished writing thousands of lines of complex multi-threaded 'C' code in a project, and which is going to be enhanced, modified etc. by several other developers unfamiliar with this code in the future, I wanted to find out what kind of safety nets do you guys try to put in such code? As an example I could do ...

An Asserting Appender for Log4Net?

Is there a 'standard' way to introduce assertions against Log4Net output? E.g. NUnit.Log4Net.Checkpoint() ...run some code that should not throw warnings... NUnit.Log4Net.AssertNoErrors() NUnit.Log4Net.AssertNoErrorsOrWarnings() Or NUnit.Log4Net.Checkpoint() ...code that warns user about an obsolete value... NUnit.Log4Net.Asser...

Best practices for multiple asserts on same result in C#

What do you think is cleanest way of doing multiple asserts on a result? In the past I've put them all the same test but this is starting to feel a little dirty, I've just been playing with another idea using setup. [TestFixture] public class GridControllerTests { protected readonly string RequestedViewId = "A1"; protected Grid...

Using assert within kernel invocation

Is there convenient way for using asserts within the kernels invocation on device mode? Thanks, in advance. ...

ExceptionAsserts & debugging your C# project in VS

We've been using NUnit & VisualStudio to write C# .NET code for a while now. Testing Exceptions was done in the style of old syntax: [Test] [ExpectException(typeof(ExceptionType))] public void TestExceptionType() { } Now NUnit has released version 2.5.2 which introduced Assert.Throws( Type expectedExceptionType, TestDelegate code...

NUnit and Log4Net integration: asserting based on the log

Hi, This is my first question on stack overflow. I haven't had much luck finding an answer via google or stackoverflow. I'm interested in having an nunit test examine the log4net for a specific entry in the log and assert based on the results of that search. Based on an unrelated post I read re: log4net, I think I can probably use Me...

In Eclipse, how do I see the input to Assert.assertEquals when it fails?

Hi, I'm not much of an Eclipse guru, so please forgive my clumsiness. In Eclipse, when I call Assert.assertEquals(obj1,obj2) and that fails, how do I get the IDE to show me obj1 and obj2? I'm using JExample, but I guess that shouldn't make a difference. Edit: Here's what I see: . ...

Should I redundantly test arguments (e.g collection emptiness)?

Is there a problem with the redundant collection checking here?: SomeMethod() { shapes = GetShapes(); //maybe Assert(shapes.Any())? if(shapes.Any()) { ToggleVisibility(shapes); } } ToggleVisibility(IEnumerable<Shape> shapes) { //maybe Assert(shapes.Any())? if(shapes.Any()) { //do stuff ...

What are acceptable use-cases for python's `assert` statement?

I often use python's assert statement to check user input and fail-fast if we're in a corrupt state. I'm aware that assert gets removed when python with the -o(optimized) flag. I personally don't run any of my apps in optimized mode, but it feels like I should stay away from assert just in-case. It feels much cleaner to write assert fi...

Windows: preventing assert() failures from opening the debug popup

How can I prevent the debug popup window from appearing when an assertion fails on a Windows machine? The app I'm writing is console based and I'm using assert() to test certain things when it's executed in test mode. I'm using MinGW + GCC 4. Edit: This is the test program. #include <stdlib.h> #include <assert.h> int main(void) { ...

Unit Testing AssertError in JUnit

I'm trying to ensure that a parameter can't be null by adding an assert statement at the top of the method. When unit testing, I'm trying to declare that the AssertError is expected, but it still gets recognized as a failed test even though it's behaviour is correct (AssertError is getting thrown). class ExampleTest { @Test(expected...