Repository: duckdb/duckdb
File: tools/shell/tests/test_shell_basics.py (Python)

Code before:

def test_tables_schema_filtering(shell):
    test = (
        ShellTest(shell)
        .statement("CREATE SCHEMA a;")
        .statement("CREATE SCHEMA b;")
        .statement("CREATE TABLE a.foobar(name VARCHAR);")
        .statement("CREATE TABLE b.foobar(name VARCHAR);")
        .statement("CREATE TABLE a.unique_table(x INTEGER);")
        .statement("CREATE TABLE b.other_table(y INTEGER);")
        .statement(".tables a.%")
    )
    result = test.run()
    result.check_stdout("foobar        unique_table")

def test_tables_backward_compatibility(shell):
    test = (
        ShellTest(shell)
        .statement("CREATE TABLE main_table(i INTEGER);")
        .statement("CREATE TABLE unique_table(x INTEGER);")
        .statement(".tables")
    )
    result = test.run()
    result.check_stdout("main_table    unique_table")

def test_tables_with_views(shell):
    test = (
        ShellTest(shell)
        .statement("CREATE SCHEMA a;")
        .statement("CREATE SCHEMA b;")
        .statement("CREATE TABLE a.foobar(name VARCHAR);")
        .statement("CREATE TABLE b.foobar(name VARCHAR);")
        .statement("CREATE VIEW a.test_view AS SELECT 1 AS x;")
        .statement("CREATE VIEW b.test_view AS SELECT 2 AS y;")
        .statement(".tables")
    )
    result = test.run()
    result.check_stdout("a.foobar     a.test_view  b.foobar     b.test_view")

def test_indexes(shell):
    test = (
        ShellTest(shell)
        .statement("CREATE TABLE a (i INTEGER);")
        .statement("CREATE INDEX a_idx ON a(i);")
        .statement(".indexes a%")
    )
    result = test.run()
    result.check_stdout("a_idx")

def test_schema_pattern_no_result(shell):
    test = (

Review comment (suggestion):
This passed before due to empty strings matching everything/anything. Not sure if this is expected to throw an error to stderr

Code after:
    result.check_stdout("a.foobar     a.test_view  b.foobar     b.test_view")

def test_indexes(shell):
    test = (
        ShellTest(shell)
        .statement("CREATE TABLE a (i INTEGER);")
        .statement("CREATE INDEX a_idx ON a(i);")
        .statement(".indexes a%")
    )
    result = test.run()
    result.check_stdout("a_idx")

def test_schema_pattern_no_result(shell):
    test = (
        ShellTest(shell)
        .statement("create table testp (a integer)")
        .statement("create table test_p (b integer)")
        .statement(".schema %z%")
    )
    result = test.run()
    result.check_not_exist("CREATE TABLE")

def test_schema_pattern(shell):
    test = (
        ShellTest(shell)
        .statement("create table duckdb_p (a int, b varchar, c BIT);")
        .statement("create table p_duck(d INT, f DATE);")
        .statement(".schema %p")
    )
    result = test.run()
    result.check_stdout("CREATE TABLE duckdb_p(a INTEGER, b VARCHAR, c BIT);")

@pytest.mark.skipif(os.name == 'nt', reason="Windows treats newlines in a problematic manner")
def test_schema_pattern_extended(shell):
    test = (
        ShellTest(shell)
        .statement("create table duckdb_p (a int, b varchar, c BIT);")
        .statement("create table p_duck(d INT, f DATE);")
        .statement(".schema %p%")
    )
    result = test.run()
    expected = [
        "CREATE TABLE duckdb_p(a INTEGER, b VARCHAR, c BIT);",
        "CREATE TABLE p_duck(d INTEGER, f DATE);"
    ]
    result.check_stdout(expected)

def test_clone_error(shell):
    test = (
        ShellTest(shell)
        .statement(".clone")