From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8A71F3858D35; Wed, 15 Dec 2021 22:57:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A71F3858D35 From: "ibuclaw at gdcproject dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug d/103728] Allow to run unittests before main() Date: Wed, 15 Dec 2021 22:57:41 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: d X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ibuclaw at gdcproject dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: ibuclaw at gdcproject dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Dec 2021 22:57:41 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103728 --- 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=3Dgcc.git;a=3Dblob;f=3Dlibphobos/libdruntime/rt/= dmain2.d;h=3Db363e3fea4fc55d9f6941030dc808e5129bd38c2;hb=3DHEAD#l491 The old behaviour was of `runAll()` was: if (rt_init() && runModuleUnitTests()) tryExec({ result =3D mainFunc(args); }); > someone suggested to use this: > version (unittest) extern(C) __gshared string[] rt_options =3D [ "testmod= e=3Drun- > main" ]; > It works well with gdc-12, but it is very cryptic and still hard to add i= n 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=3Drun-main The options itself gets filtered from the `string[] args` parameter of D ma= in, so it won't affect tests where arguments are given to binaries (unless the --DRT option appears after `--`).=