[Bug d/103728] Allow to run unittests before main()
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103728 Pierrick Bouvier changed: What|Removed |Added Resolution|--- |FIXED Status|UNCONFIRMED |RESOLVED --- Comment #5 from Pierrick Bouvier --- gdc does not have to support this use case, since it is related to D runtime.
[Bug d/103728] Allow to run unittests before main()
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103728 --- Comment #4 from Pierrick Bouvier --- Thanks for your suggestion. We will follow this to upgrade our compiler.
[Bug d/103728] Allow to run unittests before main()
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103728 --- Comment #3 from Iain Buclaw --- (In reply to Pierrick Bouvier from comment #2) > Problem with command line approach is that it implies to patch all our > scripts, which is *really* boring. At this point, manually adding rt_options > string in all binaries is easier. > > Alas, there is no environment variable for controlling this. Environment variables can be used if you declare: ``` extern(C) __gshared bool rt_envvars_enabled = true; ``` Then DRT_testmode=run-main should work.
[Bug d/103728] Allow to run unittests before main()
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103728 --- Comment #2 from Pierrick Bouvier --- Problem with command line approach is that it implies to patch all our scripts, which is *really* boring. At this point, manually adding rt_options string in all binaries is easier. Alas, there is no environment variable for controlling this. When unittests semantic was changed in dmd, from what I read, dmd maintainers were not open to keep an "old" mode as a compiler option. I understand it's not the role of gdc to control this, but I still think it could be useful to offer a flag (that automatically generates rt_options symbol).
[Bug d/103728] Allow to run unittests before main()
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103728 --- Comment #1 from Iain Buclaw --- Not sure if there'd be much help from the compiler on this front, as it's a runtime library feature that unittests are executed in the first place - the compiler simply generates functions in the proper place for the library to find them. See https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=libphobos/libdruntime/rt/dmain2.d;h=b363e3fea4fc55d9f6941030dc808e5129bd38c2;hb=HEAD#l491 The old behaviour was of `runAll()` was: if (rt_init() && runModuleUnitTests()) tryExec({ result = mainFunc(args); }); > someone suggested to use this: > version (unittest) extern(C) __gshared string[] rt_options = [ "testmode=run- > main" ]; > It works well with gdc-12, but it is very cryptic and still hard to add in all > our binaries (we have dozens). A second way of doing the would be to run the program with the command-line option: --DRT-testmode=run-main The options itself gets filtered from the `string[] args` parameter of D main, so it won't affect tests where arguments are given to binaries (unless the --DRT option appears after `--`).