#
# Correctness Tests
#

fatalerrors = length(ARGS) > 0 && ARGS[1] == "-f"
quiet = length(ARGS) > 0 && ARGS[1] == "-q"
anyerrors = false

using InMemoryDatasets, Test, Random

if VERSION > v"1.3"
    if Threads.nthreads() < 2
        @warn("Running with only one thread: correctness of parallel operations is not tested")
    else
        @show Threads.nthreads()
    end
end

my_tests = ["constructors.jl",
            "characters.jl",
            "utils.jl",
            "subdataset.jl",
            "broadcasting.jl",
            "data.jl",
            "byrow.jl",
            "sort.jl",
            "grouping.jl",
            "join.jl",
            "transpose.jl"
            ]

println("Running tests:")

for my_test in my_tests
    try
        include(my_test)
        println("\t\033[1m\033[32mPASSED\033[0m: $(my_test)")
    catch e
        global anyerrors = true
        println("\t\033[1m\033[31mFAILED\033[0m: $(my_test)")
        if fatalerrors
            rethrow(e)
        elseif !quiet
            showerror(stdout, e, backtrace())
            println()
        end
    end
end

if anyerrors
    throw("Tests failed")
end
