Go Test Command parameter issues

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

Go Test Command parameter issues

When using go test to unit test the Go code, encountered the issue of command parameters, Google, did not find a good explanation, in fact, is a few details.

The problem is that I want to enter some command-line arguments to run the program when I do the unit test.
Refer to the Go official documentation, just add-args and parameters to go test
For example

Go Test-args-classpath E:\testcase HelloWorld

That's the top.

-classpath E:\testcase HelloWorld

Is the parameter I entered, but this error:

Flag provided but not Defined:-classpath

It means that go test interprets-classpath as its own argument, rather than taking all the strings behind-args as a parameter of my program input.

There is no way, I had to in the program bar-classpath changed to Classpath, so the command line as follows

Go Test-args classpath E:\testcase HelloWorld

This barely solves the problem, but the reason for go test changed my source program.

In addition, when I want to print debug information, that is, to go test to increase the-V parameter, also encountered a small problem, I entered the

Go test-v-args classpath E:\testcase HelloWorld

In the source code this, I pass the os. Args goes to get command-line arguments, but-V is treated as an input to my command line, not ignored. In principle, it should be-args to be treated as a command-line argument, and the go test does not actually do this. So I can only modify the source program to complete the test.

In the go test process, the use of command line parameters is relatively small, but I have encountered, and there are some unexpected problems, the go test is not perfect. In addition, I was just beginning to touch the go language, perhaps there is a better way or understand the wrong, here just to make a note for yourself, please forgive me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.