diff --git a/go/tests/displayfile_test/displayfile_correct/main.go b/go/tests/displayfile_test/displayfile_correct/main.go index 0fd57bca9..d6eccb982 100644 --- a/go/tests/displayfile_test/displayfile_correct/main.go +++ b/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) } diff --git a/go/tests/displayfile_test/main.go b/go/tests/displayfile_test/main.go index 2c7cc156d..837082574 100644 --- a/go/tests/displayfile_test/main.go +++ b/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)...) } diff --git a/subjects/displayfile.en.md b/subjects/displayfile.en.md index 8ea53c935..55bfbe0d1 100644 --- a/subjects/displayfile.en.md +++ b/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