-
Notifications
You must be signed in to change notification settings - Fork 273
Improvements to the unit tests directory #1111
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
Conversation
dc1c7ed
to
3a0f1bd
Compare
/// \param name: The name of the symbol. | ||
/// \param type: The type of the symbol. | ||
/// \return The symbol that has been created. | ||
symbolt symbol_table_utilt::create_basic_symbol( |
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.
Wouldn't this make for a good constructor in symbolt
?
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 am happy to do this, but reasons why I didn't:
- I thought it was a bit of an ad-hoc collection of flags that seems very useful when you want succinct tests, but not in general.
- I don't understand all the flags in
symbolt
. I don't think this is a problem for tests, but seems more risky to introduce into the general codebase (someone might see this constructor, use it but in some unrelated part of the code, the missing flag could cause some nasty problems (not an issue with unit tests since only test isolated sections of the code).
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.
Take a look at various *_symbolt
classes defined in symbol.h - I'd see nothing wrong in adding one more, which really must be a useful one as otherwise you wouldn't have factored it out into a new function. (This would also address the namespace discussion in this PR.)
unit/src/expr/require_expr.cpp
Outdated
|
||
/// \file | ||
/// Helper functions for requiring specific expressions | ||
/// If the expression is of the wrong type, through a CATCH exception |
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.
through -> throw
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.
Looks good to me. Not sure about the namespace-esque usage of a class. I would prefer to use a proper namespace, as this code has confusing/misleading semantics.
|
||
#include <util/symbol.h> | ||
|
||
class symbol_table_utilt |
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.
Pretty sure this should be a namespace.
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.
You're quite right - @peterschrammel would this be an acceptable use of a namespace
?
8e627a0
to
02fe8bd
Compare
@tautschnig Added as an additional constructor to @reuk This "resolves" the issue of |
Sorry to be awkward but I think require_exprt should probably be a namespace too. |
As much as I'd otherwise argue against namespaces: unit tests may be a good use of them to separate out code that is exclusively of use for testing purposes. |
unit/src/expr/require_expr.h
Outdated
|
||
#include <util/std_expr.h> | ||
|
||
class require_exprt |
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.
@peterschrammel would it be OK as suggested by @reuk for me to make this into a namespace
, I know they are forbidden by coding standard but I don't really understand why.
As discussed in #1070 rather than |
02fe8bd
to
ddb728f
Compare
@reuk @peterschrammel @tautschnig I have added a commit swapping |
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.
Otherwise looks good to me.
unit/src/expr/require_expr.h
Outdated
|
||
#include <util/std_expr.h> | ||
|
||
namespace require_exprt |
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.
Not sure the t
suffix is useful then.
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.
Requires a nolint or a change in the linting rules.
020dfd7
to
423bc70
Compare
@peterschrammel Changes applied and namespace change squashed. |
@thk123 Would it be possible to rebase this one and make all CI tests pass? It seems the need for linking adjustments in unit/Makefile is starting to show in other branches/PRs as well. Thanks! |
ee9af0f
to
1520cf9
Compare
@tautschnig I think I've modified the |
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.
Looks good to me!
Previously the order of the libraries in LIB would effect whether the unit tests compiled. Use OBJ rather than LIBS to ensure the --start-group/--end-group flags are used in linking. Previously, if a file in CProver changed, though the libraries would be rebuilt, the unit tests wouldn't be relinked against the new library, meaning you would get out of date binaries. This change ensures that the link process is rerun if any of the libraries are rebuilt. Adding dependency to cprover libs for other unit executables
Use namespace rather than class with static functions as more semantically correct.
In turns the error return state into a CATCH exception so the test will fail without cluttering tests with checks on the flag when it is just setup code for the actual test.
The auxilary function had the same flags requried for the test, so added a utility constructor that allows specifying of name and type.
1520cf9
to
e3f8d4a
Compare
@kroening All fixed and squashed, could I get a merge as I understand from @tautschnig that the lack of Makefile changes is causing other issues. |
I developed some utilities and fixed the Makefile for the
unit
directory. Rather than wait for that work to make its way to master, here are those improvements as they may be useful to others.Would like some feedback on the directory structure - I wanted to keep utility code separate from the unit tests themselves. If people agree, I can add this to the coding standard.