digitalmars.D.learn - Just-run-the-unittests
- Sergei Nosov (8/8) Mar 16 2014 Hi!
- safety0ff (14/18) Mar 16 2014 Here's the first thing that came to mind:
- Sergei Nosov (4/23) Mar 16 2014 Thx! That's better, but I think -main switch could be made to
- Andrej Mitrovic (3/6) Mar 16 2014 It can't work, because main could be stored in a pre-built object or
- Rikki Cattermole (6/9) Mar 16 2014 Hmm I really should consider making a DIP for a deferred CTFE
- Dicebot (4/13) Mar 16 2014 Linker will still complain about duplicate symbols. This issue
- Rikki Cattermole (3/19) Mar 16 2014 I was inferring that no stub _Dmain would be added. Since it
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.
Mar 16 2014
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.
Mar 16 2014
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: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?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.
Mar 16 2014
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.
Mar 16 2014
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.
Mar 16 2014
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:Linker will still complain about duplicate symbols. This issue can't be solved within existing C-compatible object file toolchain.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.
Mar 16 2014
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:I was inferring that no stub _Dmain would be added. Since it would no longer be called.On Sunday, 16 March 2014 at 10:15:00 UTC, Andrej Mitrovic wrote:Linker will still complain about duplicate symbols. This issue can't be solved within existing C-compatible object file toolchain.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.
Mar 16 2014