-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
127 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,94 @@ | ||
require "./spec_helper" | ||
|
||
class Foo | ||
end | ||
|
||
module Bar | ||
end | ||
|
||
enum Baz | ||
One | ||
Two | ||
Three | ||
end | ||
|
||
describe Debug do | ||
# TODO: Write tests | ||
context "with literals" do | ||
it "works with Nil" do | ||
assert_debug nil | ||
end | ||
|
||
it "works with Int" do | ||
assert_debug 1 | ||
assert_debug 1_u64 | ||
end | ||
|
||
it "works with Float" do | ||
assert_debug 1.23 | ||
end | ||
|
||
it "works with Bool" do | ||
assert_debug true | ||
assert_debug false | ||
end | ||
|
||
it "works with Char" do | ||
assert_debug '.' | ||
assert_debug '…' | ||
end | ||
|
||
it "works with String" do | ||
assert_debug "foo" | ||
end | ||
end | ||
|
||
context "with containers" do | ||
it "works with Tuple" do | ||
assert_debug({1, 2, 3}) | ||
end | ||
|
||
it "works with Array" do | ||
assert_debug [1, 2, 3] | ||
end | ||
end | ||
|
||
context "with expressions" do | ||
it do | ||
assert_debug(1 + 2).should eq(3) | ||
assert_debug("foo" + "bar").should eq("foobar") | ||
end | ||
end | ||
|
||
context "with side-effects" do | ||
it do | ||
i = 1 | ||
assert_debug(i += 1) | ||
i.should eq(2) | ||
end | ||
|
||
it do | ||
arr = [:foo] | ||
assert_debug(arr << :bar) | ||
arr.should eq([:foo, :bar]) | ||
end | ||
end | ||
|
||
context "with user defined classes" do | ||
it "works for classes" do | ||
assert_debug Foo | ||
end | ||
|
||
it "works for objects" do | ||
assert_debug Foo.new | ||
end | ||
|
||
it "works for modules" do | ||
assert_debug Bar | ||
end | ||
|
||
it "works" do | ||
false.should eq(true) | ||
it "works for enums" do | ||
assert_debug Baz | ||
assert_debug Baz::One | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,40 @@ | ||
require "spec" | ||
require "../src/debug" | ||
|
||
Debug.configure do |settings| | ||
settings.location_detection = :compile | ||
settings.max_path_length = nil | ||
end | ||
|
||
macro assert_debug(exp, *, file = __FILE__, line = __LINE__) | ||
%ret = nil | ||
|
||
%previous_logger = Debug.logger | ||
begin | ||
IO::Memory.new.tap do |io| | ||
Debug.logger = Debug::Logger.new(io) | ||
Debug.logger.tap do |logger| | ||
%ret = debug!(value = {{ exp }}) | ||
|
||
case value | ||
when Value then %ret.should eq(value) | ||
when Reference then %ret.should be(value) | ||
end | ||
%ret.should be_a(typeof(value)) | ||
|
||
if Debug::ACTIVE && Debug.enabled? | ||
relative_filename = {{ file }}.lchop(Dir.current + "/") | ||
|
||
io.to_s.should contain "#{relative_filename}:{{ line }}" | ||
io.to_s.should contain {{ exp.stringify }} | ||
else | ||
io.to_s.should be_empty | ||
end | ||
end | ||
end | ||
ensure | ||
Debug.logger = %previous_logger | ||
end | ||
|
||
%ret | ||
end |