-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from elliotchance/master
Update
- Loading branch information
Showing
7 changed files
with
110 additions
and
111 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2017 Elliot Chance | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,87 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"io/ioutil" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
// This test exists for code coverage and does not actually test anything. The | ||
// real tests are performed with run-tests.h. | ||
// | ||
// In the future it would be nice to combine them so that the files only have to | ||
// be compiled once and we don't need the extra bash script. | ||
var ( | ||
cPath = "build/a.out" | ||
goPath = "build/go.out" | ||
stdin = "7" | ||
args = []string{"some", "args"} | ||
) | ||
|
||
type programOut struct { | ||
stdout bytes.Buffer | ||
stderr bytes.Buffer | ||
isZero bool | ||
} | ||
|
||
// TestIntegrationScripts tests all programs in the tests directory | ||
func TestIntegrationScripts(t *testing.T) { | ||
files, err := filepath.Glob("tests/*/*.c") | ||
if err != nil { | ||
panic(err) | ||
t.Fatal(err) | ||
} | ||
|
||
for _, file := range files { | ||
Start([]string{file}) | ||
// Create build folder | ||
os.Mkdir("build/", os.ModePerm) | ||
|
||
t.Run(file, func(t *testing.T) { | ||
cProgram := programOut{} | ||
goProgram := programOut{} | ||
|
||
// Compile C | ||
err := exec.Command("clang", "-lm", "-o", cPath, file).Run() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Run C program | ||
cmd := exec.Command(cPath, args...) | ||
cmd.Stdin = strings.NewReader(stdin) | ||
cmd.Stdout = &cProgram.stdout | ||
cmd.Stderr = &cProgram.stderr | ||
err = cmd.Run() | ||
cProgram.isZero = err == nil | ||
|
||
// Compile Go | ||
goSrc := Start([]string{file}) | ||
ioutil.WriteFile("build/main.go", []byte(goSrc), os.ModePerm) | ||
err = exec.Command("go", "build", "-o", goPath, "build/main.go").Run() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Run Go program | ||
cmd = exec.Command(goPath, args...) | ||
cmd.Stdin = strings.NewReader(stdin) | ||
cmd.Stdout = &goProgram.stdout | ||
cmd.Stderr = &goProgram.stderr | ||
err = cmd.Run() | ||
goProgram.isZero = err == nil | ||
|
||
// Check if both exit codes are zero (or non-zero) | ||
if cProgram.isZero != goProgram.isZero { | ||
t.Fatalf("Expected: %t, Got: %t", cProgram.isZero, goProgram.isZero) | ||
} | ||
|
||
// Check stderr | ||
if cProgram.stderr.String() != goProgram.stderr.String() { | ||
t.Fatalf("Expected %q, Got: %q", cProgram.stderr.String(), goProgram.stderr.String()) | ||
} | ||
|
||
// Check stdout | ||
if cProgram.stdout.String() != goProgram.stdout.String() { | ||
t.Fatalf("Expected %q, Got: %q", cProgram.stdout.String(), goProgram.stdout.String()) | ||
} | ||
}) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.