diff --git a/.travis.yml b/.travis.yml index 2fd401098..22e259fc8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -52,11 +52,11 @@ script: # documented. - cd /tmp - export C2GO=$GOPATH/src/github.com/elliotchance/c2go - - c2go transpile $C2GO/tests/prime.c + - c2go transpile $C2GO/examples/prime.c - echo "47" | go run prime.go - if [ $(c2go -v | wc -l) -ne 1 ]; then exit 1; fi - if [ $(cat prime.go | wc -l) -eq 0 ]; then exit 1; fi - - if [ $(c2go ast $C2GO/tests/prime.c | wc -l) -eq 0 ]; then exit 1; fi + - if [ $(c2go ast $C2GO/examples/prime.c | wc -l) -eq 0 ]; then exit 1; fi # Revert the cwd for any cleanup commands. - cd - diff --git a/README.md b/README.md index 8ca709d77..d2d03c0de 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ c2go transpile myfile.c The `c2go` program processes a single C file and outputs the translated code in Go. Let's use an included example, -[prime.c](https://github.com/elliotchance/c2go/blob/master/tests/math/prime.c): +[prime.c](https://github.com/elliotchance/c2go/blob/master/examples/prime.c): ```c #include diff --git a/tests/fib.c b/examples/fib.c similarity index 100% rename from tests/fib.c rename to examples/fib.c diff --git a/tests/prime.c b/examples/prime.c similarity index 100% rename from tests/prime.c rename to examples/prime.c diff --git a/main_test.go b/main_test.go index 7fa8382be..090f98f77 100644 --- a/main_test.go +++ b/main_test.go @@ -43,11 +43,18 @@ type programOut struct { // go test -tags=integration -run=TestIntegrationScripts/tests/ctype/isalnum.c // func TestIntegrationScripts(t *testing.T) { - files, err := filepath.Glob("tests/*.c") + testFiles, err := filepath.Glob("tests/*.c") if err != nil { t.Fatal(err) } + exampleFiles, err := filepath.Glob("examples/*.c") + if err != nil { + t.Fatal(err) + } + + files := append(testFiles, exampleFiles...) + for _, file := range files { // Create build folder os.Mkdir("build/", os.ModePerm) @@ -116,15 +123,17 @@ func TestIntegrationScripts(t *testing.T) { t.Fatalf(util.ShowDiff(cProgram.stdout.String(), goProgram.stdout.String())) } - // Extact the number of tests run. - firstLine := strings.Split(goProgram.stdout.String(), "\n")[0] + // If this is not an example we will extact the number of tests run. + if strings.Index(file, "examples/") == -1 { + firstLine := strings.Split(goProgram.stdout.String(), "\n")[0] - matches := regexp.MustCompile(`1..(\d+)`).FindStringSubmatch(firstLine) - if len(matches) == 0 { - t.Fatalf("Test did not output tap: %s", file) - } + matches := regexp.MustCompile(`1..(\d+)`).FindStringSubmatch(firstLine) + if len(matches) == 0 { + t.Fatalf("Test did not output tap: %s", file) + } - fmt.Println(file + " TAP TESTS: " + matches[1]) + fmt.Println(file + " TAP TESTS: " + matches[1]) + } }) } } diff --git a/tests/exit_status.c b/tests/exit_status.c index 3e4d2ccd9..73ec9013a 100644 --- a/tests/exit_status.c +++ b/tests/exit_status.c @@ -1,5 +1,10 @@ #include +#include "tests.h" int main() { + plan(0); + + // There is no done_testing() becuase we want to return an error code without + // checks that fail. return 1; } diff --git a/tests/for.c b/tests/for.c index d3a9d1bbf..3177d139d 100644 --- a/tests/for.c +++ b/tests/for.c @@ -1,4 +1,5 @@ #include +#include "tests.h" int main() {