Browse Source

Fix test files and subject

pull/533/head
5 years ago committed by xpetit
parent
commit
9d14f25e00
  1. 17
      go/tests/displayfile_test/displayfile_correct/main.go
  2. 12
      go/tests/displayfile_test/main.go
  3. 9
      subjects/displayfile.en.md

17
go/tests/displayfile_test/displayfile_correct/main.go

@ -9,16 +9,13 @@ import (
func main() {
if len(os.Args) < 2 {
fmt.Println("File name missing")
return
}
if len(os.Args) > 2 {
} else if len(os.Args) > 2 {
fmt.Println("Too many arguments")
return
}
fileName := os.Args[1]
data, err := ioutil.ReadFile(fileName)
if err != nil {
panic(err)
} else {
b, err := ioutil.ReadFile(os.Args[1])
if err != nil {
panic(err)
}
os.Stdout.Write(b)
}
os.Stdout.Write(data)
}

12
go/tests/displayfile_test/main.go

@ -1,19 +1,19 @@
package main
import (
"io/ioutil"
"os"
"strings"
"github.com/01-edu/public/go/lib"
"lib"
)
func main() {
pathFileName := "./student/displayfile/quest8.txt"
_, err := os.Stat(pathFileName)
if err != nil {
lib.Fatal(err)
fileName := "quest8.txt"
if err := ioutil.WriteFile(fileName, []byte("Almost there!!\n"), os.ModePerm); err != nil {
panic(err)
}
table := []string{"", pathFileName, "quest8.txt asdsada"}
table := []string{"", fileName, fileName + " asdsada"}
for _, s := range table {
lib.ChallengeMain("displayfile", strings.Fields(s)...)
}

9
subjects/displayfile.en.md

@ -4,20 +4,13 @@
Write a program that displays, on the standard output, the content of a file given as argument.
- Create a file `quest8.txt` and write into it the sentence `Almost there!!`
- The argument of the program in this case should be, `quest8.txt`.
- In case of error the program should print one the below messages accordingly:
- `File name missing`.
- `Too many arguments`.
### Usage :
```console
student@ubuntu:~/[[ROOT]]/displayfile$ go build
student@ubuntu:~/[[ROOT]]/displayfile$ ./displayfile
File name missing
student@ubuntu:~/[[ROOT]]/displayfile$ echo "Almost there!!" > quest8.txt
student@ubuntu:~/[[ROOT]]/displayfile$ ./displayfile quest8.txt main.go
Too many arguments
student@ubuntu:~/[[ROOT]]/displayfile$ ./displayfile quest8.txt

Loading…
Cancel
Save