Last active
December 21, 2015 04:29
-
-
Save atotto/6250125 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
fmt.Println("hello") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"testing" | |
) | |
func TestMain(t *testing.T) { | |
main() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright (C) 2013 Ato ARAKI. All rights reserved | |
package main_test | |
import ( | |
"io" | |
"log" | |
"os" | |
"os/exec" | |
"testing" | |
) | |
// Test for invoke process. | |
func TestRun(t *testing.T) { | |
err := doCompile(".") | |
if err != nil { | |
log.Fatal(err) | |
} | |
cmd := exec.Command("./main") | |
stdout, err := cmd.StdoutPipe() | |
if err != nil { | |
log.Fatal(err) | |
} | |
stderr, err := cmd.StderrPipe() | |
if err != nil { | |
log.Fatal(err) | |
} | |
if err := cmd.Start(); err != nil { | |
log.Fatal(err) | |
} | |
go io.Copy(os.Stdout, stdout) | |
go io.Copy(os.Stdout, stderr) | |
if err := cmd.Wait(); err != nil { | |
t.Fatal(err) | |
} | |
} | |
func doCompile(target string) error { | |
cmd := exec.Command("go", "build", target) | |
stdout, err := cmd.StdoutPipe() | |
if err != nil { | |
return err | |
} | |
stderr, err := cmd.StderrPipe() | |
if err != nil { | |
return err | |
} | |
if err := cmd.Start(); err != nil { | |
return err | |
} | |
go io.Copy(os.Stdout, stdout) | |
go io.Copy(os.Stdout, stderr) | |
if err := cmd.Wait(); err != nil { | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment