Repository: Konstantin8105/c4go
Pull request #392 (2019-04-05 12:33:19)

example: add test: go run 

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/392?src=pr&el=h1) Report
> Merging [#392](https://codecov.io/gh/Konstantin8105/c4go/pull/392?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/baf2cca815cfccd180953b0bad90c34bdc179da7?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/392/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/392?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master     #392   +/-   ##
=======================================
  Coverage   85.51%   85.51%           
=======================================
  Files         188      188           
  Lines       11037    11037           
=======================================
  Hits         9438     9438           
  Misses       1140     1140           
  Partials      459      459
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/392?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [preprocessor/preprocessor.go](https://codecov.io/gh/Konstantin8105/c4go/pull/392/diff?src=pr&el=tree#diff-cHJlcHJvY2Vzc29yL3ByZXByb2Nlc3Nvci5nbw==) | `83.48% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/392?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/392?src=pr&el=footer). Last update [baf2cca...f778f5f](https://codecov.io/gh/Konstantin8105/c4go/pull/392?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index 261fd63..5931522 100644
--- a/README.md
+++ b/README.md
@@ -151,6 +151,7 @@ int main()
 
 package main
 
+// #include </usr/include/math.h>
 import "C"
 
 import "github.com/Konstantin8105/c4go/noarch"
@@ -221,16 +222,6 @@ int main()
     a(i5);
     b(i5, 1);
 
-    // pointer arithmetic
-    int* i6 = i5 + 1;
-    a(i6);
-    b(i6, 1);
-
-    // pointer arithmetic
-    int* i7 = 1 + 0 + i5 + 0;
-    a(i7);
-    b(i7, 1);
-
     return 0;
 }
 ```
@@ -286,14 +277,7 @@ func main() {
 	// C-pointer from array
 	a(i5)
 	b(i5, 1)
-	var i6 []int32 = i5[0+1:]
-	// pointer arithmetic
-	a(i6)
-	b(i6, 1)
-	var i7 []int32 = i5[1+0+0+0:]
-	// pointer arithmetic
-	a(i7)
-	b(i7, 1)
+
 	return
 }
 
diff --git a/examples/ap.c b/examples/ap.c
index 7adfe70..bc6630f 100644
--- a/examples/ap.c
+++ b/examples/ap.c
@@ -38,15 +38,5 @@ int main()
     a(i5);
     b(i5, 1);
 
-    // pointer arithmetic
-    int* i6 = i5 + 1;
-    a(i6);
-    b(i6, 1);
-
-    // pointer arithmetic
-    int* i7 = 1 + 0 + i5 + 0;
-    a(i7);
-    b(i7, 1);
-
     return 0;
 }
diff --git a/preprocessor/preprocessor.go b/preprocessor/preprocessor.go
index b15116e..197baf4 100644
--- a/preprocessor/preprocessor.go
+++ b/preprocessor/preprocessor.go
@@ -257,7 +257,7 @@ func NewFilePP(inputFiles, clangFlags []string, cppCode bool) (
 			// find level of line
 			level, _ := separator(ier[pos])
 
-			for j := pos; j > 0; j-- {
+			for j := pos; j >= 0; j-- {
 				levelJ, nameJ := separator(ier[j])
 				if levelJ >= level {
 					continue
diff --git a/transpiler/call.go b/transpiler/call.go
index ec2c153..58bdcba 100644
--- a/transpiler/call.go
+++ b/transpiler/call.go
@@ -208,7 +208,7 @@ func transpileCallExpr(n *ast.CallExpr, p *program.Program) (
 			err = fmt.Errorf("Error in transpileCallExpr : %v", err)
 		}
 		if resultType == "" {
-			p.AddMessage(p.GenerateWarningMessage(fmt.Errorf("exprType is empty"), n))
+			resultType = n.Type
 		}
 	}()
 


Test patch:
diff --git a/main_test.go b/main_test.go
index 9a09b87..9336471 100644
--- a/main_test.go
+++ b/main_test.go
@@ -863,6 +863,20 @@ func TestExamples(t *testing.T) {
 					t.Fatal(err)
 				}
 			}
+
+			t.Run("run", func(t *testing.T) {
+				cmd := exec.Command("go", "run", args.outputFile)
+				cmdOutput := &bytes.Buffer{}
+				cmdErr := &bytes.Buffer{}
+				cmd.Stdout = cmdOutput
+				cmd.Stdin = bytes.NewBuffer([]byte("47"))
+				cmd.Stderr = cmdErr
+				err = cmd.Run()
+				if err != nil {
+					t.Fatalf("Go build test `%v` : err = %v\n%v",
+						args.outputFile, err, cmdErr.String())
+				}
+			})
 		})
 	}
 }
diff --git a/other_test.go b/other_test.go
index 28df43d..749e326 100644
--- a/other_test.go
+++ b/other_test.go
@@ -745,3 +745,82 @@ func TestTinn(t *testing.T) {
 
 	// TODO : add result compare
 }
+
+func TestSpringerproblem(t *testing.T) {
+
+	prefix := "Springerproblem"
+	gitSource := "https://github.com/carstenhag/springerproblem.git"
+
+	fileList, err := getFileList(prefix, gitSource)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	goFile := fileList[0] + ".go"
+	args := DefaultProgramArgs()
+	args.inputFiles = fileList
+	args.outputFile = goFile
+	args.ast = false
+	args.verbose = false
+
+	if err := Start(args); err != nil {
+		t.Fatalf("Cannot transpile `%v`: %v", args, err)
+	}
+
+	// warning is not acceptable
+	dat, err := ioutil.ReadFile(goFile)
+	if err != nil {
+		t.Fatal(err)
+	}
+
+	if bytes.Contains(dat, []byte(program.WarningMessage)) {
+		t.Fatalf("find warning message")
+	}
+
+	// calculate amount unsafe operations
+	unsafeLimit := 1
+	uintptrLimit := 0
+	if count := bytes.Count(dat, []byte("unsafe.Pointer")); count > unsafeLimit {
+		t.Fatalf("too much unsafe operations: %d", count)
+	} else {
+		t.Logf("amount unsafe operations: %d", count)
+	}
+	if count := bytes.Count(dat, []byte("uintptr")); count > uintptrLimit {
+		t.Fatalf("too much uintptr operations: %d", count)
+	} else {
+		t.Logf("amount uintptr operations: %d", count)
+	}
+
+	cmd := exec.Command("go", "build",
+		"-o", goFile+".app",
+		"-gcflags", "-e",
+		goFile)
+	cmdOutput := &bytes.Buffer{}
+	cmdErr := &bytes.Buffer{}
+	cmd.Stdout = cmdOutput
+	cmd.Stderr = cmdErr
+	err = cmd.Run()
+	if err != nil {
+		t.Fatalf("Go build test `%v` : err = %v\n%v",
+			goFile, err, cmdErr.String())
+	}
+
+	index := strings.LastIndex(fileList[0], "/")
+	filepath := fileList[0][:index+1]
+	os.Chdir(filepath)
+
+	cmd = exec.Command("./main.c.go.app")
+	cmdOutput = &bytes.Buffer{}
+	cmdErr = &bytes.Buffer{}
+	cmd.Stdout = cmdOutput
+	cmd.Stdin = bytes.NewBuffer([]byte("1\n12\n12\n\n\n\n"))
+	cmd.Stderr = cmdErr
+	err = cmd.Run()
+	if err != nil {
+		t.Fatalf("Go run `%v` : err = %v\n%v\n%v",
+			goFile, err, cmdOutput.String(), cmdErr.String())
+	}
+	t.Logf("%s", cmdOutput.String())
+
+	// TODO : add result compare
+}
diff --git a/scripts/test.sh b/scripts/test.sh
index e83c7a8..1d6d2f8 100755
--- a/scripts/test.sh
+++ b/scripts/test.sh
@@ -37,21 +37,3 @@ echo "End of coverage"
 
 # check race
 go test -tags=integration -run=TestIntegrationScripts/tests/ctype.c -race -v
-
-# These steps are from the README to verify it can be installed and run as
-# documented.
-go build
-
-export C4GO_DIR=$GOPATH/src/github.com/Konstantin8105/c4go
-export C4GO=$C4GO_DIR/c4go
-
-echo "Run: c4go transpile prime.c"
-$C4GO transpile -o=./testdata/prime.go $C4GO_DIR/examples/prime.c
-echo "47" | go run ./testdata/prime.go
-if [ $(cat ./testdata/prime.go | wc -l) -eq 0 ]; then exit 1; fi
-if [ $($C4GO ast $C4GO_DIR/examples/prime.c | wc -l) -eq 0 ]; then exit 1; fi
-
-echo "----------------------"
-
-# Run script sqlite
-source ./scripts/sqlite.sh