D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 20180 - Deprecated unittests should not be deprecated functions
Summary: Deprecated unittests should not be deprecated functions
Status: NEW
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 major
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-29 10:01 UTC by FeepingCreature
Modified: 2024-12-13 19:05 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description FeepingCreature 2019-08-29 10:01:19 UTC
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 FeepingCreature 2019-08-29 10:36:14 UTC
(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 Mathias LANG 2020-02-26 03:56:21 UTC
What about using `__traits(isDeprecated)` ?
Comment 3 FeepingCreature 2020-02-26 04:32:57 UTC
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 Mathias LANG 2020-02-26 06:07:58 UTC
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 dlangBugzillaToGithub 2024-12-13 19:05:19 UTC
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