1#include "catch.hpp"
2#include "duckdb/common/file_system.hpp"
3#include "dbgen.hpp"
4#include "test_helpers.hpp"
5
6#include <fstream>
7#include <streambuf>
8#include <string>
9
10using namespace duckdb;
11using namespace std;
12
13constexpr const char *QUERY_DIRECTORY = "test/sqlsmith/queries";
14static FileSystem fs;
15
16static void test_runner() {
17 auto file_name = Catch::getResultCapture().getCurrentTestName();
18 auto fname = fs.JoinPath(QUERY_DIRECTORY, file_name);
19
20 unique_ptr<QueryResult> result;
21 DuckDB db(nullptr);
22 Connection con(db);
23
24 con.EnableProfiling();
25
26 tpch::dbgen(0.1, db);
27
28 ifstream t(fname);
29 string query((istreambuf_iterator<char>(t)), istreambuf_iterator<char>());
30 con.Query(query.c_str());
31 // we don't know whether the query fails or not and we don't know the
32 // correct result we just don't want it to crash
33 REQUIRE(1 == 1);
34}
35
36struct RegisterSQLSmithTests {
37 RegisterSQLSmithTests() {
38 return;
39 // register a separate SQL Smith test for each file in the QUERY_DIRECTORY
40 fs.ListFiles(QUERY_DIRECTORY,
41 [&](const string &path) { REGISTER_TEST_CASE(test_runner, path, "[sqlsmith][.]"); });
42 }
43};
44RegisterSQLSmithTests register_sqlsmith_test;
45