// Override overrides the values in readline.Config that need to be // set with wrapped values. func Override(cfg *readline.Config) *readline.Config { cfg.Stdin = wrappedstreams.Stdin() cfg.Stdout = wrappedstreams.Stdout() cfg.Stderr = wrappedstreams.Stderr() cfg.FuncGetWidth = TerminalWidth cfg.FuncIsTerminal = IsTerminal rm := RawMode{StdinFd: int(wrappedstreams.Stdin().Fd())} cfg.FuncMakeRaw = rm.Enter cfg.FuncExitRaw = rm.Exit return cfg }
// TestSQLLex tests the usage of the lexer in the sql subcommand. func TestSQLLex(t *testing.T) { defer leaktest.AfterTest(t)() s, _, _ := serverutils.StartServer(t, base.TestServerArgs{Insecure: true}) defer s.Stopper().Stop() pgurl, err := s.(*server.TestServer).Cfg.PGURL(url.User(security.RootUser)) if err != nil { t.Fatal(err) } conn := makeSQLConn(pgurl.String()) defer conn.Close() tests := []struct { in string expect string }{ { in: ` select ' \? ; '; `, expect: `+---------------+ | e'\n\\?\n;\n' | +---------------+ |  | | \? | | ; | +---------------+ (1 row) `, }, { in: ` select '''' ; set syntax = modern; select '''' ; '''; `, expect: `+-------+ | e'\'' | +-------+ | ' | +-------+ (1 row) SET +------------+ | e'\'\n;\n' | +------------+ | ' | | ; | +------------+ (1 row) `, }, { in: `select 1; -- just a comment without final semicolon`, expect: `+---+ | 1 | +---+ | 1 | +---+ (1 row) `, }, } conf := readline.Config{ DisableAutoSaveHistory: true, FuncOnWidthChanged: func(func()) {}, } // Some other tests (TestDumpRow) mess with this, so make sure it's set. cliCtx.prettyFmt = true for _, test := range tests { conf.Stdin = strings.NewReader(test.in) out, err := captureOutput(func() { err := runInteractive(conn, &conf) if err != nil { t.Fatal(err) } }) if err != nil { t.Fatal(err) } if out != test.expect { t.Fatalf("%s:\nexpected: %s\ngot: %s", test.in, test.expect, out) } } }