Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
March 16, 2014 Just-run-the-unittests | ||||
---|---|---|---|---|
| ||||
Hi! Suppose I have a small .d script that has a main. Is there any simple way to just run the unit tests without running main at all? I thought -main switch was intended for this, but apparently it works only if there's no main defined at all, otherwise, it issues a double main definition error. I could place main into a separate module but its really awkward to create 2 files for a small script. |
March 16, 2014 Re: Just-run-the-unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sergei Nosov | On Sunday, 16 March 2014 at 07:59:33 UTC, Sergei Nosov wrote:
> Hi!
>
> Suppose I have a small .d script that has a main. Is there any simple way to just run the unit tests without running main at all?
Here's the first thing that came to mind:
If you never want to both unit tests and regular main:
---- code begins ----
import std.stdio;
version(unittest) void main(){}
else
void main() { writeln("Hello world!"); }
unittest { writeln("Hello unit testing world!"); }
---- code ends ----
If you sometimes want to have your normal main with unit testing you can replace "version(unittest)" with "version(nopmain)" or some other custom version identifier and compile with -version=nopmain when you want the dummy main.
|
March 16, 2014 Re: Just-run-the-unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to safety0ff | On Sunday, 16 March 2014 at 08:22:04 UTC, safety0ff wrote:
> On Sunday, 16 March 2014 at 07:59:33 UTC, Sergei Nosov wrote:
>> Hi!
>>
>> Suppose I have a small .d script that has a main. Is there any simple way to just run the unit tests without running main at all?
>
> Here's the first thing that came to mind:
> If you never want to both unit tests and regular main:
> ---- code begins ----
> import std.stdio;
> version(unittest) void main(){}
> else
> void main() { writeln("Hello world!"); }
>
> unittest { writeln("Hello unit testing world!"); }
> ---- code ends ----
>
> If you sometimes want to have your normal main with unit testing you can replace "version(unittest)" with "version(nopmain)" or some other custom version identifier and compile with -version=nopmain when you want the dummy main.
Thx! That's better, but I think -main switch could be made to work like 'add or replace main by stub' instead of just 'add'. I don't think it'll hurt anybody, what do you think?
|
March 16, 2014 Re: Just-run-the-unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sergei Nosov | On 3/16/14, Sergei Nosov <sergei.nosov@gmail.com> wrote:
> Thx! That's better, but I think -main switch could be made to work like 'add or replace main by stub' instead of just 'add'. I don't think it'll hurt anybody, what do you think?
It can't work, because main could be stored in a pre-built object or static library that's passed to DMD.
|
March 16, 2014 Re: Just-run-the-unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Sunday, 16 March 2014 at 10:15:00 UTC, Andrej Mitrovic wrote:
> It can't work, because main could be stored in a pre-built object or
> static library that's passed to DMD.
Hmm I really should consider making a DIP for a deferred CTFE block. Could really come in handy for a situation like this. In the format of if -main specified use e.g. -version=D_Main to remove the call to _Dmain symbol. Removes the whole linker issue altogether.
|
March 16, 2014 Re: Just-run-the-unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | On Sunday, 16 March 2014 at 12:57:04 UTC, Rikki Cattermole wrote:
> On Sunday, 16 March 2014 at 10:15:00 UTC, Andrej Mitrovic wrote:
>> It can't work, because main could be stored in a pre-built object or
>> static library that's passed to DMD.
>
> Hmm I really should consider making a DIP for a deferred CTFE block. Could really come in handy for a situation like this. In the format of if -main specified use e.g. -version=D_Main to remove the call to _Dmain symbol. Removes the whole linker issue altogether.
Linker will still complain about duplicate symbols. This issue can't be solved within existing C-compatible object file toolchain.
|
March 16, 2014 Re: Just-run-the-unittests | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dicebot | On Sunday, 16 March 2014 at 20:22:15 UTC, Dicebot wrote:
> On Sunday, 16 March 2014 at 12:57:04 UTC, Rikki Cattermole wrote:
>> On Sunday, 16 March 2014 at 10:15:00 UTC, Andrej Mitrovic wrote:
>>> It can't work, because main could be stored in a pre-built object or
>>> static library that's passed to DMD.
>>
>> Hmm I really should consider making a DIP for a deferred CTFE block. Could really come in handy for a situation like this. In the format of if -main specified use e.g. -version=D_Main to remove the call to _Dmain symbol. Removes the whole linker issue altogether.
>
> Linker will still complain about duplicate symbols. This issue can't be solved within existing C-compatible object file toolchain.
I was inferring that no stub _Dmain would be added. Since it would no longer be called.
|
Copyright © 1999-2021 by the D Language Foundation