rogpeppe / go-internal

Selected Go-internal packages factored out from the standard library
BSD 3-Clause "New" or "Revised" License
823 stars 67 forks source link

testscript: Add TestScript.Unsetenv #233

Closed bep closed 11 months ago

bep commented 11 months ago

I'm setting up a set of common environment variables in *testscript.Env in a Setup func, which works great. But there are some tests that needs to run without some of these.

This should allow me to create a command so I could do:

unset MY_ENV_VAR
mvdan commented 11 months ago

Out of curiosity, why not env MY_ENV_VAR=? That's what I've done in the past, since practically all software treats an empty variable as equivalent to a missing variable.

I don't oppose Unsetenv for what it's worth, I just wonder how often it would actually be necessary.

bep commented 11 months ago

Out of curiosity, why not env MY_ENV_VAR=?

You are right. I tried MY_ENV_VAR="" which (obviously now I guess) didn't work, but as you say, env MY_ENV_VAR= works fine for me.