You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The list is quite long. In contrast, while working on #45448 I noted that the new T.Setenv could be used only in few cases.
There is an interesting fact in the list: the perm argument is not always 0644; the interesting cases are 0 (in one cases it is for windows so it make senses) and 0755 used on non executable files.
Using the proposed TB.WriteFile should reduce a bit of noise in the tests.
I'm not sure if TB.WriteTempFile(name, data string) string (where the returned value is the file name) is a better API (assuming that each call of TB.WriteTempFile reuses the same temporary directory).
Thanks.
The text was updated successfully, but these errors were encountered:
perillo
changed the title
proposal: add TB.WriteFile(name string, data string)
proposal: add TB.WriteFile(name string, data string) string
Apr 14, 2021
The T.Setenv function is useful because it sets global state and then undoes that global state when the test is complete. That is code that it is easy for a test to get wrong, so it makes some sense to provide as part of the testing package.
That argument doesn't apply here. There is nothing specific to the testing package about providing a function that writes a string to a file with a default mode. We could do that in the os package.
This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group
While working on some CL on the tests I noted a common pattern: calling
os.WriteFile
to create a temporary file using a string as input.Here is the list, obtained using
grep -F "os.WriteFile(" **/*_test.go | grep -F '[]byte'
:The list is quite long. In contrast, while working on #45448 I noted that the new
T.Setenv
could be used only in few cases.There is an interesting fact in the list: the
perm
argument is not always 0644; the interesting cases are0
(in one cases it is for windows so it make senses) and0755
used on non executable files.Using the proposed
TB.WriteFile
should reduce a bit of noise in the tests.I'm not sure if
TB.WriteTempFile(name, data string) string
(where the returned value is the file name) is a better API (assuming that each call ofTB.WriteTempFile
reuses the same temporary directory).Thanks.
The text was updated successfully, but these errors were encountered: