Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecated unittests should not be deprecated functions #17921

Open
dlangBugzillaToGithub opened this issue Aug 29, 2019 · 4 comments
Open

Deprecated unittests should not be deprecated functions #17921

dlangBugzillaToGithub opened this issue Aug 29, 2019 · 4 comments

Comments

@dlangBugzillaToGithub
Copy link

FeepingCreature (@FeepingCreature) reported this on 2019-08-29T10:01:19Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=20180

CC List

Description

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.
@dlangBugzillaToGithub
Copy link
Author

default_357-line (@FeepingCreature) commented on 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.)

@dlangBugzillaToGithub
Copy link
Author

pro.mathias.lang (@Geod24) commented on 2020-02-26T03:56:21Z

What about using `__traits(isDeprecated)` ?

@dlangBugzillaToGithub
Copy link
Author

default_357-line (@FeepingCreature) commented on 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.

@dlangBugzillaToGithub
Copy link
Author

pro.mathias.lang (@Geod24) commented on 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant