From 09b1f4c514b14a834f763a64d9087f674657052c Mon Sep 17 00:00:00 2001 From: Augusto Date: Wed, 7 Oct 2020 11:07:08 +0100 Subject: [PATCH] Avoids that the rc crashes when encountering more than one package in the same directory --- go/tests/rc/rc.go | 16 ++++++++++++++++ .../rc/tests/grand-prix-go-burdeux/isnegative.go | 11 +++++++++++ go/tests/rc/tests/moreThanOnePackage/func.go | 5 +++++ go/tests/rc/tests/moreThanOnePackage/main.go | 7 +++++++ go/tests/rc/tests/testLiteralRestriction/main.go | 10 ++++++++++ 5 files changed, 49 insertions(+) create mode 100644 go/tests/rc/tests/grand-prix-go-burdeux/isnegative.go create mode 100644 go/tests/rc/tests/moreThanOnePackage/func.go create mode 100644 go/tests/rc/tests/moreThanOnePackage/main.go create mode 100644 go/tests/rc/tests/testLiteralRestriction/main.go diff --git a/go/tests/rc/rc.go b/go/tests/rc/rc.go index caf6ae7f0..6816796f7 100644 --- a/go/tests/rc/rc.go +++ b/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 diff --git a/go/tests/rc/tests/grand-prix-go-burdeux/isnegative.go b/go/tests/rc/tests/grand-prix-go-burdeux/isnegative.go new file mode 100644 index 000000000..52795b220 --- /dev/null +++ b/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') + } +} diff --git a/go/tests/rc/tests/moreThanOnePackage/func.go b/go/tests/rc/tests/moreThanOnePackage/func.go new file mode 100644 index 000000000..e7a82f917 --- /dev/null +++ b/go/tests/rc/tests/moreThanOnePackage/func.go @@ -0,0 +1,5 @@ +package piscine + +func hello() { + println("Nothing here") +} diff --git a/go/tests/rc/tests/moreThanOnePackage/main.go b/go/tests/rc/tests/moreThanOnePackage/main.go new file mode 100644 index 000000000..d2c4e91ea --- /dev/null +++ b/go/tests/rc/tests/moreThanOnePackage/main.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello world") +} diff --git a/go/tests/rc/tests/testLiteralRestriction/main.go b/go/tests/rc/tests/testLiteralRestriction/main.go new file mode 100644 index 000000000..64a8606e8 --- /dev/null +++ b/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) + } +}