Skip to content

proposal: testing: add Setargs to set os.Args #63607

Description

@mitar

os.Args is similar to os.Getenv that it is a global state of the process. testing package provides a function Setenv on T which tries to help tests which use environment variables:

  • It makes sure that such tests are not run in parallel.
  • It makes sure to restore env after the test.

Currently, nothing similar exist for os.Args. But sometimes it is necessary to do so to be able to test CLI parsing (especially in tools which expect to read from os.Args. Current option to do the change to os.Args yourself and then restore it has a downside that it does not check if t.Parallel has been called.

I understand that global state is tricky, but making a function which checks for parallel execution could help here.

No activity

Activity on this issue will appear here.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions