Browse Source

Change the rc to report always the relative package

And add test cases for double wrapping of a disallowed function
content-update
Augusto 4 years ago committed by xpetit
parent
commit
81d69fdbbd
  1. 8
      go/tests/rc/rc.go
  2. 31
      go/tests/rc/rc_test.go

8
go/tests/rc/rc.go

@ -282,7 +282,7 @@ func loadProgram(path string, load loadedSource) error {
for _, v := range l.relImports {
if load[v.name] == nil {
newPath, _ := filepath.Abs(path + "/" + v.name)
newPath := filepath.Clean(path + "/" + v.name)
err = loadProgram(newPath, load)
if err != nil {
return err
@ -454,11 +454,7 @@ func isAllowed(function *element, path string, load loadedSource, walked map[ast
continue
}
newPath, err := filepath.Abs(path + "/" + importRelPath.name)
if err != nil {
panic(err)
}
newPath := filepath.Clean(path + "/" + importRelPath.name)
newEl := newElement(fun.name)
allowedSel := isAllowed(newEl, newPath, load, walked, info)
if !allowedSel {

31
go/tests/rc/rc_test.go

@ -2,7 +2,6 @@ package main
import (
"fmt"
"runtime"
"strings"
"testing"
@ -106,16 +105,31 @@ Cheating:
Ok
Cheating:
Ok
`,
`test/testingWrapping.go`: `Parsing:
Ok
Cheating:
TYPE: NAME: LOCATION:
illegal-call len tests/utilDepth2/wrapper.go:4:9
illegal-definition LenWrapper tests/utilDepth2/wrapper.go:3:1
illegal-access util2.LenWrapper tests/util/util.go:10:9
illegal-definition LenWrapperU tests/util/util.go:9:1
illegal-access util.LenWrapperU tests/testingWrapping.go:8:9
illegal-definition Length tests/testingWrapping.go:7:1
`,
`test/testingWrapping.go len`: `Parsing:
Ok
Cheating:
Ok
`,
}
_, filename, _, _ := runtime.Caller(1)
fmt.Println("Filename:", filename)
Compare(t, argsAndSolution)
}
func Compare(t *testing.T, argsAndSol map[string]string) {
for args, sol := range argsAndSol {
out, err := z01.MainOut("../rc", strings.Split(args, " ")...)
a := strings.Split(args, " ")
out, err := z01.MainOut("../rc", a...)
if EqualResult(out, sol) && err != nil && EqualResult(err.Error(), sol) {
fmt.Println(args, "\nError:", err)
fmt.Println("Solution:", sol)
@ -133,3 +147,12 @@ func EqualResult(out, sol string) bool {
}
return false
}
func ExtractFile(args []string) string {
for _, v := range args {
if strings.HasSuffix(v, ".go") {
return v
}
}
return ""
}

Loading…
Cancel
Save