github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/logictest/logic_test.go (about)

     1  // Copyright 2017 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  package logictest
    12  
    13  import (
    14  	"go/build"
    15  	"os"
    16  	"path/filepath"
    17  	"testing"
    18  
    19  	"github.com/cockroachdb/cockroach/pkg/util/leaktest"
    20  )
    21  
    22  // TestLogic runs logic tests that were written by hand to test various
    23  // CockroachDB features. The tests use a similar methodology to the SQLLite
    24  // Sqllogictests. All of these tests should only verify correctness of output,
    25  // and not how that output was derived. Therefore, these tests can be run
    26  // using the heuristic planner, the cost-based optimizer, or even run against
    27  // Postgres to verify it returns the same logical results.
    28  //
    29  // See the comments in logic.go for more details.
    30  func TestLogic(t *testing.T) {
    31  	defer leaktest.AfterTest(t)()
    32  	RunLogicTest(t, TestServerArgs{}, "testdata/logic_test/[^.]*")
    33  }
    34  
    35  // TestSqlLiteLogic runs the supported SqlLite logic tests. See the comments
    36  // for runSQLLiteLogicTest for more detail on these tests.
    37  func TestSqlLiteLogic(t *testing.T) {
    38  	defer leaktest.AfterTest(t)()
    39  	runSQLLiteLogicTest(t,
    40  		"/test/index/between/*/*.test",
    41  		"/test/index/commute/*/*.test",
    42  		"/test/index/delete/*/*.test",
    43  		"/test/index/in/*/*.test",
    44  		"/test/index/orderby/*/*.test",
    45  		"/test/index/orderby_nosort/*/*.test",
    46  		"/test/index/view/*/*.test",
    47  
    48  		"/test/select1.test",
    49  		"/test/select2.test",
    50  		"/test/select3.test",
    51  		"/test/select4.test",
    52  
    53  		// TODO(andyk): No support for join ordering yet, so this takes too long.
    54  		// "/test/select5.test",
    55  
    56  		// TODO(pmattis): Incompatibilities in numeric types.
    57  		// For instance, we type SUM(int) as a decimal since all of our ints are
    58  		// int64.
    59  		// "/test/random/expr/*.test",
    60  
    61  		// TODO(pmattis): We don't support unary + on strings.
    62  		// "/test/index/random/*/*.test",
    63  		// "/test/random/aggregates/*.test",
    64  		// "/test/random/groupby/*.test",
    65  		// "/test/random/select/*.test",
    66  	)
    67  }
    68  
    69  // runSQLLiteLogicTest runs logic tests from CockroachDB's fork of sqllogictest:
    70  //
    71  //   https://www.sqlite.org/sqllogictest/doc/trunk/about.wiki
    72  //
    73  // This fork contains many generated tests created by the SqlLite project that
    74  // ensure the tested SQL database returns correct statement and query output.
    75  // The logic tests are reasonably independent of the specific dialect of each
    76  // database so that they can be retargeted. In fact, the expected output for
    77  // each test can be generated by one database and then used to verify the output
    78  // of another database.
    79  //
    80  // By default, these tests are skipped, unless the `bigtest` flag is specified.
    81  // The reason for this is that these tests are contained in another repo that
    82  // must be present on the machine, and because they take a long time to run.
    83  //
    84  // See the comments in logic.go for more details.
    85  func runSQLLiteLogicTest(t *testing.T, globs ...string) {
    86  	if !*bigtest {
    87  		t.Skip("-bigtest flag must be specified to run this test")
    88  	}
    89  
    90  	logicTestPath := build.Default.GOPATH + "/src/github.com/cockroachdb/sqllogictest"
    91  	if _, err := os.Stat(logicTestPath); os.IsNotExist(err) {
    92  		fullPath, err := filepath.Abs(logicTestPath)
    93  		if err != nil {
    94  			t.Fatal(err)
    95  		}
    96  		t.Fatalf("unable to find sqllogictest repo: %s\n"+
    97  			"git clone https://github.com/cockroachdb/sqllogictest %s",
    98  			logicTestPath, fullPath)
    99  		return
   100  	}
   101  
   102  	// Prefix the globs with the logicTestPath.
   103  	prefixedGlobs := make([]string, len(globs))
   104  	for i, glob := range globs {
   105  		prefixedGlobs[i] = logicTestPath + glob
   106  	}
   107  
   108  	// SQLLite logic tests can be very disk (with '-disk' configs) intensive,
   109  	// so we give them larger temp storage limit than other logic tests get.
   110  	serverArgs := TestServerArgs{
   111  		tempStorageDiskLimit: 512 << 20, // 512 MiB
   112  	}
   113  	RunLogicTest(t, serverArgs, prefixedGlobs...)
   114  }