Add ability to override DFLAGS env variable in test suite#7845
Add ability to override DFLAGS env variable in test suite#7845wilzbach merged 1 commit intodlang:masterfrom JinShil:dflags
Conversation
|
Thanks for your pull request, @JinShil! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
|
The CI failures are correct but unrelated to this PR - see #7838 (comment) |
Interesting. Shouldn't it overwrite the default I fear a bit that exposing |
Line 677 in c55c9be A |
Same here. It was just an idea. Has someone a (strong) opinion about this? |
|
After giving this some thought, I think the |
test/d_do_test.d
Outdated
|
|
||
| // Clear the DFLAGS environment variable if it was specified in the test file | ||
| if (testArgs.noDflags) | ||
| environment.remove("DFLAGS"); |
There was a problem hiding this comment.
edit: ah I see `-conf=` is already set at other parts here.
wilzbach
left a comment
There was a problem hiding this comment.
Looks reasonable to me.
|
Shouldn't do the trick of setting it to nothing? |
Where? In Originally, I created a It could be argued that we could simplify the test suite by removing all the other test variables and only allowing |
Sorry, the in there unless one wants to clear DFLAGS.
Good point. Just don't allow anything for I.e. just rename |
Not by me. |
I bet this will confuse people and they will waste time wondering why |
I agree. @WalterBright, can we convince you to keep this PR as is and support |
test/d_do_test.d
Outdated
| { | ||
| string file = cast(string)std.file.read(input_file); | ||
|
|
||
| string ignore; |
There was a problem hiding this comment.
I would put ignore in it's own scope
{
string ignore;
testArgs.noDflags = findTestParameter(envData, file, "NO_DFLAGS", ignore);
}
|
I wonder how many tests don't need druntime/phobos? Probably the majority correct? Maybe the better solution is to have DFLAGS be "opt-in" instead of "opt-out"? Would also make it a bit clearer that using druntime/phobos should be the "atypical" case. |
I bet most, if not all, don't need Phobos, but I'd be willing to bet 99.9% need druntime simply because of |
How? I set/reset env variables all the time, and setting them to nothing is
If they set |
Ah ok, nevermind then :) |
|
@wilzbach Keep in mind that you have another PR with |
|
|
|
Yes, I believe we'll have to use |
|
|
I was talking about things like: // DFLAGS: -version=Foo
version(Foo) {
... // this is never executed, but assumed by contributor and reviewers to be executed & tested
}
Maybe it should have been named
Ok. We should do this no matter how the variable is named.
That would imply we should use CC @CyberShadow who has always shown a lot of wisdom in such CLI usability questions. |
|
OK, I've implemented I still need to figure out why this isn't working for Windows though. |
test/d_do_test.d
Outdated
| if (testArgs.dflags != "") | ||
| throw new Exception("The DFLAGS test argument must be empty"); | ||
|
|
||
| environment["DFLAGS"] = testArgs.dflags; |
|
Clearing the environment variable with |
|
I tried calling Win32 API function |
|
It looks like |
Isn't the process executing
|
|
Ah, it looks like // string is defined in object.d, this should guarantee that object.d is getting loaded
static assert(string.sizeof > 0); |
| @@ -0,0 +1,15 @@ | |||
| /* | |||
| DFLAGS: | |||
| REQUIRED_ARGS: | |||
There was a problem hiding this comment.
Try -v here to debug win32
(edit: I just tried this for you)
There was a problem hiding this comment.
I did. See the result here: https://auto-tester.puremagic.com/show-run.ghtml?projectid=1&runid=3027610&isPull=true
import object (....\druntime\import\object.d)
I don't know where that's coming from.
There was a problem hiding this comment.
(edit: I just tried this for you)
You'll probably want to disable other platforms or the auto-tester will fail and will never get around to running the test in question.
There was a problem hiding this comment.
Oh sorry. Feel free to drop my commit.
We should really print D_FLAGS with -v too ...
There was a problem hiding this comment.
We should really print D_FLAGS with -v too ...
#7865 - this might help you.
The OMF library snn.lib has putenv, too, it just isn't declared in core.stdc.stdlib. Using |
|
Thanks @rainers. Using This should now be ready to go. |
|
Should a bug be filed for |
Yes. If I can create an isolated test case, I'll file a bug. |
|
Phew! What a chore that turned out to be. I had to make a couple of changes (it worked once and then started failing again... weird). This should be ready to go now. I'll file a bug for std.process after I get in front of a Windows machine, and assuming I can reproduce the problem in an isolated test. |
|
I've created an issue so we don't forget to address this: https://issues.dlang.org/show_bug.cgi?id=18425 |
test/d_do_test.d
Outdated
| version(Win32) | ||
| { | ||
| char[] varExpression = cast(char[])"DFLAGS=\0"; | ||
| putenv(varExpression.ptr); |
There was a problem hiding this comment.
Declaring extern(C) int putenv(const char *); globally and calling putenv("DFLAGS="); worked for me. The literal already has the trailing zero and converts implicitly.
|
I suspect the issue is that SetEnvironmentVariable is called with an empty string, while removal should be done with a null argument. Not sure why this works for Win64, though. |
|
Hmmm, but deleting DFLAGS or setting it to an empty string should still produce the same result... |
I tried calling |
|
Might have something to do with mixing native windows functions with posix. The system posix function may not pick up environment variables from SetEnvironmentVariable |
Maybe the empty string is silently ignored. Both snn.lib and libcmt.lib implement putenv via SetEnvironmentVariable and convert it to the null parameter for removal. |
|
Thanks a lot @JinShil @rainers @marler8997 for this diligent debugging work. We should really look into fixing |
The test suite makefile adds the import directories for druntime and phobos to the
DFLAGSenvironment variable:dmd/test/Makefile
Lines 173 to 177 in c55c9be
This makes it impossible to write tests for no- or minimal-runtime programming, due to the implicit import of object.d. See #7825 for evidence.
This PR adds a
DFLAGS:test variable that clears theDFLAGSenvironment variable enabling us to write no- or minimal-runtime tests among other potential possibilities.