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()
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?
On Mon, Jul 30, 2012 at 5:45 AM, Archos <raul....@sent.com> wrote:
> 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()
> 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?
> Since you're not using testing.T, why not just run the command?
> On Mon, Jul 30, 2012 at 5:45 AM, Archos <raul....@sent.com> wrote:
>> 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()
>> 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?
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?
On Mon, Jul 30, 2012 at 5:58 AM, Archos <raul....@sent.com> wrote:
> 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ó:
>> Since you're not using testing.T, why not just run the command?
>> On Mon, Jul 30, 2012 at 5:45 AM, Archos <raul....@sent.com> wrote:
>>> 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()
>>> 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?
> 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?
> On Mon, Jul 30, 2012 at 5:58 AM, Archos <raul....@sent.com> wrote:
>> 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ó:
>>> Since you're not using testing.T, why not just run the command?
>>> On Mon, Jul 30, 2012 at 5:45 AM, Archos <raul....@sent.com> wrote:
>>>> 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()
>>>> 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?
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.
> 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.
> 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ó:
>> > 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.
> 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()
> 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?