Skip to content
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

Added unit test infrastructure #24

Merged
merged 54 commits into from
May 2, 2015

Conversation

perlun
Copy link
Contributor

@perlun perlun commented Apr 22, 2015

This adds infrastructure for unit testing, plus 5 very simplistic test cases. It's now trivial to add more as we go along. Can be good when working with the existing code base, to try and squeeze out bugs.

perlun added 30 commits April 21, 2015 19:10
That way, the list is much more easy to read and diffs (when adding new packages) are much more obvious. It's not a problem with the vertical space in this file anyway.
cmocka (http://cmocka.org) is a unit testing framework for C which seems to be actively maintained and reasonable. Let's give it a try, since there are very clear areas in the chaos system that would be much easier to maintain with unit testing/TDD in place.
This has been suggested as a FIXME in one of the Rakefiles. Now, we're moving towards this, by taking small steps, one at a time. This fix supports both scenarios - CFLAGS can be an array, or a string, and the common_rules.rake file will support both ways.
…mes.

Also started doing some cleanup in the Rakefile.
The right approach here would be something like http://stackoverflow.com/a/1139148/227779 but this should also work, even though it is not the proper way to do it.
perlun added 24 commits April 24, 2015 21:39
… tests.

This also involved some "moving around" of methods, so that they are listed in the order in which they are called. The code is IMHO more readable that way.
Function prototypes are really only a necessary evil. For methods defined in unit tests, they serve no other purpose than to make one annoyed about the fact how primitive the C programming language is.
After all, this is unit tests. Adding this warning does not add any value whatsoever.
Weak symbols are quite useful for this. I looked into using the --wrap function in GNU ld instead, but the problem is that it only works for *undefined* functions, and I don't want to have to mess around with linking a special .a file just for the tests. So making them weak and just overriding them is simpler (since I have need for calling the underlying methods; at least not yet).
…eallocate.

This is unfortunately all but trivial. The problem is that the code hasn't really been written with testability in mind. Is it worth it? one may ask. "I don't know" is the simple answer. In some ways, yes: it makes sense to have an infrastructure for tests so we can easily (at a very low cost) add more tests later. But maybe this (memory_global_allocate et al) are just a few bad examples and it would make more sense to add tests for e.g. string_to_number and such - methods which have very few external dependencies etc.
perlun added a commit that referenced this pull request May 2, 2015
@perlun perlun merged commit d6f372c into master May 2, 2015
@perlun perlun deleted the feature/added-unit-test-infrastructure branch May 2, 2015 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant