Skip to content

Add debug and p tests #154

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions bin/run-tests.sh
Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@ for test_dir in tests/*; do
# -e "s~${test_dir_path}~/solution~g" \
# "${results_file_path}"

echo "${test_dir_name}: comparing results.json to expected_results.json"
diff "${results_file_path}" "${expected_results_file_path}"
echo "${test_dir_name}: comparing expected_results.json to results.json"
diff "${expected_results_file_path}" "${results_file_path}"

if [ $? -ne 0 ]; then
exit_code=1
4 changes: 4 additions & 0 deletions lib/ext/kernel.rb
Original file line number Diff line number Diff line change
@@ -2,4 +2,8 @@ module Kernel
def debug(*args)
Minitest::ExercismReporter.instance.record_output(*args)
end

def p(*args)
Minitest::ExercismReporter.instance.record_output(*args)
end
end
13 changes: 13 additions & 0 deletions test/extract_metadata_test.rb
Original file line number Diff line number Diff line change
@@ -38,6 +38,19 @@ def test_no_skip_comments
assert_equal expected, actual
end

def test_debug
expected = [{
test: "test_debug_works_properly",
name: "Debug works properly",
test_code: 'debug "Hello!"',
index: 0
}]

actual = TestRunner::ExtractMetadata.(File.expand_path("fixtures/metadata/debug.rb", __dir__))
assert_equal expected, actual
end


def test_extracting_indices
expected = [
{
5 changes: 5 additions & 0 deletions test/fixtures/metadata/debug.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SomeTest < Minitest::Test
def test_debug_works_properly
debug "Hello!"
end
end
5 changes: 5 additions & 0 deletions tests/metadata/debug_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class SomeTest < Minitest::Test
def test_debug_works_properly
debug "Hello!"
end
end
2 changes: 1 addition & 1 deletion tests/metadata/expected_results.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":2,"status":"fail","message":null,"tests":[{"name":"Assert equal works properly","test_code":"some_result = TwoFer.two_fer\nassert_equal \"One for you, one for me.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 3:in `test_assert_equal_works_properly'"},{"name":"Skip works properly","test_code":"something = \"Something\"\nassert something.present?","status":"error","message":"NoMethodError: undefined method `present?' for an instance of String\n\nTraceback (most recent call first):\n Line 5:in `test_skip_works_properly'"},{"name":"Zebra","test_code":"some_result = TwoFer.two_fer(\"zebra\")\nassert_equal \"One for you, one for zebra.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 3:in `test_zebra'"},{"name":"Anaconda","test_code":"some_result = TwoFer.two_fer(\"anaconda\")\nassert_equal \"One for you, one for anaconda.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 8:in `test_anaconda'"},{"name":"Gorilla","test_code":"some_result = TwoFer.two_fer(\"gorilla\")\nassert_equal \"One for you, one for gorilla.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 13:in `test_gorilla'"},{"name":"Boa","test_code":"some_result = TwoFer.two_fer(\"boa\")\nassert_equal \"One for you, one for boa.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 18:in `test_boa'"}]}
{"version":2,"status":"fail","message":null,"tests":[{"name":"Assert equal works properly","test_code":"some_result = TwoFer.two_fer\nassert_equal \"One for you, one for me.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 3:in `test_assert_equal_works_properly'"},{"name":"Debug works properly","test_code":"debug \"Hello!\"","status":"pass","output":"Hello!\n"},{"name":"P works properly","test_code":"p \"Hello!\"","status":"pass","output":"Hello!\n"},{"name":"Skip works properly","test_code":"something = \"Something\"\nassert something.present?","status":"error","message":"NoMethodError: undefined method `present?' for an instance of String\n\nTraceback (most recent call first):\n Line 5:in `test_skip_works_properly'"},{"name":"Zebra","test_code":"some_result = TwoFer.two_fer(\"zebra\")\nassert_equal \"One for you, one for zebra.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 3:in `test_zebra'"},{"name":"Anaconda","test_code":"some_result = TwoFer.two_fer(\"anaconda\")\nassert_equal \"One for you, one for anaconda.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 8:in `test_anaconda'"},{"name":"Gorilla","test_code":"some_result = TwoFer.two_fer(\"gorilla\")\nassert_equal \"One for you, one for gorilla.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 13:in `test_gorilla'"},{"name":"Boa","test_code":"some_result = TwoFer.two_fer(\"boa\")\nassert_equal \"One for you, one for boa.\", some_result","status":"error","message":"NameError: uninitialized constant SomeTest::TwoFer\n\nTraceback (most recent call first):\n Line 18:in `test_boa'"}]}
6 changes: 6 additions & 0 deletions tests/metadata/p_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class SomeTest < Minitest::Test
def test_p_works_properly
p "Hello!"
end
end