Skip to content

Commit 41e635a

Browse files
authored
Auto-format .sql files using github.com/sql-formatter-org/sql-formatter - hello-world (#154)
[no important files changed]
1 parent 341b0df commit 41e635a

File tree

6 files changed

+68
-37
lines changed

6 files changed

+68
-37
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
INSERT INTO hello_world (greeting)
2-
VALUES ('Hello, World!');
1+
INSERT INTO
2+
hello_world (greeting)
3+
VALUES
4+
('Hello, World!');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
DROP TABLE IF EXISTS hello_world;
2+
23
CREATE TABLE hello_world (greeting TEXT);
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
INSERT INTO hello_world (greeting)
2-
VALUES ('Goodbye, Mars!');
1+
INSERT INTO
2+
hello_world (greeting)
3+
VALUES
4+
('Goodbye, Mars!');
Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
-- Setup test table and read in student solution:
22
.read ./test_setup.sql
3-
43
-- Test cases:
5-
INSERT INTO tests (name, uuid,
6-
expected)
7-
VALUES
8-
('Say Hi!', 'af9ffe10-dc13-42d8-a742-e7bdafac449d',
9-
'Hello, World!');
4+
INSERT INTO
5+
tests (name, uuid, expected)
6+
VALUES
7+
(
8+
'Say Hi!',
9+
'af9ffe10-dc13-42d8-a742-e7bdafac449d',
10+
'Hello, World!'
11+
);
1012

1113
-- Comparison of user input and the tests updates the status for each test:
1214
UPDATE tests
13-
SET status = 'pass'
14-
FROM (SELECT greeting FROM hello_world) AS actual
15-
WHERE actual.greeting = tests.expected;
15+
SET
16+
status = 'pass'
17+
FROM
18+
(
19+
SELECT
20+
greeting
21+
FROM
22+
hello_world
23+
) AS actual
24+
WHERE
25+
actual.greeting = tests.expected;
1626

1727
-- Write results and debug info:
1828
.read ./test_reporter.sql
Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,37 @@
11
-- Upadate message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = (
4-
'Greeting'
5-
|| ' is "' || COALESCE(actual.greeting, 'NULL')
6-
|| '" but should be "' || tests.expected || '"'
7-
)
8-
FROM (SELECT greeting FROM hello_world) AS actual
9-
WHERE tests.status = 'fail';
3+
SET
4+
message = (
5+
'Greeting' || ' is "' || COALESCE(actual.greeting, 'NULL') || '" but should be "' || tests.expected || '"'
6+
)
7+
FROM
8+
(
9+
SELECT
10+
greeting
11+
FROM
12+
hello_world
13+
) AS actual
14+
WHERE
15+
tests.status = 'fail';
1016

1117
-- Save results to ./output.json (needed by the online test-runner)
1218
.mode json
1319
.once './output.json'
14-
SELECT name, status, message, output, test_code, task_id
15-
FROM tests;
20+
SELECT
21+
name,
22+
status,
23+
message,
24+
output,
25+
test_code,
26+
task_id
27+
FROM
28+
tests;
1629

1730
-- Display test results in readable form for the student:
1831
.mode table
19-
SELECT name, status, message
20-
FROM tests;
32+
SELECT
33+
name,
34+
status,
35+
message
36+
FROM
37+
tests;
Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
-- Create database:
22
.read ./create_fixture.sql
3-
43
-- Read user student solution and save any output as markdown in user_output.md:
54
.mode markdown
65
.output user_output.md
76
.read ./hello-world.sql
87
.output
9-
108
-- Create a clean testing environment:
119
DROP TABLE IF EXISTS main.tests;
10+
1211
CREATE TABLE IF NOT EXISTS main.tests (
13-
-- uuid and name (description) are taken from the test.toml file
14-
uuid TEXT PRIMARY KEY,
15-
name TEXT NOT NULL,
16-
-- The following section is needed by the online test-runner
17-
status TEXT DEFAULT 'fail',
18-
message TEXT,
19-
output TEXT,
20-
test_code TEXT,
21-
task_id INTEGER DEFAULT NULL,
22-
-- Here are columns for the actual tests
23-
expected TEXT NOT NULL
12+
-- uuid and name (description) are taken from the test.toml file
13+
uuid TEXT PRIMARY KEY,
14+
name TEXT NOT NULL,
15+
-- The following section is needed by the online test-runner
16+
status TEXT DEFAULT 'fail',
17+
message TEXT,
18+
output TEXT,
19+
test_code TEXT,
20+
task_id INTEGER DEFAULT NULL,
21+
-- Here are columns for the actual tests
22+
expected TEXT NOT NULL
2423
);

0 commit comments

Comments
 (0)