Browse Source

Avoids that the rc crashes when encountering more than one package

in the same directory
pull/684/head
Augusto 4 years ago committed by xpetit
parent
commit
09b1f4c514
  1. 16
      go/tests/rc/rc.go
  2. 11
      go/tests/rc/tests/grand-prix-go-burdeux/isnegative.go
  3. 5
      go/tests/rc/tests/moreThanOnePackage/func.go
  4. 7
      go/tests/rc/tests/moreThanOnePackage/main.go
  5. 10
      go/tests/rc/tests/testLiteralRestriction/main.go

16
go/tests/rc/rc.go

@ -279,6 +279,14 @@ func loadProgram(path string, load loadedSource) error {
return err
}
if len(pkgs) > 1 {
packages := []string{}
for pkgName := range pkgs {
packages = append(packages, pkgName)
}
return fmt.Errorf("There should be only one package in this directory: Found packages: %v", packages)
}
for _, pkg := range pkgs {
ast.Walk(l, pkg)
l.pkgScope = ast.NewScope(nil)
@ -779,6 +787,14 @@ type loadVisitor struct {
files map[string]*ast.File
}
func (l *loadVisitor) String() (res string) {
res = "files"
for f, _ := range l.files {
res += f + ","
}
return res
}
// Returns all the parameter of a function that identify a function
func functionsInTheParameters(params *ast.FieldList) []string {
var funcs []string

11
go/tests/rc/tests/grand-prix-go-burdeux/isnegative.go

@ -0,0 +1,11 @@
package piscine
import "github.com/01-edu/z01"
func IsNegative(nb int) {
if nb < 0 {
z01.PrintRune('T')
} else {
z01.PrintRune('F')
}
}

5
go/tests/rc/tests/moreThanOnePackage/func.go

@ -0,0 +1,5 @@
package piscine
func hello() {
println("Nothing here")
}

7
go/tests/rc/tests/moreThanOnePackage/main.go

@ -0,0 +1,7 @@
package main
import "fmt"
func main() {
fmt.Println("Hello world")
}

10
go/tests/rc/tests/testLiteralRestriction/main.go

@ -0,0 +1,10 @@
package main
import "github.com/01-edu/z01"
func main() {
alphabet := "abcdefghijklmnopqrstuvwxyz\n"
for _, letter := range alphabet {
z01.PrintRune(letter)
}
}
Loading…
Cancel
Save