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

Fix START_TEST to look like valid C code. #158

Merged
merged 2 commits into from
Jun 20, 2018

Conversation

filbranden
Copy link
Contributor

Instead of exporting the defined name as a bare function, export a struct that has a pointer to the function, but also its name, file and line number where it is defined.

Store that information into a new struct TTest.

After this commit, START_TEST(testname) will create three definitions:

  • testname_fn: The actual function;
  • testname_ttest: A struct TTest with the information about it;
  • testname: A pointer to testname_ttest.

Functions tcase_add_test() and friends are updated to take a TTest * argument rather than a TFun and separate name. The runners are updated to find that information inside the linked tc->ttest. The call to tcase_fn_start() is moved from the defined functions to the runners (both the "fork" and the "nofork" one) which call it just before invoking the test function.

A nice side-effect is that END_TEST is now optional, though the empty #define is kept for backwards compability.

Tested:

  • make check still passes.
  • Removing END_TEST from test cases still produces valid code that builds and passes tests.

This PR should address this TODO item.

NOTE: I'm not 100% sure I like the name TTest but I wonder what would be a better name for that item... I thought of TFunc but that's too similar to TFun. What would you call that? A test fixture? A test function? A test method? Clarifying the terminology would be helpful here...

Cheers!
Filipe

@brarcher
Copy link
Contributor

Jenkins: ok to test
^ will kick off remaining tests

@brarcher
Copy link
Contributor

The AppVeyor failures are with the 2010 and 2012 Visual Studio releases not supporting inline initialization of structs. Errors like the following are reported:

C:\projects\check\tests\check_check_exit.c(31): error C2059: syntax error : '.' [C:\projects\check\tests\check_check.vcxproj]

The versions after that, namely 2013, 2015, and 2017, do not find an issue. Check does not claim it supports specific versions of that compiler, only that it supports it. It may be acceptable to drop support for the older versions.

The other checker, "default" is a Jenkins job which is failing to clone from the pull request. I'll need to look into that.

The change look good to me at first pass. I'll look over it a little more carefully.

@filbranden
Copy link
Contributor Author

The AppVeyor failures are with the 2010 and 2012 Visual Studio releases not supporting inline initialization of structs.

I imagine they don't support initialization with named fields, but if we do initialization by position that might fix it.

Instead of:

static const TTest __testname ## _ttest = {\
  .name = ""# __testname,\
  .fn = __testname ## _fn,\
  .file = __FILE__,\
  .line = __LINE__,\
};\

We would use:

static const TTest __testname ## _ttest = { ""# __testname, __testname ## _fn, __FILE__, __LINE__ };\

Which is OK, not that bad to read...

Let me know if you'd like me to push something like that.

Otherwise, we could add a requirement on whatever C standard (C99? C11?) specified the ability to include named fields in struct initialization...

@brarcher
Copy link
Contributor

brarcher commented Jun 14, 2018 via email

@filbranden
Copy link
Contributor Author

Try pushing a change to initialize by position and see if it builds. If it does, we'll go with it.

Done, let's see how that goes... Thanks!

@brarcher
Copy link
Contributor

Hm, it still seems unhappy:

check_check_exit.c(31): error C2059: syntax error : '.' [C:\projects\check\tests\check_check.vcxproj]

but I do not see that your second push changed the code. Did your second attempt include the change?

Instead of exporting the defined name as a bare function, export a
struct that has a pointer to the function, but also its name, file and
line number where it is defined.

Store that information into a new `struct TTest`.

After this commit, START_TEST(<testname>) will create three definitions:
- <testname>_fn: The actual function;
- <testname>_ttest: A `struct TTest` with the information about it;
- <testname>: A pointer to <testname>_ttest.

Functions `tcase_add_test()` and friends are updated to take a `TTest *`
argument rather than a `TFun` and separate name. The runners are updated
to find that information inside the linked `tc->ttest`. The call to
`tcase_fn_start()` is moved from the defined functions to the runners
(both the "fork" and the "nofork" one) which call it just before
invoking the test function.

A nice side-effect is that END_TEST is now optional, though the empty
`#define` is kept for backwards compability.

v2: Initialize the struct TTest by position to be compatible with older
compilers that do not recognize named fields (e.g. VS 2010, VS 2012.)

Tested:
- `make check` still passes.
- Removing END_TEST from test cases still produces valid code that
  builds and passes tests.
@filbranden
Copy link
Contributor Author

I had changed check.h instead of check.h.in, duh... Fixed now, let's see how it goes.

@brarcher
Copy link
Contributor

That make the Visual Studio build much happier.

I think I figured out what broke with the Jenkins job, a change on GitHub's side to deprecate weak crypto that the job was using. That should now be resolved, and I'll rekick the job.

Jenkins: retest this please

@brarcher
Copy link
Contributor

Jenkins will fetch now, but the updated Jenkins nodes are missing at least one tool. I'll need to have it installed so the various builds and tests can make it through. I've sent a request to have the tool installed, and when it is I'll rekick.

@filbranden
Copy link
Contributor Author

Sounds good, thanks!

By the way, do you like the name TTest? I wasn't too sure about it... Is the right terminology to have TestSuite → TestCase → Test? I thought of "Test Function" but the name TFun is already taken (and TFunc would be too similar...) Let me know if you'd like any changes in this area...

Cheers!
Filipe

@filbranden
Copy link
Contributor Author

Hi @brarcher, let me know if you still require an action on my part. (For instance, if Jenkins is now fixed, would you like me to touch my tree, pushing a no-op change like a git commit --amend with no additional changes, just to trigger it again?)

Thanks!
Filipe

@brarcher
Copy link
Contributor

I got a response from CloudBees, who provides the Jenkins instances for free to FOSS projects. They said it would take over a day for an engineer to fix the VMs to install the missing package, and they did not want to do it. In response to this, I'll need to move all the tests off of Jenkins and onto Travis-CI. When I finish that, I'll merge master into the task branch, which will kick off the tests again.

I cannot think of a better term for TTest. Calling it a 'fixture' may be good, such as TestFixture. Though, the name does not mean anything without context.

If you want to change TTest to TestFixture (or another name if one comes to mind), besides that you should have nothing to do on your side if the tests which I'll port to Travis-CI pass. If one of the tests do find an issue, I'll poke you.

@brarcher
Copy link
Contributor

I've moved the automated tests to Travis-CI here, and am updating the branch to pick up these changes.

@brarcher
Copy link
Contributor

All the tests passed, the change is good to go. Thanks for the contribution. If you would like to submit a merge request adding yourself to the AUTHORS file, feel free.

@brarcher brarcher merged commit 4636fef into libcheck:master Jun 20, 2018
brarcher added a commit that referenced this pull request Jun 20, 2018
This TODO was addressed here:

#158
3987c1d
@brarcher brarcher mentioned this pull request Jun 20, 2018
@ThomasHabets
Copy link

Looks like this change makes it impossible to create a test registry, since now the actual function is not predictable. It also doesn't seem possible to be version agnostic about this breaking change.

Do you have a recommendation for how to do this in a way that works before and after this change?

@ThomasHabets
Copy link

Alternatively, do you have a macro I can #ifdef on to duplicate my code for before and after this change?

ThomasHabets added a commit to ThomasHabets/arping that referenced this pull request Jan 20, 2021
As of libcheck/check#158 libcheck broke the
ability to have a test registry, so we have to resort to code duplication.
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.

3 participants