Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Test command
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Archos  
View profile  
 More options Jul 30 2012, 8:45 am
From: Archos <raul....@sent.com>
Date: Mon, 30 Jul 2012 05:45:26 -0700 (PDT)
Local: Mon, Jul 30 2012 8:45 am
Subject: Test command

I wanted to testing the output of a command and I just check that Go does
very easy. I know that could testing functions of a command but not the
"full command" through main().

This is really cool. To pass it the argument that you would use in the
command line, insert them in os.Args, and then you already run main()

func init() {
    os.Args = []string{"def2go", "-s", "linux", "-p", "foo",
"testdata/ioctls.h"}

}

func Test(t *testing.T) {
    main()

}

And it runs like if were done from command line. The only problem is that
it can not be used the example functions to checking whether the ouput is
like I was expecting.

Is there any technical issue for that the example functions can not be run
in commands?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Mylund Nielsen  
View profile  
 More options Jul 30 2012, 8:52 am
From: Patrick Mylund Nielsen <patr...@patrickmylund.com>
Date: Mon, 30 Jul 2012 05:52:13 -0700
Local: Mon, Jul 30 2012 8:52 am
Subject: Re: [go-nuts] Test command

Since you're not using testing.T, why not just run the command?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Archos  
View profile  
 More options Jul 30 2012, 8:58 am
From: Archos <raul....@sent.com>
Date: Mon, 30 Jul 2012 05:58:34 -0700 (PDT)
Local: Mon, Jul 30 2012 8:58 am
Subject: Re: [go-nuts] Test command

Because I would want to check that the output of that command is like I'm
expecting which could be done from exampla functions.

El lunes, 30 de julio de 2012 13:52:13 UTC+1, Patrick Mylund Nielsen
escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aram Hăvărneanu  
View profile  
 More options Jul 30 2012, 9:00 am
From: Aram Hăvărneanu <ara...@mgk.ro>
Date: Mon, 30 Jul 2012 16:00:46 +0300
Local: Mon, Jul 30 2012 9:00 am
Subject: Re: [go-nuts] Test command
Use a <cmd>_test package instead of a test package to test the command
out of process.

--
Aram Hăvărneanu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Patrick Mylund Nielsen  
View profile  
 More options Jul 30 2012, 9:03 am
From: Patrick Mylund Nielsen <patr...@patrickmylund.com>
Date: Mon, 30 Jul 2012 06:03:40 -0700
Local: Mon, Jul 30 2012 9:03 am
Subject: Re: [go-nuts] Test command

If you really need to do this, run it with os/exec, store the return value,
and write the appropriate message with t.Errorf().

path, err := exec.LookPath("fortune")
if err != nil {
    log.Fatal("installing fortune is in your future")

}

fmt.Printf("fortune is available at %s\n", path)

Can't you just have main() launch a function with whatever parameters in
your program, and have your test launch the same functions with different
parameters?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Archos  
View profile  
 More options Jul 30 2012, 9:15 am
From: Archos <raul....@sent.com>
Date: Mon, 30 Jul 2012 06:15:23 -0700 (PDT)
Local: Mon, Jul 30 2012 9:15 am
Subject: Re: [go-nuts] Test command

But it does not compare the output whith another one, and the example
functions does easy to see what it is expected.

El lunes, 30 de julio de 2012 14:03:40 UTC+1, Patrick Mylund Nielsen
escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Archos  
View profile  
 More options Jul 30 2012, 9:18 am
From: Archos <raul....@sent.com>
Date: Mon, 30 Jul 2012 06:18:13 -0700 (PDT)
Local: Mon, Jul 30 2012 9:18 am
Subject: Re: [go-nuts] Test command

I already the test file in <cmd>_test.go

package main

import (
    "testing"
)
...

El lunes, 30 de julio de 2012 14:00:46 UTC+1, Aram Hăvărneanu escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Aram Hăvărneanu  
View profile  
 More options Jul 30 2012, 9:43 am
From: Aram Hăvărneanu <ara...@mgk.ro>
Date: Mon, 30 Jul 2012 16:43:49 +0300
Local: Mon, Jul 30 2012 9:43 am
Subject: Re: [go-nuts] Test command

> I already the test file in <cmd>_test.go

No, what I meant is that you should use a <cmd>_test package that uses
os/exec in the Example[A-Z] functions to run your command and validate
the output against the sample output.

--
Aram Hăvărneanu


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Archos  
View profile  
 More options Jul 30 2012, 10:00 am
From: Archos <raul....@sent.com>
Date: Mon, 30 Jul 2012 07:00:03 -0700 (PDT)
Local: Mon, Jul 30 2012 10:00 am
Subject: Re: [go-nuts] Test command

It looks that it's the better alternative

// TODO: use exec.LookPath()
func ExampleHello() {
    out, _ := exec.Command("def2go", "-s", "linux", "-p", "foo",
"testdata/ioctls.h").Output()
    fmt.Print(string(out))
    // Output:
    // whatever...

}

Before, it should be checked if the binary to run is not in the PATH
environment, to build it before of execute command.

El lunes, 30 de julio de 2012 14:43:49 UTC+1, Aram Hăvărneanu escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Archos  
View profile  
 More options Jul 30 2012, 10:57 am
From: Archos <raul....@sent.com>
Date: Mon, 30 Jul 2012 07:57:26 -0700 (PDT)
Local: Mon, Jul 30 2012 10:57 am
Subject: Re: [go-nuts] Test command

For if somebody needs it:

package main

import (
    "fmt"
    "log"
    "os/exec"
)

const EXEC = [BINARY NAME]

var execPath string

func init() {
    var err error
    execPath, err = exec.LookPath(EXEC)
    if err != nil {
        if err.(*exec.Error).Err == exec.ErrNotFound {
            if err2 := exec.Command("go", "build").Run(); err2 != nil {
                log.Fatal(err2)
            }
        } else {
            log.Fatal(err)
        }
    }

}

func Example() {
    out, _ := exec.Command(execPath, [ARGS]).Output()
    fmt.Print(string(out))
    // Output:
    // ...

}

El lunes, 30 de julio de 2012 15:00:03 UTC+1, Archos escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Archos  
View profile  
 More options Jul 31 2012, 8:13 am
From: Archos <raul....@sent.com>
Date: Tue, 31 Jul 2012 05:13:19 -0700 (PDT)
Local: Tues, Jul 31 2012 8:13 am
Subject: Re: Test command

Link to template for testing the output of a command:

https://github.com/kless/wizard/wiki/Tester

El lunes, 30 de julio de 2012 13:45:26 UTC+1, Archos escribió:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »