github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/nightly_pretty_test.go (about) 1 // Copyright 2019 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 // +build nightly 12 13 package tree_test 14 15 import ( 16 "path/filepath" 17 "testing" 18 19 _ "github.com/cockroachdb/cockroach/pkg/sql/sem/builtins" 20 "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 21 "github.com/cockroachdb/cockroach/pkg/util/leaktest" 22 ) 23 24 // TestPrettyData reads in a single SQL statement from a file, formats it at 25 // all line lengths, and compares that output to a known-good output file. It 26 // is most useful when changing or implementing the doc interface for a node, 27 // and should be used to compare and verify the changed output. 28 func TestPrettyData(t *testing.T) { 29 defer leaktest.AfterTest(t)() 30 matches, err := filepath.Glob(filepath.Join("testdata", "pretty", "*.sql")) 31 if err != nil { 32 t.Fatal(err) 33 } 34 cfg := testPrettyCfg 35 cfg.Align = tree.PrettyNoAlign 36 t.Run("ref", func(t *testing.T) { 37 runTestPrettyData(t, "ref", cfg, matches, false /*short*/) 38 }) 39 cfg.Align = tree.PrettyAlignAndDeindent 40 t.Run("align-deindent", func(t *testing.T) { 41 runTestPrettyData(t, "align-deindent", cfg, matches, false /*short*/) 42 }) 43 cfg.Align = tree.PrettyAlignOnly 44 t.Run("align-only", func(t *testing.T) { 45 runTestPrettyData(t, "align-only", cfg, matches, false /*short*/) 46 }) 47 }