Skip to content

Commit

Permalink
Move some files into examples/
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotchance committed May 30, 2017
1 parent 02c5b1a commit 3a1d5d1
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdio.h>
Expand Down
File renamed without changes.
File renamed without changes.
25 changes: 17 additions & 8 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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])
}
})
}
}
5 changes: 5 additions & 0 deletions tests/exit_status.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#include <stdio.h>
#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;
}
1 change: 1 addition & 0 deletions tests/for.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h>
#include "tests.h"

int main()
{
Expand Down

0 comments on commit 3a1d5d1

Please sign in to comment.