Skip to content

Commit 6523d8e

Browse files
authored
Rewrite test result message (#92)
Context: https://forum.exercism.org/t/sqlite-test-output-is-empty-when-result-column-is-null/17467 Rewrite test message and use COALESCE to avoid `NULL` messing with the output.
1 parent b4f2346 commit 6523d8e

File tree

27 files changed

+144
-30
lines changed

27 files changed

+144
-30
lines changed

exercises/practice/allergies/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for ' || tests.task || ' ' || tests.item || ' ' || tests.score || ' is ' || actual.result || ', but should be ' || tests.expected
3+
SET message = (
4+
'Result for ' || tests.task || ' ' || tests.item || ' ' || tests.score
5+
|| ' is <' || COALESCE(actual.result, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
48
FROM (SELECT task, item, score, result FROM allergies) AS actual
59
WHERE (actual.task, actual.item, actual.score) = (tests.task, tests.item, tests.score) AND tests.status = 'fail';
610

exercises/practice/armstrong-numbers/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for ' || tests.number || ' is ' || actual.result || ', but should be ' || tests.expected
3+
SET message = (
4+
'Result for ' || tests.number
5+
|| ' is <' || COALESCE(actual.result, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
48
FROM (SELECT number, result FROM "armstrong-numbers") AS actual
59
WHERE actual.number = tests.number AND tests.status = 'fail';
610

exercises/practice/bob/test_reporter.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
-- Update message for failed tests to give helpful information:
2+
UPDATE tests
3+
SET message = (
4+
'Result for "' || tests.input || '"'
5+
|| ' is <' || COALESCE(actual.reply, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
8+
FROM (SELECT input, reply FROM bob) AS actual
9+
WHERE actual.input = tests.input AND tests.status = 'fail';
10+
111
-- Save results to ./output.json (needed by the online test-runner)
212
.mode json
313
.once './output.json'

exercises/practice/collatz-conjecture/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for ' || tests.number || ' is ' || actual.steps || ', but should be ' || tests.expected
3+
SET message = (
4+
'Result for ' || tests.number
5+
|| ' is <' || COALESCE(actual.steps, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
48
FROM (SELECT number, steps FROM collatz) AS actual
59
WHERE actual.number = tests.number AND tests.status = 'fail';
610

exercises/practice/darts/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for ' || tests.x || ', ' || tests.y || ' is ' || actual.score || ', but should be ' || tests.expected
3+
SET message = (
4+
'Result for (' || tests.x || ', ' || tests.y || ')'
5+
|| ' is <' || COALESCE(actual.score, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
48
FROM (SELECT x, y, score FROM darts) AS actual
59
WHERE (actual.x, actual.y) = (tests.x, tests.y) AND tests.status = 'fail';
610

exercises/practice/difference-of-squares/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for ' || tests.number || ' is ' || actual.result || ', but should be ' || tests.expected
3+
SET message = (
4+
'Result for ' || tests.number
5+
|| ' is <' || COALESCE(actual.result, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
48
FROM (SELECT number, property, result FROM "difference-of-squares") AS actual
59
WHERE (actual.number, actual.property) = (tests.number, tests.property) AND tests.status = 'fail';
610

exercises/practice/eliuds-eggs/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for ' || tests.number || ' is ' || actual.result || ', but should be ' || tests.expected
3+
SET message = (
4+
'Result for ' || tests.number
5+
|| ' is <' || COALESCE(actual.result, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
48
FROM (SELECT number, result FROM "eliuds-eggs") AS actual
59
WHERE actual.number = tests.number AND tests.status = 'fail';
610

exercises/practice/etl/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for ' || actual.input || ' is: ' || actual.result || ', but should be: ' || tests.expected
3+
SET message = (
4+
'Result for ' || tests.input
5+
|| ' is <' || COALESCE(actual.result, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
48
FROM (SELECT input, result FROM etl) AS actual
59
WHERE actual.input = tests.input AND tests.status = 'fail';
610

exercises/practice/gigasecond/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for "' || tests.moment || '" is "' || actual.result || '", but should be "' || tests.result || '"'
3+
SET message = (
4+
'Result for ' || tests.moment
5+
|| ' is <' || COALESCE(actual.result, 'NULL')
6+
|| '> but should be <' || tests.result || '>'
7+
)
48
FROM (SELECT moment, result FROM gigasecond) AS actual
59
WHERE actual.moment = tests.moment AND tests.status = 'fail';
610

exercises/practice/grains/test_reporter.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
-- Update message for failed tests to give helpful information:
22
UPDATE tests
3-
SET message = 'Result for ' || tests.task || ' as ' || tests.square || ' is ' || actual.result || ', but should be ' || tests.expected
3+
SET message = (
4+
'Result for ' || tests.task || ' as ' || tests.square
5+
|| ' is <' || COALESCE(actual.result, 'NULL')
6+
|| '> but should be <' || tests.expected || '>'
7+
)
48
FROM (SELECT task, square, result FROM grains) AS actual
59
WHERE (actual.task, actual.square) = (tests.task, tests.square) AND tests.status = 'fail';
610

0 commit comments

Comments
 (0)