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

main: improve test flag handling #3151

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions config_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
// Copyright (c) 2018 The Decred developers
// Copyright (c) 2018-2023 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.

package main

import (
"flag"
"os"
"path/filepath"
"strings"
"testing"
)

func TestMain(m *testing.M) {
flag.Parse()

// Trim -test.* flags from the command line arguments list to allow
// go-flags tests to succeed.
os.Args = append([]string{os.Args[0]}, flag.Args()...)

os.Exit(m.Run())
}

// In order to test command line arguments and environment variables, append
// the flags to the os.Args variable like so:
// os.Args = append(os.Args, "--altdnsnames=\"hostname1,hostname2\"")
Expand Down Expand Up @@ -80,9 +91,3 @@ func TestAltDNSNamesWithArg(t *testing.T) {
}
os.Args = old
}

// init parses the -test.* flags from the command line arguments list and then
// removes them to allow go-flags tests to succeed.
func init() {
os.Args = os.Args[:1]
}