From 5c6d3e7309900a7e7a784cc9bce960d4fb7f79b2 Mon Sep 17 00:00:00 2001 From: Beth Brown Date: Sat, 15 Jan 2022 05:43:21 +0000 Subject: _content/doc/tutorial: fix fuzz.md final steps main.go modified to import unicode/utf8 and errors packages, discard returned error. Steps added to import packages and make changes in final steps. Fixes golang/go#50628 Change-Id: I5dd5fb66256d56eb81bdbb16ba2d5a3fc1ee5dd4 Reviewed-on: https://go-review.googlesource.com/c/website/+/378477 Trust: Julie Qiu Trust: DO NOT USE Reviewed-by: Julie Qiu Reviewed-by: DO NOT USE --- _content/doc/tutorial/fuzz.md | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to '_content/doc/tutorial') diff --git a/_content/doc/tutorial/fuzz.md b/_content/doc/tutorial/fuzz.md index 40575f90..0f96ce52 100644 --- a/_content/doc/tutorial/fuzz.md +++ b/_content/doc/tutorial/fuzz.md @@ -611,7 +611,32 @@ UTF-8. } ``` -2. Modify the reverse_test.go file to check for errors and skip the test if +1. Since the Reverse function now returns an error, modify the `main` function to + discard the extra error value. Replace the existing `main` function with the + following. + + ``` + func main() { + input := "The quick brown fox jumped over the lazy dog" + rev, _ := Reverse(input) + doubleRev, _ := Reverse(rev) + fmt.Printf("original: %q\n", input) + fmt.Printf("reversed: %q\n", rev) + fmt.Printf("reversed again: %q\n", doubleRev) + } + ``` +1. Don't forget to import the new errors package. The first lines of main.go + should look like the following. + + ``` + import ( + "fmt" + "errors" + "unicode/utf8" + ) + ``` + +1. Modify the reverse_test.go file to check for errors and skip the test if errors are generated by returning. ``` @@ -725,12 +750,16 @@ further reading. ``` package main -import "fmt" +import ( + "fmt" + "errors" + "unicode/utf8" +) func main() { input := "The quick brown fox jumped over the lazy dog" - rev := Reverse(input) - doubleRev := Reverse(rev) + rev, _ := Reverse(input) + doubleRev, _ := Reverse(rev) fmt.Printf("original: %q\n", input) fmt.Printf("reversed: %q\n", rev) fmt.Printf("reversed again: %q\n", doubleRev) -- cgit v1.3