Thanks to visit codestin.com
Credit goes to github.com

Skip to content

assertEqual does not support nullptr #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hlovdal opened this issue Jan 28, 2019 · 6 comments
Closed

assertEqual does not support nullptr #102

hlovdal opened this issue Jan 28, 2019 · 6 comments
Labels
arduino mocks Compilation mocks for the Arduino library bug Something isn't working

Comments

@hlovdal
Copy link
Contributor

hlovdal commented Jan 28, 2019

Trying to test that a function returns a null pointer, e.g.

	assertEqual(nullptr, result);

does not work

.../ArduinoUnitTests.h:69:56: error: ambiguous overload for ‘operator<< (operand types are ‘std::basic_ostream<char>’ and ‘std::nullptr_t’)
               cerr << "      " << lhsRelevance << ": " << lhs << endl;

I tried to fix it by extracting that line into a template function and then make a template specialisation for nullptr but did not get the compiler to select it, and have put that on ice for now since there is a simple workaround, just adding

#define nullptr (void *)NULL

at the top of the test file. But it would be nice to eventually have this fixed.

@ianfixes ianfixes added bug Something isn't working arduino mocks Compilation mocks for the Arduino library labels Jan 29, 2019
@ianfixes
Copy link
Collaborator

Yup, this seems like part of C++11 that needs to be added to the mocks. What's the data type of result in the code you posted? I'll add that to a unit test.

@ianfixes
Copy link
Collaborator

I will add nullptr and assertNull(result)

@hlovdal
Copy link
Contributor Author

hlovdal commented Jan 30, 2019

Those updates still do not fix the issue with assertEqual. The problem is that onAssert tries to print the argument of type nullptr which it is not able to. There needs to be an additional unit test:

unittest(nullpointer_equal)
{
  int* myPointer = NULL;
  int **notNullPointer = &myPointer;
  assertEqual(nullptr, myPointer);
  assertNotEqual(nullptr, notNullPointer);

#if 0
  // The following should not compile, which they currently do not but in a
  // cryptic way. If possible and with low effort an explicit denial which
  // produces an explanatory error would be nice.
  assertLessOrEqual(nullptr, myPointer);
  assertMoreOrEqual(nullptr, notNullPointer);
  assertLess(nullptr, myPointer);
  assertMore(nullptr, notNullPointer);
  assertFalse(nullptr);
  assertTrue(nullptr);
  assertAnyLhsRhsFunction(..., nullptr);
#endif
}

@ianfixes
Copy link
Collaborator

Thanks, those unit tests are exactly what was needed.

@ianfixes
Copy link
Collaborator

ianfixes commented Jan 31, 2019

@hlovdal You gave me an excellent idea here.

I've set up a new branch called tdd (https://github.com/ianfixes/arduino_ci/tree/tdd). If you can write unit tests that show a problem, make a PR using the tdd branch as a base. That will give me something to work from when I go about fixing the issue, and not require me to break the master branch in the process.

@ianfixes
Copy link
Collaborator

ianfixes commented Feb 7, 2019

This fix is live in the latest version, sorry for the arbitrary delay there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arduino mocks Compilation mocks for the Arduino library bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants