Bug 20180 – Deprecated unittests should not be deprecated functions

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2019-08-29T10:01:19Z
Last change time
2024-12-13T19:05:19Z
Assigned to
No Owner
Creator
FeepingCreature
Moved to GitHub: dmd#17921 →

Comments

Comment #0 by default_357-line — 2019-08-29T10:01:19Z
When deprecated unittests are accessed with __traits(getUnitTests), the resulting functions are deprecated. Since it is impossible to get rid of deprecated, this fatally breaks unittesting frameworks like unit_threaded with deprecated unittests, or else forces the entire framework to be considered deprecated.
Comment #1 by default_357-line — 2019-08-29T10:36:14Z
(This issue has come up in dmd nightly because deprecations from nested functions and mixins used to be ignored, which allowed unit-threaded to work without complaint.)
Comment #2 by pro.mathias.lang — 2020-02-26T03:56:21Z
What about using `__traits(isDeprecated)` ?
Comment #3 by default_357-line — 2020-02-26T04:32:57Z
I mean, it'll still be deprecated. The problem isn't determining whether a unittest is deprecated, the problem is calling it from a nondeprecated function.
Comment #4 by pro.mathias.lang — 2020-02-26T06:07:58Z
Oh right. Yeah we probably need a way for framework to handle deprecated. I wonder if it should be limited to unittests, or extended. For example you could have a fuzzing framework that iterates over functions and generate fuzzing code. You don't want to stop testing functions as soon as they're deprecated, but you don't want to trigger the message either. For the moment, a possible workaround is: ``` import std.traits; deprecated @safe pure unittest { } string funAttrToString (uint attrs) { string result; if (attrs & FunctionAttribute.pure_) result ~= " pure"; if (attrs & FunctionAttribute.nothrow_) result ~= " nothrow"; if (attrs & FunctionAttribute.property) result ~= " @property"; if (attrs & FunctionAttribute.trusted) result ~= " @trusted"; if (attrs & FunctionAttribute.safe) result ~= " @safe"; if (attrs & FunctionAttribute.nogc) result ~= " @nogc"; if (attrs & FunctionAttribute.system) result ~= " @system"; if (attrs & FunctionAttribute.const_) result ~= " const"; if (attrs & FunctionAttribute.immutable_) result ~= " immutable"; if (attrs & FunctionAttribute.inout_) result ~= " inout"; if (attrs & FunctionAttribute.shared_) result ~= " shared"; if (attrs & FunctionAttribute.return_) result ~= " return"; return result; } void main () @safe pure { static foreach (ut; __traits(getUnitTests, mixin(__MODULE__))) { static if (__traits(isDeprecated, ut)) { mixin(`extern(C) void `, ut.mangleof, `()`, funAttrToString(functionAttributes!ut),`;`); typeof(&ut) workaround = &mixin(__traits(identifier, ut)); workaround(); } else ut(); } } ``` However this relies on the fact that using `ut` in `__traits(identifier)` and `typeof` does not trigger a deprecation. Perhaps simply extending `__traits(isDeprecated)` to support: `__traits(isDeprecated, ut, () { doThis(); })` would be enough.
Comment #5 by robert.schadek — 2024-12-13T19:05:19Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17921 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB