Comments (4)
(Or maybe TEST_PROCESS_INIT
instead of TEST_GLOBAL_INIT
. That's even more descriptive.)
from acutest.
I'm fine with the proposal in principle.
But I would prefer it is named differently, e.g. TEST_INIT
or TEST_GLOBAL_INIT
(and *_FINI
respectivelly):
- All our public interface identifiers begin with
TEST_
. _CTOR
/_DTOR
sounds too C++-like to me and I'm afraid people might expect it gets called before/aftermain()
(e.g. even before their own global constructors).
Secondly, if you want e.g. to just call setlocale()
, isn't expecting a function name as the macro expansion too uncomfortable? You'd have often to implement a dummy wrapper function. Shouldn't we rather allow any C block?
Then you could just to do e.g. something like this:
#define TEST_INIT { setlocale(... any args ...); }
instead of the much more verbose
void
my_init(void)
{
setlocale(... any args ...);
}
#define TEST_INIT my_init
Finally, I am wondering whether the start/end of main()
is the best possible call site for it. It would mean that it gets called exactly once on Unix or whenever with --no-exec
, but more then once on Windows (which calls CreateProcess()
for the child processes per every test, unless --no-exec
is used). And it would get called even when e.g. --help
is used, which may be a bad idea if the function connects to a remote server or to a database for example.
Unless you plan something time-expensive there, wouldn't it be better to call it from beginning/end of test_do_run_()
? That way, it would have the exactly same semantics no mater what: It would always be called exactly once per every executed test.
Or, perhaps, we could offer both? TEST_INIT
per every test and TEST_GLOBAL_INIT
from main()
(but rather after the command line is parsed)? Just thinking aloud here.
from acutest.
As using preprocessor is often tricky, especially when one wants to have it reasonably flexible and foolproof, I've played a little bit with it to see how the execute-the-macro pattern could look like. I have ended with this:
#include <stdio.h>
// Test suite side:
// ================
//#define X /* empty definition */
//#define X printf("foo\n") /* single call; no semicolon */
//#define X printf("foo\n"); /* single call; with semicolon */
//#define X const char* str = "foo\n"; printf(str) /* using a var. declaration */
//#define X printf("foo"); printf("\n"); /* multiple calls */
//#define X { printf("foo"); printf("\n"); } /* a whole code block */
// Acutest side:
// =============
static void
call_X(void)
{
#ifdef X
X
#endif
;
}
int
main(int argc, char** argv)
{
call_X();
return 0;
}
Notes:
- It works with all the example macro definitions listed (as well as when X is not defined, of course).
- However it does not work if the user specifies just a function name as in the original post. Must be
#define X my_constructor()
and not#define X my_constructor
, i.e. the parenthesis are required. - It uses a helper function which serves two purposes:
- It allows X to declare helper variables (even when the user does not enclose it in a code block).
- It makes sure the X expansion cannot reach our local variables in our internal function where we want to execute the initialization.
Is it foolproof and flexible for practical use? Or any better idea?
from acutest.
Sorry for disappearing. A stressful release led me to take a week's "holiday".
That looks very nice.
from acutest.
Related Issues (20)
- reserved identifier violation HOT 2
- Completion of error handling HOT 2
- #define ⇒ enum?
- Windows outputs "Debug Error - Abort() was called" on every failed test HOT 2
- TEST_STRING_EQUAL method HOT 2
- Compile works but program does not finish and takes 100% CPU ?! HOT 3
- Memory leak in children HOT 2
- Call cleanup handler after assert fail HOT 4
- travisci C std 17 HOT 1
- How can I compile multiple units to one executable? HOT 1
- Any way to test for a non-zero exit(status) condition? HOT 3
- flush stdout and stderr before aborting
- Allow TEST_CHECK for non-int conditions
- Can acutest add support like doctest's DOCTEST_CONFIG_DISABLE?
- Provide TEST_SKIP(message) macro
- Warning `warning: variable length array folded to constant array as an extension` on Clang 10 HOT 2
- Is this repo abandoned? HOT 2
- Any way to figure out code coverage or lines not covered? HOT 1
- Can exception handling be disabled for use in testing embedded C++ systems? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from acutest.