diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..b4568988 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,19 @@ +name: Continuous Integration +on: + push: + branches: + - main + pull_request: + +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-go@v5 + with: + go-version: 1.22 + + - name: Run tests + run: go test -v ./... diff --git a/_content/tour/eng/algorithms/fun/freq_concurrent.go b/_content/tour/eng/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/eng/algorithms/fun/freq_concurrent.go +++ b/_content/tour/eng/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/arrays/example2.go b/_content/tour/eng/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/eng/arrays/example2.go +++ b/_content/tour/eng/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/composition/assertions/example1.go b/_content/tour/eng/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/eng/composition/assertions/example1.go +++ b/_content/tour/eng/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/composition/decoupling/exercise1.go b/_content/tour/eng/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/eng/composition/decoupling/exercise1.go +++ b/_content/tour/eng/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/composition/grouping/example1.go b/_content/tour/eng/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/eng/composition/grouping/example1.go +++ b/_content/tour/eng/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/composition/mocking/example1.go b/_content/tour/eng/composition/mocking/example1.go index e72930c1..445b6e18 100644 --- a/_content/tour/eng/composition/mocking/example1.go +++ b/_content/tour/eng/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/constants/example4.go b/_content/tour/eng/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/eng/constants/example4.go +++ b/_content/tour/eng/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/context/exercise1.go b/_content/tour/eng/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/eng/context/exercise1.go +++ b/_content/tour/eng/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/data_race/example5.go b/_content/tour/eng/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/eng/data_race/example5.go +++ b/_content/tour/eng/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/data_race/example6.go b/_content/tour/eng/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/eng/data_race/example6.go +++ b/_content/tour/eng/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/error-handling/example4.go b/_content/tour/eng/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/eng/error-handling/example4.go +++ b/_content/tour/eng/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/error-handling/example5.go b/_content/tour/eng/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/eng/error-handling/example5.go +++ b/_content/tour/eng/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/error-handling/exercise1.go b/_content/tour/eng/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/eng/error-handling/exercise1.go +++ b/_content/tour/eng/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/error-handling/exercise2.go b/_content/tour/eng/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/eng/error-handling/exercise2.go +++ b/_content/tour/eng/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/exporting/answer1.go b/_content/tour/eng/exporting/answer1.go index f0abc4c6..dcd28e17 100644 --- a/_content/tour/eng/exporting/answer1.go +++ b/_content/tour/eng/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/exporting/example1.go b/_content/tour/eng/exporting/example1.go index 5cd1820c..a828b2f6 100644 --- a/_content/tour/eng/exporting/example1.go +++ b/_content/tour/eng/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/exporting/example2.go b/_content/tour/eng/exporting/example2.go index cec2201e..91735097 100644 --- a/_content/tour/eng/exporting/example2.go +++ b/_content/tour/eng/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/exporting/example3.go b/_content/tour/eng/exporting/example3.go index 00a1dda7..1ba82103 100644 --- a/_content/tour/eng/exporting/example3.go +++ b/_content/tour/eng/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/exporting/example4.go b/_content/tour/eng/exporting/example4.go index f2b0174a..93d06902 100644 --- a/_content/tour/eng/exporting/example4.go +++ b/_content/tour/eng/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/exporting/example5.go b/_content/tour/eng/exporting/example5.go index 70da23ed..8ae0fa09 100644 --- a/_content/tour/eng/exporting/example5.go +++ b/_content/tour/eng/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/exporting/exercise1.go b/_content/tour/eng/exporting/exercise1.go index bafbd5a5..4ff23346 100644 --- a/_content/tour/eng/exporting/exercise1.go +++ b/_content/tour/eng/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/generics/type-constraints/exercise1.go b/_content/tour/eng/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/eng/generics/type-constraints/exercise1.go +++ b/_content/tour/eng/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/interfaces/example2.go b/_content/tour/eng/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/eng/interfaces/example2.go +++ b/_content/tour/eng/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/interfaces/example3.go b/_content/tour/eng/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/eng/interfaces/example3.go +++ b/_content/tour/eng/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/interfaces/example4.go b/_content/tour/eng/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/eng/interfaces/example4.go +++ b/_content/tour/eng/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/interfaces/example6.go b/_content/tour/eng/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/eng/interfaces/example6.go +++ b/_content/tour/eng/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/maps/example3.go b/_content/tour/eng/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/eng/maps/example3.go +++ b/_content/tour/eng/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/maps/example6.go b/_content/tour/eng/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/eng/maps/example6.go +++ b/_content/tour/eng/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/methods/example5.go b/_content/tour/eng/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/eng/methods/example5.go +++ b/_content/tour/eng/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/methods/exercise1.go b/_content/tour/eng/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/eng/methods/exercise1.go +++ b/_content/tour/eng/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/slices/example1.go b/_content/tour/eng/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/eng/slices/example1.go +++ b/_content/tour/eng/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/slices/example8.go b/_content/tour/eng/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/eng/slices/example8.go +++ b/_content/tour/eng/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/eng/welcome/sandbox.go b/_content/tour/eng/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/eng/welcome/sandbox.go +++ b/_content/tour/eng/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/fre/algorithms/fun/freq_concurrent.go b/_content/tour/fre/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/fre/algorithms/fun/freq_concurrent.go +++ b/_content/tour/fre/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/arrays/example2.go b/_content/tour/fre/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/fre/arrays/example2.go +++ b/_content/tour/fre/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/composition/assertions/example1.go b/_content/tour/fre/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/fre/composition/assertions/example1.go +++ b/_content/tour/fre/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/composition/decoupling/exercise1.go b/_content/tour/fre/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/fre/composition/decoupling/exercise1.go +++ b/_content/tour/fre/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/composition/grouping/example1.go b/_content/tour/fre/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/fre/composition/grouping/example1.go +++ b/_content/tour/fre/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/composition/mocking/example1.go b/_content/tour/fre/composition/mocking/example1.go index 8be5dd98..da1e04c9 100644 --- a/_content/tour/fre/composition/mocking/example1.go +++ b/_content/tour/fre/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/constants/example4.go b/_content/tour/fre/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/fre/constants/example4.go +++ b/_content/tour/fre/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/content_test.go b/_content/tour/fre/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/fre/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/fre/context/exercise1.go b/_content/tour/fre/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/fre/context/exercise1.go +++ b/_content/tour/fre/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/data_race/example5.go b/_content/tour/fre/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/fre/data_race/example5.go +++ b/_content/tour/fre/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/data_race/example6.go b/_content/tour/fre/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/fre/data_race/example6.go +++ b/_content/tour/fre/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/error-handling/example4.go b/_content/tour/fre/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/fre/error-handling/example4.go +++ b/_content/tour/fre/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/error-handling/example5.go b/_content/tour/fre/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/fre/error-handling/example5.go +++ b/_content/tour/fre/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/error-handling/exercise1.go b/_content/tour/fre/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/fre/error-handling/exercise1.go +++ b/_content/tour/fre/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/error-handling/exercise2.go b/_content/tour/fre/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/fre/error-handling/exercise2.go +++ b/_content/tour/fre/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/exporting/answer1.go b/_content/tour/fre/exporting/answer1.go index 59f33b35..53972b27 100644 --- a/_content/tour/fre/exporting/answer1.go +++ b/_content/tour/fre/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/exporting/example1.go b/_content/tour/fre/exporting/example1.go index 6326f8d1..81756296 100644 --- a/_content/tour/fre/exporting/example1.go +++ b/_content/tour/fre/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/exporting/example2.go b/_content/tour/fre/exporting/example2.go index 5854e07b..4c53a8e0 100644 --- a/_content/tour/fre/exporting/example2.go +++ b/_content/tour/fre/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/exporting/example3.go b/_content/tour/fre/exporting/example3.go index 89e87cb0..7a6728ff 100644 --- a/_content/tour/fre/exporting/example3.go +++ b/_content/tour/fre/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/exporting/example4.go b/_content/tour/fre/exporting/example4.go index dba47fd1..a321f3c5 100644 --- a/_content/tour/fre/exporting/example4.go +++ b/_content/tour/fre/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/exporting/example5.go b/_content/tour/fre/exporting/example5.go index f64ce5bc..5d77a697 100644 --- a/_content/tour/fre/exporting/example5.go +++ b/_content/tour/fre/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/exporting/exercise1.go b/_content/tour/fre/exporting/exercise1.go index e90a1db2..a29ee1ba 100644 --- a/_content/tour/fre/exporting/exercise1.go +++ b/_content/tour/fre/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/generics/type-constraints/exercise1.go b/_content/tour/fre/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/fre/generics/type-constraints/exercise1.go +++ b/_content/tour/fre/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/interfaces/example2.go b/_content/tour/fre/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/fre/interfaces/example2.go +++ b/_content/tour/fre/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/interfaces/example3.go b/_content/tour/fre/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/fre/interfaces/example3.go +++ b/_content/tour/fre/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/interfaces/example4.go b/_content/tour/fre/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/fre/interfaces/example4.go +++ b/_content/tour/fre/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/interfaces/example6.go b/_content/tour/fre/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/fre/interfaces/example6.go +++ b/_content/tour/fre/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/maps/example3.go b/_content/tour/fre/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/fre/maps/example3.go +++ b/_content/tour/fre/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/maps/example6.go b/_content/tour/fre/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/fre/maps/example6.go +++ b/_content/tour/fre/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/methods/example5.go b/_content/tour/fre/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/fre/methods/example5.go +++ b/_content/tour/fre/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/methods/exercise1.go b/_content/tour/fre/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/fre/methods/exercise1.go +++ b/_content/tour/fre/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/slices/example1.go b/_content/tour/fre/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/fre/slices/example1.go +++ b/_content/tour/fre/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/slices/example8.go b/_content/tour/fre/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/fre/slices/example8.go +++ b/_content/tour/fre/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/fre/welcome/sandbox.go b/_content/tour/fre/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/fre/welcome/sandbox.go +++ b/_content/tour/fre/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/ger/algorithms/fun/freq_concurrent.go b/_content/tour/ger/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/ger/algorithms/fun/freq_concurrent.go +++ b/_content/tour/ger/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/arrays/example2.go b/_content/tour/ger/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/ger/arrays/example2.go +++ b/_content/tour/ger/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/composition/assertions/example1.go b/_content/tour/ger/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/ger/composition/assertions/example1.go +++ b/_content/tour/ger/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/composition/decoupling/exercise1.go b/_content/tour/ger/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/ger/composition/decoupling/exercise1.go +++ b/_content/tour/ger/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/composition/grouping/example1.go b/_content/tour/ger/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/ger/composition/grouping/example1.go +++ b/_content/tour/ger/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/composition/mocking/example1.go b/_content/tour/ger/composition/mocking/example1.go index e72930c1..445b6e18 100644 --- a/_content/tour/ger/composition/mocking/example1.go +++ b/_content/tour/ger/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/constants/example4.go b/_content/tour/ger/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/ger/constants/example4.go +++ b/_content/tour/ger/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/content_test.go b/_content/tour/ger/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/ger/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/ger/context/exercise1.go b/_content/tour/ger/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/ger/context/exercise1.go +++ b/_content/tour/ger/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/data_race/example5.go b/_content/tour/ger/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/ger/data_race/example5.go +++ b/_content/tour/ger/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/data_race/example6.go b/_content/tour/ger/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/ger/data_race/example6.go +++ b/_content/tour/ger/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/error-handling/example4.go b/_content/tour/ger/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/ger/error-handling/example4.go +++ b/_content/tour/ger/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/error-handling/example5.go b/_content/tour/ger/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/ger/error-handling/example5.go +++ b/_content/tour/ger/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/error-handling/exercise1.go b/_content/tour/ger/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/ger/error-handling/exercise1.go +++ b/_content/tour/ger/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/error-handling/exercise2.go b/_content/tour/ger/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/ger/error-handling/exercise2.go +++ b/_content/tour/ger/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/exporting/answer1.go b/_content/tour/ger/exporting/answer1.go index f0abc4c6..dcd28e17 100644 --- a/_content/tour/ger/exporting/answer1.go +++ b/_content/tour/ger/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/exporting/example1.go b/_content/tour/ger/exporting/example1.go index 5cd1820c..a828b2f6 100644 --- a/_content/tour/ger/exporting/example1.go +++ b/_content/tour/ger/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/exporting/example2.go b/_content/tour/ger/exporting/example2.go index cec2201e..91735097 100644 --- a/_content/tour/ger/exporting/example2.go +++ b/_content/tour/ger/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/exporting/example3.go b/_content/tour/ger/exporting/example3.go index 00a1dda7..1ba82103 100644 --- a/_content/tour/ger/exporting/example3.go +++ b/_content/tour/ger/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/exporting/example4.go b/_content/tour/ger/exporting/example4.go index f2b0174a..93d06902 100644 --- a/_content/tour/ger/exporting/example4.go +++ b/_content/tour/ger/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/exporting/example5.go b/_content/tour/ger/exporting/example5.go index 70da23ed..8ae0fa09 100644 --- a/_content/tour/ger/exporting/example5.go +++ b/_content/tour/ger/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/exporting/exercise1.go b/_content/tour/ger/exporting/exercise1.go index bafbd5a5..4ff23346 100644 --- a/_content/tour/ger/exporting/exercise1.go +++ b/_content/tour/ger/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/generics/type-constraints/exercise1.go b/_content/tour/ger/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/ger/generics/type-constraints/exercise1.go +++ b/_content/tour/ger/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/interfaces/example2.go b/_content/tour/ger/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/ger/interfaces/example2.go +++ b/_content/tour/ger/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/interfaces/example3.go b/_content/tour/ger/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/ger/interfaces/example3.go +++ b/_content/tour/ger/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/interfaces/example4.go b/_content/tour/ger/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/ger/interfaces/example4.go +++ b/_content/tour/ger/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/interfaces/example6.go b/_content/tour/ger/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/ger/interfaces/example6.go +++ b/_content/tour/ger/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/maps/example3.go b/_content/tour/ger/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/ger/maps/example3.go +++ b/_content/tour/ger/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/maps/example6.go b/_content/tour/ger/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/ger/maps/example6.go +++ b/_content/tour/ger/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/methods/example5.go b/_content/tour/ger/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/ger/methods/example5.go +++ b/_content/tour/ger/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/methods/exercise1.go b/_content/tour/ger/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/ger/methods/exercise1.go +++ b/_content/tour/ger/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/slices/example1.go b/_content/tour/ger/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/ger/slices/example1.go +++ b/_content/tour/ger/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/slices/example8.go b/_content/tour/ger/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/ger/slices/example8.go +++ b/_content/tour/ger/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ger/welcome/sandbox.go b/_content/tour/ger/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/ger/welcome/sandbox.go +++ b/_content/tour/ger/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/grc/algorithms/fun/freq_concurrent.go b/_content/tour/grc/algorithms/fun/freq_concurrent.go index f5485b16..cf3ae2d6 100644 --- a/_content/tour/grc/algorithms/fun/freq_concurrent.go +++ b/_content/tour/grc/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/arrays/example2.go b/_content/tour/grc/arrays/example2.go index 72cbe7c0..2dc61018 100644 --- a/_content/tour/grc/arrays/example2.go +++ b/_content/tour/grc/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/composition/assertions/example1.go b/_content/tour/grc/composition/assertions/example1.go index 89352d56..9272d0ff 100644 --- a/_content/tour/grc/composition/assertions/example1.go +++ b/_content/tour/grc/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/composition/decoupling/exercise1.go b/_content/tour/grc/composition/decoupling/exercise1.go index fc9047c8..e8183cf7 100644 --- a/_content/tour/grc/composition/decoupling/exercise1.go +++ b/_content/tour/grc/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/composition/grouping/example1.go b/_content/tour/grc/composition/grouping/example1.go index e177c37a..32e074c0 100644 --- a/_content/tour/grc/composition/grouping/example1.go +++ b/_content/tour/grc/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/composition/mocking/example1.go b/_content/tour/grc/composition/mocking/example1.go index 88c14dc0..e853be72 100644 --- a/_content/tour/grc/composition/mocking/example1.go +++ b/_content/tour/grc/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/constants/example4.go b/_content/tour/grc/constants/example4.go index a8ba5cf5..aaaa95a6 100644 --- a/_content/tour/grc/constants/example4.go +++ b/_content/tour/grc/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/content_test.go b/_content/tour/grc/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/grc/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/grc/context/exercise1.go b/_content/tour/grc/context/exercise1.go index 0eb0224e..1e3aa217 100644 --- a/_content/tour/grc/context/exercise1.go +++ b/_content/tour/grc/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/data_race/example5.go b/_content/tour/grc/data_race/example5.go index 5e798db0..2a8d5262 100644 --- a/_content/tour/grc/data_race/example5.go +++ b/_content/tour/grc/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/data_race/example6.go b/_content/tour/grc/data_race/example6.go index e0637fbc..04fef46e 100644 --- a/_content/tour/grc/data_race/example6.go +++ b/_content/tour/grc/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/error-handling/example4.go b/_content/tour/grc/error-handling/example4.go index f4794abf..c250edfb 100644 --- a/_content/tour/grc/error-handling/example4.go +++ b/_content/tour/grc/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/error-handling/example5.go b/_content/tour/grc/error-handling/example5.go index 29093907..bc689a17 100644 --- a/_content/tour/grc/error-handling/example5.go +++ b/_content/tour/grc/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/error-handling/exercise1.go b/_content/tour/grc/error-handling/exercise1.go index f5761fdd..be04e80a 100644 --- a/_content/tour/grc/error-handling/exercise1.go +++ b/_content/tour/grc/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/error-handling/exercise2.go b/_content/tour/grc/error-handling/exercise2.go index 7baa8fcf..e83c66fb 100644 --- a/_content/tour/grc/error-handling/exercise2.go +++ b/_content/tour/grc/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/exporting/answer1.go b/_content/tour/grc/exporting/answer1.go index 56c7ae16..316a8a53 100644 --- a/_content/tour/grc/exporting/answer1.go +++ b/_content/tour/grc/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/exporting/example1.go b/_content/tour/grc/exporting/example1.go index 6c4ad813..339a09d6 100644 --- a/_content/tour/grc/exporting/example1.go +++ b/_content/tour/grc/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/exporting/example2.go b/_content/tour/grc/exporting/example2.go index f3b3d389..2252ec08 100644 --- a/_content/tour/grc/exporting/example2.go +++ b/_content/tour/grc/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/exporting/example3.go b/_content/tour/grc/exporting/example3.go index 00909be6..547671f8 100644 --- a/_content/tour/grc/exporting/example3.go +++ b/_content/tour/grc/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/exporting/example4.go b/_content/tour/grc/exporting/example4.go index 80056e7f..bde23749 100644 --- a/_content/tour/grc/exporting/example4.go +++ b/_content/tour/grc/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/exporting/example5.go b/_content/tour/grc/exporting/example5.go index 8f9106bd..a9a8c807 100644 --- a/_content/tour/grc/exporting/example5.go +++ b/_content/tour/grc/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/exporting/exercise1.go b/_content/tour/grc/exporting/exercise1.go index 9c09e491..30419521 100644 --- a/_content/tour/grc/exporting/exercise1.go +++ b/_content/tour/grc/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/generics/type-constraints/exercise1.go b/_content/tour/grc/generics/type-constraints/exercise1.go index 6de6feb4..09dd0377 100644 --- a/_content/tour/grc/generics/type-constraints/exercise1.go +++ b/_content/tour/grc/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/interfaces/example2.go b/_content/tour/grc/interfaces/example2.go index 1f783a3c..48f30343 100644 --- a/_content/tour/grc/interfaces/example2.go +++ b/_content/tour/grc/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/interfaces/example3.go b/_content/tour/grc/interfaces/example3.go index f897bc12..e69879d4 100644 --- a/_content/tour/grc/interfaces/example3.go +++ b/_content/tour/grc/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/interfaces/example4.go b/_content/tour/grc/interfaces/example4.go index 989e46e4..e756d8f5 100644 --- a/_content/tour/grc/interfaces/example4.go +++ b/_content/tour/grc/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/interfaces/example6.go b/_content/tour/grc/interfaces/example6.go index 6fe89c26..f03cd950 100644 --- a/_content/tour/grc/interfaces/example6.go +++ b/_content/tour/grc/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/maps/example3.go b/_content/tour/grc/maps/example3.go index 8978a3c3..8dbf7823 100644 --- a/_content/tour/grc/maps/example3.go +++ b/_content/tour/grc/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/maps/example6.go b/_content/tour/grc/maps/example6.go index a0db0f22..8ecb1c54 100644 --- a/_content/tour/grc/maps/example6.go +++ b/_content/tour/grc/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/methods/example5.go b/_content/tour/grc/methods/example5.go index 337ca16b..758844ae 100644 --- a/_content/tour/grc/methods/example5.go +++ b/_content/tour/grc/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/methods/exercise1.go b/_content/tour/grc/methods/exercise1.go index 988a34ca..d0039ad2 100644 --- a/_content/tour/grc/methods/exercise1.go +++ b/_content/tour/grc/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/slices/example1.go b/_content/tour/grc/slices/example1.go index aadd43f7..f786f6fc 100644 --- a/_content/tour/grc/slices/example1.go +++ b/_content/tour/grc/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/slices/example8.go b/_content/tour/grc/slices/example8.go index b0d1911e..3a61b00a 100644 --- a/_content/tour/grc/slices/example8.go +++ b/_content/tour/grc/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // Όλα τα υλικά είναι αδειοδοτημένα υπό την Άδεια Apache Έκδοση 2.0, Ιανουάριος 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/grc/welcome/sandbox.go b/_content/tour/grc/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/grc/welcome/sandbox.go +++ b/_content/tour/grc/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/ita/algorithms/fun/freq_concurrent.go b/_content/tour/ita/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/ita/algorithms/fun/freq_concurrent.go +++ b/_content/tour/ita/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/arrays/example2.go b/_content/tour/ita/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/ita/arrays/example2.go +++ b/_content/tour/ita/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/composition/assertions/example1.go b/_content/tour/ita/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/ita/composition/assertions/example1.go +++ b/_content/tour/ita/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/composition/decoupling/exercise1.go b/_content/tour/ita/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/ita/composition/decoupling/exercise1.go +++ b/_content/tour/ita/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/composition/grouping/example1.go b/_content/tour/ita/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/ita/composition/grouping/example1.go +++ b/_content/tour/ita/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/composition/mocking/example1.go b/_content/tour/ita/composition/mocking/example1.go index e72930c1..445b6e18 100644 --- a/_content/tour/ita/composition/mocking/example1.go +++ b/_content/tour/ita/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/constants/example4.go b/_content/tour/ita/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/ita/constants/example4.go +++ b/_content/tour/ita/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/content_test.go b/_content/tour/ita/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/ita/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/ita/context/exercise1.go b/_content/tour/ita/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/ita/context/exercise1.go +++ b/_content/tour/ita/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/data_race/example5.go b/_content/tour/ita/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/ita/data_race/example5.go +++ b/_content/tour/ita/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/data_race/example6.go b/_content/tour/ita/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/ita/data_race/example6.go +++ b/_content/tour/ita/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/error-handling/example4.go b/_content/tour/ita/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/ita/error-handling/example4.go +++ b/_content/tour/ita/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/error-handling/example5.go b/_content/tour/ita/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/ita/error-handling/example5.go +++ b/_content/tour/ita/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/error-handling/exercise1.go b/_content/tour/ita/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/ita/error-handling/exercise1.go +++ b/_content/tour/ita/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/error-handling/exercise2.go b/_content/tour/ita/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/ita/error-handling/exercise2.go +++ b/_content/tour/ita/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/exporting/answer1.go b/_content/tour/ita/exporting/answer1.go index f0abc4c6..dcd28e17 100644 --- a/_content/tour/ita/exporting/answer1.go +++ b/_content/tour/ita/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/exporting/example1.go b/_content/tour/ita/exporting/example1.go index 5cd1820c..a828b2f6 100644 --- a/_content/tour/ita/exporting/example1.go +++ b/_content/tour/ita/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/exporting/example2.go b/_content/tour/ita/exporting/example2.go index cec2201e..91735097 100644 --- a/_content/tour/ita/exporting/example2.go +++ b/_content/tour/ita/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/exporting/example3.go b/_content/tour/ita/exporting/example3.go index 00a1dda7..1ba82103 100644 --- a/_content/tour/ita/exporting/example3.go +++ b/_content/tour/ita/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/exporting/example4.go b/_content/tour/ita/exporting/example4.go index f2b0174a..93d06902 100644 --- a/_content/tour/ita/exporting/example4.go +++ b/_content/tour/ita/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/exporting/example5.go b/_content/tour/ita/exporting/example5.go index 70da23ed..8ae0fa09 100644 --- a/_content/tour/ita/exporting/example5.go +++ b/_content/tour/ita/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/exporting/exercise1.go b/_content/tour/ita/exporting/exercise1.go index bafbd5a5..4ff23346 100644 --- a/_content/tour/ita/exporting/exercise1.go +++ b/_content/tour/ita/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/generics/type-constraints/exercise1.go b/_content/tour/ita/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/ita/generics/type-constraints/exercise1.go +++ b/_content/tour/ita/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/interfaces/example2.go b/_content/tour/ita/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/ita/interfaces/example2.go +++ b/_content/tour/ita/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/interfaces/example3.go b/_content/tour/ita/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/ita/interfaces/example3.go +++ b/_content/tour/ita/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/interfaces/example4.go b/_content/tour/ita/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/ita/interfaces/example4.go +++ b/_content/tour/ita/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/interfaces/example6.go b/_content/tour/ita/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/ita/interfaces/example6.go +++ b/_content/tour/ita/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/maps/example3.go b/_content/tour/ita/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/ita/maps/example3.go +++ b/_content/tour/ita/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/maps/example6.go b/_content/tour/ita/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/ita/maps/example6.go +++ b/_content/tour/ita/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/methods/example5.go b/_content/tour/ita/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/ita/methods/example5.go +++ b/_content/tour/ita/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/methods/exercise1.go b/_content/tour/ita/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/ita/methods/exercise1.go +++ b/_content/tour/ita/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/slices/example1.go b/_content/tour/ita/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/ita/slices/example1.go +++ b/_content/tour/ita/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/slices/example8.go b/_content/tour/ita/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/ita/slices/example8.go +++ b/_content/tour/ita/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/ita/welcome/sandbox.go b/_content/tour/ita/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/ita/welcome/sandbox.go +++ b/_content/tour/ita/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/per/algorithms/fun/freq_concurrent.go b/_content/tour/per/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/per/algorithms/fun/freq_concurrent.go +++ b/_content/tour/per/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/arrays/example2.go b/_content/tour/per/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/per/arrays/example2.go +++ b/_content/tour/per/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/composition/assertions/example1.go b/_content/tour/per/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/per/composition/assertions/example1.go +++ b/_content/tour/per/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/composition/decoupling/exercise1.go b/_content/tour/per/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/per/composition/decoupling/exercise1.go +++ b/_content/tour/per/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/composition/grouping/example1.go b/_content/tour/per/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/per/composition/grouping/example1.go +++ b/_content/tour/per/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/composition/mocking/example1.go b/_content/tour/per/composition/mocking/example1.go index e72930c1..445b6e18 100644 --- a/_content/tour/per/composition/mocking/example1.go +++ b/_content/tour/per/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/constants/example4.go b/_content/tour/per/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/per/constants/example4.go +++ b/_content/tour/per/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/content_test.go b/_content/tour/per/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/per/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/per/context/exercise1.go b/_content/tour/per/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/per/context/exercise1.go +++ b/_content/tour/per/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/data_race/example5.go b/_content/tour/per/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/per/data_race/example5.go +++ b/_content/tour/per/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/data_race/example6.go b/_content/tour/per/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/per/data_race/example6.go +++ b/_content/tour/per/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/error-handling/example4.go b/_content/tour/per/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/per/error-handling/example4.go +++ b/_content/tour/per/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/error-handling/example5.go b/_content/tour/per/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/per/error-handling/example5.go +++ b/_content/tour/per/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/error-handling/exercise1.go b/_content/tour/per/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/per/error-handling/exercise1.go +++ b/_content/tour/per/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/error-handling/exercise2.go b/_content/tour/per/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/per/error-handling/exercise2.go +++ b/_content/tour/per/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/exporting/answer1.go b/_content/tour/per/exporting/answer1.go index f0abc4c6..dcd28e17 100644 --- a/_content/tour/per/exporting/answer1.go +++ b/_content/tour/per/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/exporting/example1.go b/_content/tour/per/exporting/example1.go index 5cd1820c..a828b2f6 100644 --- a/_content/tour/per/exporting/example1.go +++ b/_content/tour/per/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/exporting/example2.go b/_content/tour/per/exporting/example2.go index cec2201e..91735097 100644 --- a/_content/tour/per/exporting/example2.go +++ b/_content/tour/per/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/exporting/example3.go b/_content/tour/per/exporting/example3.go index 00a1dda7..1ba82103 100644 --- a/_content/tour/per/exporting/example3.go +++ b/_content/tour/per/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/exporting/example4.go b/_content/tour/per/exporting/example4.go index f2b0174a..93d06902 100644 --- a/_content/tour/per/exporting/example4.go +++ b/_content/tour/per/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/exporting/example5.go b/_content/tour/per/exporting/example5.go index 70da23ed..8ae0fa09 100644 --- a/_content/tour/per/exporting/example5.go +++ b/_content/tour/per/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/exporting/exercise1.go b/_content/tour/per/exporting/exercise1.go index bafbd5a5..4ff23346 100644 --- a/_content/tour/per/exporting/exercise1.go +++ b/_content/tour/per/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/generics/type-constraints/exercise1.go b/_content/tour/per/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/per/generics/type-constraints/exercise1.go +++ b/_content/tour/per/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/interfaces/example2.go b/_content/tour/per/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/per/interfaces/example2.go +++ b/_content/tour/per/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/interfaces/example3.go b/_content/tour/per/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/per/interfaces/example3.go +++ b/_content/tour/per/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/interfaces/example4.go b/_content/tour/per/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/per/interfaces/example4.go +++ b/_content/tour/per/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/interfaces/example6.go b/_content/tour/per/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/per/interfaces/example6.go +++ b/_content/tour/per/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/maps/example3.go b/_content/tour/per/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/per/maps/example3.go +++ b/_content/tour/per/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/maps/example6.go b/_content/tour/per/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/per/maps/example6.go +++ b/_content/tour/per/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/methods/example5.go b/_content/tour/per/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/per/methods/example5.go +++ b/_content/tour/per/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/methods/exercise1.go b/_content/tour/per/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/per/methods/exercise1.go +++ b/_content/tour/per/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/slices/example1.go b/_content/tour/per/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/per/slices/example1.go +++ b/_content/tour/per/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/slices/example8.go b/_content/tour/per/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/per/slices/example8.go +++ b/_content/tour/per/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/per/welcome/sandbox.go b/_content/tour/per/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/per/welcome/sandbox.go +++ b/_content/tour/per/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/pol/algorithms/fun/freq_concurrent.go b/_content/tour/pol/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/pol/algorithms/fun/freq_concurrent.go +++ b/_content/tour/pol/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/arrays/example2.go b/_content/tour/pol/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/pol/arrays/example2.go +++ b/_content/tour/pol/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/composition/assertions/example1.go b/_content/tour/pol/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/pol/composition/assertions/example1.go +++ b/_content/tour/pol/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/composition/decoupling/exercise1.go b/_content/tour/pol/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/pol/composition/decoupling/exercise1.go +++ b/_content/tour/pol/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/composition/grouping/example1.go b/_content/tour/pol/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/pol/composition/grouping/example1.go +++ b/_content/tour/pol/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/composition/mocking/example1.go b/_content/tour/pol/composition/mocking/example1.go index e72930c1..445b6e18 100644 --- a/_content/tour/pol/composition/mocking/example1.go +++ b/_content/tour/pol/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/constants/example4.go b/_content/tour/pol/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/pol/constants/example4.go +++ b/_content/tour/pol/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/content_test.go b/_content/tour/pol/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/pol/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/pol/context/exercise1.go b/_content/tour/pol/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/pol/context/exercise1.go +++ b/_content/tour/pol/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/data_race/example5.go b/_content/tour/pol/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/pol/data_race/example5.go +++ b/_content/tour/pol/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/data_race/example6.go b/_content/tour/pol/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/pol/data_race/example6.go +++ b/_content/tour/pol/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/error-handling/example4.go b/_content/tour/pol/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/pol/error-handling/example4.go +++ b/_content/tour/pol/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/error-handling/example5.go b/_content/tour/pol/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/pol/error-handling/example5.go +++ b/_content/tour/pol/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/error-handling/exercise1.go b/_content/tour/pol/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/pol/error-handling/exercise1.go +++ b/_content/tour/pol/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/error-handling/exercise2.go b/_content/tour/pol/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/pol/error-handling/exercise2.go +++ b/_content/tour/pol/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/exporting/answer1.go b/_content/tour/pol/exporting/answer1.go index f0abc4c6..dcd28e17 100644 --- a/_content/tour/pol/exporting/answer1.go +++ b/_content/tour/pol/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/exporting/example1.go b/_content/tour/pol/exporting/example1.go index 5cd1820c..a828b2f6 100644 --- a/_content/tour/pol/exporting/example1.go +++ b/_content/tour/pol/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/exporting/example2.go b/_content/tour/pol/exporting/example2.go index cec2201e..91735097 100644 --- a/_content/tour/pol/exporting/example2.go +++ b/_content/tour/pol/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/exporting/example3.go b/_content/tour/pol/exporting/example3.go index 00a1dda7..1ba82103 100644 --- a/_content/tour/pol/exporting/example3.go +++ b/_content/tour/pol/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/exporting/example4.go b/_content/tour/pol/exporting/example4.go index f2b0174a..93d06902 100644 --- a/_content/tour/pol/exporting/example4.go +++ b/_content/tour/pol/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/exporting/example5.go b/_content/tour/pol/exporting/example5.go index 70da23ed..8ae0fa09 100644 --- a/_content/tour/pol/exporting/example5.go +++ b/_content/tour/pol/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/exporting/exercise1.go b/_content/tour/pol/exporting/exercise1.go index bafbd5a5..4ff23346 100644 --- a/_content/tour/pol/exporting/exercise1.go +++ b/_content/tour/pol/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/generics/type-constraints/exercise1.go b/_content/tour/pol/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/pol/generics/type-constraints/exercise1.go +++ b/_content/tour/pol/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/interfaces/example2.go b/_content/tour/pol/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/pol/interfaces/example2.go +++ b/_content/tour/pol/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/interfaces/example3.go b/_content/tour/pol/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/pol/interfaces/example3.go +++ b/_content/tour/pol/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/interfaces/example4.go b/_content/tour/pol/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/pol/interfaces/example4.go +++ b/_content/tour/pol/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/interfaces/example6.go b/_content/tour/pol/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/pol/interfaces/example6.go +++ b/_content/tour/pol/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/maps/example3.go b/_content/tour/pol/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/pol/maps/example3.go +++ b/_content/tour/pol/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/maps/example6.go b/_content/tour/pol/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/pol/maps/example6.go +++ b/_content/tour/pol/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/methods/example5.go b/_content/tour/pol/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/pol/methods/example5.go +++ b/_content/tour/pol/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/methods/exercise1.go b/_content/tour/pol/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/pol/methods/exercise1.go +++ b/_content/tour/pol/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/slices/example1.go b/_content/tour/pol/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/pol/slices/example1.go +++ b/_content/tour/pol/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/slices/example8.go b/_content/tour/pol/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/pol/slices/example8.go +++ b/_content/tour/pol/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/pol/welcome/sandbox.go b/_content/tour/pol/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/pol/welcome/sandbox.go +++ b/_content/tour/pol/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/por/algorithms/fun/freq_concurrent.go b/_content/tour/por/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/por/algorithms/fun/freq_concurrent.go +++ b/_content/tour/por/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/arrays/example2.go b/_content/tour/por/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/por/arrays/example2.go +++ b/_content/tour/por/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/composition/assertions/example1.go b/_content/tour/por/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/por/composition/assertions/example1.go +++ b/_content/tour/por/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/composition/decoupling/exercise1.go b/_content/tour/por/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/por/composition/decoupling/exercise1.go +++ b/_content/tour/por/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/composition/grouping/example1.go b/_content/tour/por/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/por/composition/grouping/example1.go +++ b/_content/tour/por/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/composition/mocking/example1.go b/_content/tour/por/composition/mocking/example1.go index e72930c1..445b6e18 100644 --- a/_content/tour/por/composition/mocking/example1.go +++ b/_content/tour/por/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/constants/example4.go b/_content/tour/por/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/por/constants/example4.go +++ b/_content/tour/por/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/content_test.go b/_content/tour/por/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/por/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/por/context/exercise1.go b/_content/tour/por/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/por/context/exercise1.go +++ b/_content/tour/por/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/data_race/example5.go b/_content/tour/por/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/por/data_race/example5.go +++ b/_content/tour/por/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/data_race/example6.go b/_content/tour/por/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/por/data_race/example6.go +++ b/_content/tour/por/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/error-handling/example4.go b/_content/tour/por/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/por/error-handling/example4.go +++ b/_content/tour/por/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/error-handling/example5.go b/_content/tour/por/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/por/error-handling/example5.go +++ b/_content/tour/por/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/error-handling/exercise1.go b/_content/tour/por/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/por/error-handling/exercise1.go +++ b/_content/tour/por/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/error-handling/exercise2.go b/_content/tour/por/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/por/error-handling/exercise2.go +++ b/_content/tour/por/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/exporting/answer1.go b/_content/tour/por/exporting/answer1.go index f0abc4c6..dcd28e17 100644 --- a/_content/tour/por/exporting/answer1.go +++ b/_content/tour/por/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/exporting/example1.go b/_content/tour/por/exporting/example1.go index 5cd1820c..a828b2f6 100644 --- a/_content/tour/por/exporting/example1.go +++ b/_content/tour/por/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/exporting/example2.go b/_content/tour/por/exporting/example2.go index cec2201e..91735097 100644 --- a/_content/tour/por/exporting/example2.go +++ b/_content/tour/por/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/exporting/example3.go b/_content/tour/por/exporting/example3.go index 00a1dda7..1ba82103 100644 --- a/_content/tour/por/exporting/example3.go +++ b/_content/tour/por/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/exporting/example4.go b/_content/tour/por/exporting/example4.go index f2b0174a..93d06902 100644 --- a/_content/tour/por/exporting/example4.go +++ b/_content/tour/por/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/exporting/example5.go b/_content/tour/por/exporting/example5.go index 70da23ed..8ae0fa09 100644 --- a/_content/tour/por/exporting/example5.go +++ b/_content/tour/por/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/exporting/exercise1.go b/_content/tour/por/exporting/exercise1.go index bafbd5a5..4ff23346 100644 --- a/_content/tour/por/exporting/exercise1.go +++ b/_content/tour/por/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/generics/type-constraints/exercise1.go b/_content/tour/por/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/por/generics/type-constraints/exercise1.go +++ b/_content/tour/por/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/interfaces/example2.go b/_content/tour/por/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/por/interfaces/example2.go +++ b/_content/tour/por/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/interfaces/example3.go b/_content/tour/por/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/por/interfaces/example3.go +++ b/_content/tour/por/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/interfaces/example4.go b/_content/tour/por/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/por/interfaces/example4.go +++ b/_content/tour/por/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/interfaces/example6.go b/_content/tour/por/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/por/interfaces/example6.go +++ b/_content/tour/por/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/maps/example3.go b/_content/tour/por/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/por/maps/example3.go +++ b/_content/tour/por/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/maps/example6.go b/_content/tour/por/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/por/maps/example6.go +++ b/_content/tour/por/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/methods/example5.go b/_content/tour/por/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/por/methods/example5.go +++ b/_content/tour/por/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/methods/exercise1.go b/_content/tour/por/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/por/methods/exercise1.go +++ b/_content/tour/por/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/slices/example1.go b/_content/tour/por/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/por/slices/example1.go +++ b/_content/tour/por/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/slices/example8.go b/_content/tour/por/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/por/slices/example8.go +++ b/_content/tour/por/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/por/welcome/sandbox.go b/_content/tour/por/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/por/welcome/sandbox.go +++ b/_content/tour/por/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/rus/algorithms/fun/freq_concurrent.go b/_content/tour/rus/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/rus/algorithms/fun/freq_concurrent.go +++ b/_content/tour/rus/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/arrays/example2.go b/_content/tour/rus/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/rus/arrays/example2.go +++ b/_content/tour/rus/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/composition/assertions/example1.go b/_content/tour/rus/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/rus/composition/assertions/example1.go +++ b/_content/tour/rus/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/composition/decoupling/exercise1.go b/_content/tour/rus/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/rus/composition/decoupling/exercise1.go +++ b/_content/tour/rus/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/composition/grouping/example1.go b/_content/tour/rus/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/rus/composition/grouping/example1.go +++ b/_content/tour/rus/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/composition/mocking/example1.go b/_content/tour/rus/composition/mocking/example1.go index 8be5dd98..da1e04c9 100644 --- a/_content/tour/rus/composition/mocking/example1.go +++ b/_content/tour/rus/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/constants/example4.go b/_content/tour/rus/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/rus/constants/example4.go +++ b/_content/tour/rus/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/content_test.go b/_content/tour/rus/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/rus/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/rus/context/exercise1.go b/_content/tour/rus/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/rus/context/exercise1.go +++ b/_content/tour/rus/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/data_race/example5.go b/_content/tour/rus/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/rus/data_race/example5.go +++ b/_content/tour/rus/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/data_race/example6.go b/_content/tour/rus/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/rus/data_race/example6.go +++ b/_content/tour/rus/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/error-handling/example4.go b/_content/tour/rus/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/rus/error-handling/example4.go +++ b/_content/tour/rus/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/error-handling/example5.go b/_content/tour/rus/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/rus/error-handling/example5.go +++ b/_content/tour/rus/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/error-handling/exercise1.go b/_content/tour/rus/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/rus/error-handling/exercise1.go +++ b/_content/tour/rus/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/error-handling/exercise2.go b/_content/tour/rus/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/rus/error-handling/exercise2.go +++ b/_content/tour/rus/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/exporting/answer1.go b/_content/tour/rus/exporting/answer1.go index 59f33b35..53972b27 100644 --- a/_content/tour/rus/exporting/answer1.go +++ b/_content/tour/rus/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/exporting/example1.go b/_content/tour/rus/exporting/example1.go index 6326f8d1..81756296 100644 --- a/_content/tour/rus/exporting/example1.go +++ b/_content/tour/rus/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/exporting/example2.go b/_content/tour/rus/exporting/example2.go index 5854e07b..4c53a8e0 100644 --- a/_content/tour/rus/exporting/example2.go +++ b/_content/tour/rus/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/exporting/example3.go b/_content/tour/rus/exporting/example3.go index 89e87cb0..7a6728ff 100644 --- a/_content/tour/rus/exporting/example3.go +++ b/_content/tour/rus/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/exporting/example4.go b/_content/tour/rus/exporting/example4.go index dba47fd1..a321f3c5 100644 --- a/_content/tour/rus/exporting/example4.go +++ b/_content/tour/rus/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/exporting/example5.go b/_content/tour/rus/exporting/example5.go index f64ce5bc..5d77a697 100644 --- a/_content/tour/rus/exporting/example5.go +++ b/_content/tour/rus/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/exporting/exercise1.go b/_content/tour/rus/exporting/exercise1.go index e90a1db2..a29ee1ba 100644 --- a/_content/tour/rus/exporting/exercise1.go +++ b/_content/tour/rus/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/generics/type-constraints/exercise1.go b/_content/tour/rus/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/rus/generics/type-constraints/exercise1.go +++ b/_content/tour/rus/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/interfaces/example2.go b/_content/tour/rus/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/rus/interfaces/example2.go +++ b/_content/tour/rus/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/interfaces/example3.go b/_content/tour/rus/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/rus/interfaces/example3.go +++ b/_content/tour/rus/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/interfaces/example4.go b/_content/tour/rus/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/rus/interfaces/example4.go +++ b/_content/tour/rus/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/interfaces/example6.go b/_content/tour/rus/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/rus/interfaces/example6.go +++ b/_content/tour/rus/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/maps/example3.go b/_content/tour/rus/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/rus/maps/example3.go +++ b/_content/tour/rus/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/maps/example6.go b/_content/tour/rus/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/rus/maps/example6.go +++ b/_content/tour/rus/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/methods/example5.go b/_content/tour/rus/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/rus/methods/example5.go +++ b/_content/tour/rus/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/methods/exercise1.go b/_content/tour/rus/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/rus/methods/exercise1.go +++ b/_content/tour/rus/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/slices/example1.go b/_content/tour/rus/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/rus/slices/example1.go +++ b/_content/tour/rus/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/slices/example8.go b/_content/tour/rus/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/rus/slices/example8.go +++ b/_content/tour/rus/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/rus/welcome/sandbox.go b/_content/tour/rus/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/rus/welcome/sandbox.go +++ b/_content/tour/rus/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/tur/algorithms/fun/freq_concurrent.go b/_content/tour/tur/algorithms/fun/freq_concurrent.go index 3b91df41..edfa678f 100644 --- a/_content/tour/tur/algorithms/fun/freq_concurrent.go +++ b/_content/tour/tur/algorithms/fun/freq_concurrent.go @@ -1,3 +1,5 @@ +//go:build OMIT + // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/arrays/example2.go b/_content/tour/tur/arrays/example2.go index ce6e4299..5c41c454 100644 --- a/_content/tour/tur/arrays/example2.go +++ b/_content/tour/tur/arrays/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/composition/assertions/example1.go b/_content/tour/tur/composition/assertions/example1.go index 5d1191cb..f0e81147 100644 --- a/_content/tour/tur/composition/assertions/example1.go +++ b/_content/tour/tur/composition/assertions/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/composition/decoupling/exercise1.go b/_content/tour/tur/composition/decoupling/exercise1.go index db2f3a41..98bd38df 100644 --- a/_content/tour/tur/composition/decoupling/exercise1.go +++ b/_content/tour/tur/composition/decoupling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/composition/grouping/example1.go b/_content/tour/tur/composition/grouping/example1.go index 474b91ca..59d0bea8 100644 --- a/_content/tour/tur/composition/grouping/example1.go +++ b/_content/tour/tur/composition/grouping/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/composition/mocking/example1.go b/_content/tour/tur/composition/mocking/example1.go index e72930c1..445b6e18 100644 --- a/_content/tour/tur/composition/mocking/example1.go +++ b/_content/tour/tur/composition/mocking/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/constants/example4.go b/_content/tour/tur/constants/example4.go index 1b735f9c..64560df1 100644 --- a/_content/tour/tur/constants/example4.go +++ b/_content/tour/tur/constants/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/content_test.go b/_content/tour/tur/content_test.go deleted file mode 100644 index 6c7b22d4..00000000 --- a/_content/tour/tur/content_test.go +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package content - -import ( - "bytes" - "errors" - "fmt" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "strings" - "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" -) - -// Test that all the .go files inside the content file build -// and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { - if _, err := exec.LookPath("go"); err != nil { - t.Skipf("skipping because 'go' executable not available: %v", err) - } - - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { - if filepath.Ext(path) != ".go" { - return nil - } - if filepath.Base(path) == "content_test.go" { - return nil - } - t.Run(path, func(t *testing.T) { - t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { - t.Errorf("%v: %v", path, err) - } - }) - return nil - }) - if err != nil { - t.Error(err) - } -} - -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) - if err != nil { - return err - } - - build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") - } - if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) - } - - if strings.Contains(build, "no-build") { - return nil - } - bin := filepath.Join(scratch, filepath.Base(path)+".exe") - out, err := exec.Command("go", "build", "-o", bin, path).CombinedOutput() - if err != nil { - return fmt.Errorf("build error: %v\noutput:\n%s", err, out) - } - defer os.Remove(bin) - - if strings.Contains(build, "no-run") { - return nil - } - out, err = exec.Command(bin).CombinedOutput() - if err != nil { - return fmt.Errorf("%v\nOutput:\n%s", err, out) - } - return nil -} diff --git a/_content/tour/tur/context/exercise1.go b/_content/tour/tur/context/exercise1.go index d7225c6c..cf7d6224 100644 --- a/_content/tour/tur/context/exercise1.go +++ b/_content/tour/tur/context/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/data_race/example5.go b/_content/tour/tur/data_race/example5.go index dd7cb0fc..fda16cd5 100644 --- a/_content/tour/tur/data_race/example5.go +++ b/_content/tour/tur/data_race/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/data_race/example6.go b/_content/tour/tur/data_race/example6.go index 61243b57..8ab7578d 100644 --- a/_content/tour/tur/data_race/example6.go +++ b/_content/tour/tur/data_race/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/error-handling/example4.go b/_content/tour/tur/error-handling/example4.go index 40f8303e..5e2e7f48 100644 --- a/_content/tour/tur/error-handling/example4.go +++ b/_content/tour/tur/error-handling/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/error-handling/example5.go b/_content/tour/tur/error-handling/example5.go index de920b11..4c677b32 100644 --- a/_content/tour/tur/error-handling/example5.go +++ b/_content/tour/tur/error-handling/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/error-handling/exercise1.go b/_content/tour/tur/error-handling/exercise1.go index 0fb21e45..378257d8 100644 --- a/_content/tour/tur/error-handling/exercise1.go +++ b/_content/tour/tur/error-handling/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/error-handling/exercise2.go b/_content/tour/tur/error-handling/exercise2.go index 59310aa9..e2883ef2 100644 --- a/_content/tour/tur/error-handling/exercise2.go +++ b/_content/tour/tur/error-handling/exercise2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/exporting/answer1.go b/_content/tour/tur/exporting/answer1.go index f0abc4c6..dcd28e17 100644 --- a/_content/tour/tur/exporting/answer1.go +++ b/_content/tour/tur/exporting/answer1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/exporting/example1.go b/_content/tour/tur/exporting/example1.go index 5cd1820c..a828b2f6 100644 --- a/_content/tour/tur/exporting/example1.go +++ b/_content/tour/tur/exporting/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/exporting/example2.go b/_content/tour/tur/exporting/example2.go index cec2201e..91735097 100644 --- a/_content/tour/tur/exporting/example2.go +++ b/_content/tour/tur/exporting/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/exporting/example3.go b/_content/tour/tur/exporting/example3.go index 00a1dda7..1ba82103 100644 --- a/_content/tour/tur/exporting/example3.go +++ b/_content/tour/tur/exporting/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/exporting/example4.go b/_content/tour/tur/exporting/example4.go index f2b0174a..93d06902 100644 --- a/_content/tour/tur/exporting/example4.go +++ b/_content/tour/tur/exporting/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/exporting/example5.go b/_content/tour/tur/exporting/example5.go index 70da23ed..8ae0fa09 100644 --- a/_content/tour/tur/exporting/example5.go +++ b/_content/tour/tur/exporting/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/exporting/exercise1.go b/_content/tour/tur/exporting/exercise1.go index bafbd5a5..4ff23346 100644 --- a/_content/tour/tur/exporting/exercise1.go +++ b/_content/tour/tur/exporting/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/generics/type-constraints/exercise1.go b/_content/tour/tur/generics/type-constraints/exercise1.go index 01dd1324..13c74e40 100644 --- a/_content/tour/tur/generics/type-constraints/exercise1.go +++ b/_content/tour/tur/generics/type-constraints/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/interfaces/example2.go b/_content/tour/tur/interfaces/example2.go index a9e10aa4..3b56f6fd 100644 --- a/_content/tour/tur/interfaces/example2.go +++ b/_content/tour/tur/interfaces/example2.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/interfaces/example3.go b/_content/tour/tur/interfaces/example3.go index 2ed6c756..cbd2a139 100644 --- a/_content/tour/tur/interfaces/example3.go +++ b/_content/tour/tur/interfaces/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/interfaces/example4.go b/_content/tour/tur/interfaces/example4.go index acb8e2f6..e8cab8ba 100644 --- a/_content/tour/tur/interfaces/example4.go +++ b/_content/tour/tur/interfaces/example4.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/interfaces/example6.go b/_content/tour/tur/interfaces/example6.go index 68825182..5187153e 100644 --- a/_content/tour/tur/interfaces/example6.go +++ b/_content/tour/tur/interfaces/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/maps/example3.go b/_content/tour/tur/maps/example3.go index a1fb2fa6..a9913573 100644 --- a/_content/tour/tur/maps/example3.go +++ b/_content/tour/tur/maps/example3.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/maps/example6.go b/_content/tour/tur/maps/example6.go index bfffd74e..e79d9f1a 100644 --- a/_content/tour/tur/maps/example6.go +++ b/_content/tour/tur/maps/example6.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/methods/example5.go b/_content/tour/tur/methods/example5.go index fb0d8cf7..13275785 100644 --- a/_content/tour/tur/methods/example5.go +++ b/_content/tour/tur/methods/example5.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/methods/exercise1.go b/_content/tour/tur/methods/exercise1.go index 555d0ef1..8e09f37c 100644 --- a/_content/tour/tur/methods/exercise1.go +++ b/_content/tour/tur/methods/exercise1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || nobuild // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/slices/example1.go b/_content/tour/tur/slices/example1.go index 36f418d4..f86c3764 100644 --- a/_content/tour/tur/slices/example1.go +++ b/_content/tour/tur/slices/example1.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/slices/example8.go b/_content/tour/tur/slices/example8.go index af4361da..ad9b748d 100644 --- a/_content/tour/tur/slices/example8.go +++ b/_content/tour/tur/slices/example8.go @@ -1,4 +1,4 @@ -//go:build OMIT +//go:build OMIT || norun // All material is licensed under the Apache License Version 2.0, January 2004 // http://www.apache.org/licenses/LICENSE-2.0 diff --git a/_content/tour/tur/welcome/sandbox.go b/_content/tour/tur/welcome/sandbox.go index 183bb929..9525b562 100644 --- a/_content/tour/tur/welcome/sandbox.go +++ b/_content/tour/tur/welcome/sandbox.go @@ -1,3 +1,5 @@ +//go:build OMIT + package main import ( diff --git a/_content/tour/eng/content_test.go b/content_test.go similarity index 57% rename from _content/tour/eng/content_test.go rename to content_test.go index 6c7b22d4..719c6dae 100644 --- a/_content/tour/eng/content_test.go +++ b/content_test.go @@ -2,39 +2,29 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -package content +package website import ( "bytes" "errors" "fmt" - "io/ioutil" "os" "os/exec" "path/filepath" "strings" "testing" - - // Keep github.com/ardanlabs/gotour/external/tour/wc in our go.mod require list for use during test. - _ "github.com/ardanlabs/gotour/external/tour/wc" ) // Test that all the .go files inside the content file build // and execute (without checking for output correctness). -// Files that contain the string "// +build no-build" are not built. -// Files that contain the string "// +build no-run" are not executed. -func TestContent(t *testing.T) { +// Files that contain the build constraint "nobuild" are not built. +// Files that contain the build constraint "norun" are not executed. +func TestContentTour(t *testing.T) { if _, err := exec.LookPath("go"); err != nil { t.Skipf("skipping because 'go' executable not available: %v", err) } - scratch, err := ioutil.TempDir("", "tour-content-test") - if err != nil { - t.Fatal(err) - } - defer os.RemoveAll(scratch) - - err = filepath.Walk(".", func(path string, fi os.FileInfo, err error) error { + err := filepath.Walk(filepath.Join("_content", "tour"), func(path string, fi os.FileInfo, err error) error { if filepath.Ext(path) != ".go" { return nil } @@ -43,7 +33,7 @@ func TestContent(t *testing.T) { } t.Run(path, func(t *testing.T) { t.Parallel() - if err := testSnippet(t, filepath.ToSlash(path), scratch); err != nil { + if err := testSnippet(filepath.ToSlash(path), t.TempDir()); err != nil { t.Errorf("%v: %v", path, err) } }) @@ -54,21 +44,21 @@ func TestContent(t *testing.T) { } } -func testSnippet(t *testing.T, path, scratch string) error { - b, err := ioutil.ReadFile(path) +func testSnippet(path, scratch string) error { + b, err := os.ReadFile(path) if err != nil { return err } build := string(bytes.SplitN(b, []byte{'\n'}, 2)[0]) - if !strings.HasPrefix(build, "// +build ") { - return errors.New("first line is not a +build comment") + if !strings.HasPrefix(build, "//go:build ") { + return errors.New("first line is not a go:build comment") } if !strings.Contains(build, "OMIT") { - return errors.New(`+build comment does not contain "OMIT"`) + return errors.New(`go:build comment does not contain "OMIT"`) } - if strings.Contains(build, "no-build") { + if strings.Contains(build, "nobuild") { return nil } bin := filepath.Join(scratch, filepath.Base(path)+".exe") @@ -78,7 +68,7 @@ func testSnippet(t *testing.T, path, scratch string) error { } defer os.Remove(bin) - if strings.Contains(build, "no-run") { + if strings.Contains(build, "norun") { return nil } out, err = exec.Command(bin).CombinedOutput()