-
Notifications
You must be signed in to change notification settings - Fork 273
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
Add the Catch unit testing framework #874
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big request is to split the changes to sharing_map.cpp into three commits, one to indent, one to move and one to actually make the changes. That way I can review the last one properly. Understand if that feels like too much work though.
CODING_STANDARD
Outdated
Unit tests: | ||
- Unit tests are written using Catch: https://github.com/philsquared/Catch/ | ||
- For large classes: | ||
- Each file should contain tests for one function in one class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested clarity rewording:
Create a separate file that contains the tests for each method of each class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just edited my suggestion again, which shows that it's hard to find clear wording for this!
CODING_STANDARD
Outdated
- Each file should contain tests for one function in one class | ||
- The file should be put inside unit/class/path/class_name/function_name.cpp | ||
- For small classes: | ||
- Each file should contain the tests for the class |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a separate file that contains the tests for all methods of each class
CODING_STANDARD
Outdated
- Each file should contain the tests for the class | ||
- The file should be put inside unit/class/path/class_name.cpp | ||
- Catch supports tagging, tests should be tagged with: | ||
- [CORE] or [LONG] if the test takes a long time to run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps explain the difference between these tags.
unit/Makefile
Outdated
# Empty last line | ||
|
||
INCLUDES= -I ../src/ | ||
INCLUDES= -I ../src/ -I. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need this? It seems like a bad thing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this is needed so that include paths can be relative to the root of the unit directory, is that not true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, each of the Makefile
s for each CBMC module does INCLUDE= -I ..
to get the src
directory included.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But then that should be the INCLUDES
as is; the -I.
seems wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to think about what the current working directory will be when the actual compile command is run and make the include paths relative to this. But if it's working already then maybe I'm wrong. If I'm not then this setting might need to be in the makefile in each sub-folder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I understand what is going on. This makefile is directly building source files in sub-folders that include files in this folder using #include <catch.hpp>
. In that case this is the right syntax. As you were.
unit/Makefile
Outdated
catch: catch_entry_point$(EXEEXT) | ||
|
||
# Run the catch tests | ||
test-catch: catch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rule should not be named for the unit test framework. unit-test
or unit
might be better names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically all the tests in here are unit tests, the only difference is these are catch unit tests. We could just remove the rule since I've removed tests that don't actually pass.
unit/catch_example.cpp
Outdated
/// This is an example unit test to demonstrate the build system and the | ||
/// catch unit test framework. The source code is taken from the documentation | ||
/// of catch. | ||
/// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment block is not in a standard format. If you want to include the example you probably need to DiffBlue-ise it.
unit/sharing_map.cpp
Outdated
|
||
// place elements | ||
TEST_CASE("sharing map", "[core][util][sharing_map]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately this file is impossible to diff because of the change in indenting. Can you split the changes into one that does the change and then one that indents it out correctly (or one that indents it out wrongly and then one that does the change)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have just learnt the magic of ?w=1 and the diff looks fine on this file.
unit/Makefile
Outdated
@@ -1,5 +1,5 @@ | |||
CATCH_TESTS = catch_example.cpp \ | |||
sharing_map.cpp \ | |||
util/sharing_map.cpp \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is in the wrong commit (will mess up git blame).
unit/Makefile
Outdated
miniBDD.cpp \ | ||
osx_fat_reader.cpp \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dangling files aren't great. (Yes, effectively the entire directory had been dangling.) Any chance to get those fixed instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I don't have time to fix these at the moment, I have opened an issue to resolve this: #879. Would you prefer the files to be deleted (I'll attach them to the issue) so they aren't dangling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for logging #879; I think it's good enough this way, no need to delete files.
420babb
to
e9a6824
Compare
I have applied Nathan's suggestions and fixed the linting errors. Hopefully I've got the travis file right this time. I still suspect the Makefile could be improved as the way the CBMC libraries are linked in feels a bit clunky, but I don't know how to improve it. I will squash after review so easier to see what changes have been made. |
e2de329
to
1a4a9ac
Compare
Do remember to ignore your executable output in a local .gitignore. |
Done
Done Assuming I have finally got the travis and appveyor things correct - I will rebase this on Tuesday. |
48d6e70
to
22a0505
Compare
@forejtv This is failing on Mac because of your unit test - could you investigate? https://travis-ci.org/diffblue/cbmc/jobs/228295412#L2395 Still investigating why the Windows build is failing, it is something to do with the sharing map so I might just pull that into a separate PR so can get this merged. |
22a0505
to
2d5bac3
Compare
2d5bac3
to
66bccf0
Compare
The windows one is now also failing on the |
fb3ccdf
to
ca6e2b3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of minor suggestions but otherwise good to merge.
CODING_STANDARD
Outdated
- For large classes: | ||
- Create a separate file that contains the tests for each method of each | ||
class | ||
- The file should be put inside unit/class/path/class_name/function_name.cpp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file should be named according to unit/class/path/class_name/function_name.cpp
CODING_STANDARD
Outdated
- Create a separate file that contains the tests for all methods of each | ||
class | ||
- The file should be put inside unit/class/path/class_name.cpp | ||
- Catch supports tagging, tests should be tagged with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with all the following tags:
unit/.gitignore
Outdated
float_utils | ||
json | ||
miniBDD | ||
osx_fat_reader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are all of these still created?
ca6e2b3
to
a4af717
Compare
@NathanJPhillips Thanks, fixed. |
I think the Makefile might still not be correct as if I clean CBMC then do a clean build of the unit, it appears to try and build the unit tests in parallel to the CBMC directory. I think the all rule should be: all: cprover.dir
$(TESTS) Does this make sense to someone who know's make files?(!) As an aside, would you expect |
A rule |
a4af717
to
3b79d6c
Compare
@tautschnig This didn't work exactly (by adding that dependency, the all: cprover.dir
$(MAKE) $(MAKEARGS) $(TESTS) |
Adds catch.hpp - a test harness for writing and running unit tests. Updated the make file so that running `make test` runs all the tests. I removed all the tests that either didn't compile, failing on running or didn't terminate without some input. Added an example catch test to demonstrate it working.
Added running unit tests to the Travis and AppVeyor yml files
Moved the sharing map test into the appropriate folder
3b79d6c
to
760e1fc
Compare
|
||
Module: Example Catch Tests | ||
|
||
Author: DiffBlue Limited. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to put your name as author until we have a common copyright header.
unit/Makefile
Outdated
|
||
CLEANFILES = $(SRC:.cpp=$(EXEEXT)) | ||
TESTS = catch_entry_point$(EXEEXT) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way to specify which tests (not) to run?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the Catch tests get compiled into one executable, so the only way to remove them will be to modify the source of the test or remove them from the SRC list above I believe.
unit/Makefile
Outdated
@@ -1,6 +1,6 @@ | |||
.PHONY: all cprover.dir test | |||
|
|||
SRC = catch_entry_point.cpp \ | |||
SRC = unit_tests.cpp \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to specify the tests to build and execute in a way that does not require to add them in three different places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that the test is catch_example, which is only specified once, in SRC. That's where extra tests will be added. The other executables here will be migrated to the Catch framework over time and be removed from this makefile.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the plan to put all tests into a single cpp file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Multiple cpp files, since executable is my understanding.
Since the cleanup of #887 will take a considerable amount of time, I suggest to get this merged as is, and do the porting of the existing tests in follow-up PRs. |
Adds catch.hpp - a test harness for writing and running unit tests. Updated the make file so that running
make test
runs all the tests. I removed all the tests that either didn't compile, failing on running ordidn't terminate without some input.
Added an example catch test to demonstrate it working.
Updated one of the unit tests to use catch as a demonstration (I can do the others in the next sprint if it is deemed important).