Skip to content

CoreRel migrations #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 5 additions & 21 deletions src/code-util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,12 @@ function convert_input_dict_to_string(inputs::AbstractDict)
for input in inputs
name = string(input.first)

program *= "\ndef insert:" * name * " = "
program *= "\ndef insert[:" * name * "] { "

first = true
values = to_vector_of_tuples(input.second)
program *= join([input_element_to_string(v) for v in values], "; ")

values = input.second

if isempty(values)
program *= "{ }"
continue
end

values = to_vector_of_tuples(values)

for i in values
if first
first = false
else
program *= "; "
end

program *= input_element_to_string(i)
end
program *= " }"
end
return program
end
Expand Down Expand Up @@ -111,7 +95,7 @@ function generate_output_string_from_expected(expected::AbstractDict)
is_special_symbol(e.first) && continue

name = string(e.first)
program *= "\ndef output:" * name * " = " * name
program *= "\ndef output[:" * name * "]: " * name
end
return program
end
Expand Down
21 changes: 12 additions & 9 deletions src/testrel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ function create_test_database_name()::String
return gen_safe_name(basename)
end

function create_test_database(name::String, clone_db::Option{String}=nothing; retries_remaining=3)
function create_test_database(
name::String,
clone_db::Option{String}=nothing;
retries_remaining=3,
)
try
create_database(get_context(), name; source=clone_db, readtimeout=30).database
return name
Expand All @@ -56,13 +60,12 @@ function create_test_database(name::String, clone_db::Option{String}=nothing; re
return create_test_database(
new_name,
clone_db;
retries_remaining = retries_remaining - 1,
)
retries_remaining=retries_remaining - 1,
)
else
rethrow()
end
end

end

function delete_test_database(name::String)
Expand Down Expand Up @@ -378,24 +381,24 @@ function test_rel_steps(;
# Delete all but the core-intrinsics file, which would cause an error on deletion.
# We use the native `rel_primitive_neq` directly, since `!=` is defined in the stdlib.
config_query *= """
def delete:rel:catalog:model(srcname, src) =
rel:catalog:model(srcname, src) and
def delete(:rel, :catalog, :model, srcname, src):
rel(:catalog, :model, srcname, src) and
rel_primitive_neq(srcname, "rel/core-intrinsics")
"""
end

if debug && !debug_trace
config_query *= """def insert:rel:config:debug = "basic"\n"""
config_query *= """def insert[:rel, :config, :debug]: "basic" \n"""
end

if debug_trace
# Also set debug for its use in tracing test_rel execution
debug = true
config_query *= """def insert:rel:config:debug = "trace"\n"""
config_query *= """def insert[:rel, :config, :debug]: "trace"\n"""
end

if abort_on_error
config_query *= """def insert:rel:config:abort_on_error = true\n"""
config_query *= """def insert[:rel, :config, :abort_on_error]: true\n"""
end

if config_query != ""
Expand Down
74 changes: 33 additions & 41 deletions test/integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,44 @@
@test_rel(
name = "No input, expected, or output",
query = """
def result = 1
""",
)
def result { 1 }
""",)

@test_rel(
name = "No input or expected, has output",
query = """
def output = 1
def output { 1 }
""",
)

@test_rel(
name = "Input, no expected or output",
query = """
def result = input
def result { input }
""",
inputs = Dict(:input => [1]),
)

@test_rel(
name = "Input, output, no expected",
query = """
def output = input
def output { input }
""",
inputs = Dict(:input => [1]),
)

@test_rel(
name = "No input, expected output",
query = """
def output = 1
def output { 1 }
""",
expected = Dict(:output => [1]),
)

@test_rel(
name = "Input, expected output",
query = """
def output = input
def output { input }
""",
inputs = Dict(:input => [1]),
expected = Dict(:output => [1]),
Expand All @@ -51,15 +50,15 @@
@test_rel(
name = "Empty expected, empty actual",
query = """
def output = false
def output { false }
""",
expected = Dict(:output => []),
)

@test_rel(
name = "Empty expected, present actual",
query = """
def output = true
def output { true }
""",
expected = Dict(:output => []),
broken = true,
Expand All @@ -68,7 +67,7 @@
@test_rel(
name = "Broken expected",
query = """
def output = 1
def output { 1 }
""",
expected = Dict(:output => [2]),
broken = true,
Expand All @@ -77,103 +76,96 @@
@test_rel(
name = "Expected abort",
query = """
def result = 1
ic { result = 2 }
def result { 1 }
ic () requires result = 2
""",
expect_abort = true,
)

@test_rel(
name = "Broken abort",
query = """
def result = 1
ic { result = 2 }
def result { 1 }
ic () requires result = 2
""",
broken = true,
)

@test_rel(
name = "Expected problem",
query = """
def output = a
def output { a }
""",
expected_problems = [(:code => :UNDEFINED, :line => 1)],
expected_problems = [(:code => :UNDEFINED_IDENTIFIER, :line => 1)],
)

@test_rel(
name = "Expected problem, allow all",
query = """
def output = a
def output { a }
""",
expected_problems = [(:code => :UNDEFINED, :line => 1)],
expected_problems = [(:code => :UNDEFINED_IDENTIFIER, :line => 1)],
allow_unexpected = :error,
)

@test_rel(
name = "Expected problem, allow none",
query = """
def output = a
def output { a }
""",
expected_problems = [(:code => :UNDEFINED, :line => 1)],
expected_problems = [(:code => :UNDEFINED_IDENTIFIER, :line => 1)],
allow_unexpected = :none,
)

@test_rel(
name = "Expected problems, allow none",
query = """
// Line 1
def output = a
def output = b
def output { a }
def output { b }
""",
expected_problems = [
(:code => :UNDEFINED, :line => 2),
(:code => :UNDEFINED, :line => 3)],
(:code => :UNDEFINED_IDENTIFIER, :line => 2),
(:code => :UNDEFINED_IDENTIFIER, :line => 3),
],
allow_unexpected = :none,
)

@test_rel(
name = "Unexpected problem, ignore all",
query = """
def output = a
def output { a }
""",
allow_unexpected = :error,
)

@test_rel(
name = "Unexpected problem, broken",
query = """
def output = a
def output { a }
""",
broken = true,
)

@test_rel(
name = "abort_on_error",
query = "def output = a",
query = "def output { a }",
abort_on_error = true,
expect_abort = true,
)

# `setup` and `tags` keywords ignored
# --------------------------------------------------------

@test_rel(
name = "tags keyword ignored",
query = "def result = 1",
tags=[:foo],
)
@test_rel(name = "tags keyword ignored", query = "def result { 1 }", tags = [:foo],)

module FooSetup end

@test_rel(
name = "setup keyword ignored",
query = "def result = 1",
setup=FooSetup,
)
@test_rel(name = "setup keyword ignored", query = "def result { 1 }", setup = FooSetup,)

@test_rel(
name = "setup and tags keywords ignored",
query = "def result = 1",
setup=FooSetup,
tags=[:foo],
query = "def result { 1 }",
setup = FooSetup,
tags = [:foo],
)
Loading