Reorganise and test std::debug

std::debug now has tests, and the `file` argument and getter method have
been renamed to `path`.
parent fc2f7977
Pipeline #41338724 passed with stages
in 18 minutes and 47 seconds
......@@ -8,15 +8,15 @@ import std::string_buffer::StringBuffer
## Details of a single call frame in a call stack.
object CallFrame {
def init(file: ToPath, name: String, line: Integer) {
let @file = file.to_path
def init(path: ToPath, name: String, line: Integer) {
let @path = path.to_path
let @name = name
let @line = line
}
## Returns the path of the file the frame belongs to.
def file -> Path {
@file
def path -> Path {
@path
}
## Returns the name of the block of code the frame belongs to.
......@@ -34,7 +34,7 @@ impl ToString for CallFrame {
## Formats the CallFrame as a String
def to_string -> String {
let buffer = StringBuffer.new([
@file.to_string.inspect,
@path.to_string.inspect,
', line ',
@line.to_string,
', in ',
......@@ -86,7 +86,7 @@ def stacktrace(skip = 1, limit: ?Integer = Nil) -> Array!(CallFrame) {
raw_frames.each do (raw_frame) {
frames.push(
CallFrame.new(
file: (raw_frame[0] as String).to_path,
path: (raw_frame[0] as String).to_path,
name: raw_frame[1] as String,
line: raw_frame[2] as Integer,
),
......@@ -119,7 +119,7 @@ def last_call_frame_in(file: ToPath) -> CallFrame {
{ index >= 0 }.while_true {
let frame = *frames[index]
frame.file == path
frame.path == path
.if_true {
return frame
}
......
......@@ -87,7 +87,7 @@ object ProgressFormatter impl Formatter {
let location = failure.location
StringBuffer
.new([location.file.to_string, ':', location.line.to_string])
.new([location.path.to_string, ':', location.line.to_string])
.to_string
}
......
......@@ -73,7 +73,7 @@ object Test {
process.panicking do (error) {
@failure = TestFailure.new(
message: error,
location: debug.last_call_frame_in(location.file),
location: debug.last_call_frame_in(location.path),
)
notify_runner
......
......@@ -67,12 +67,12 @@ panicking lambda (error) {
debug.stacktrace(skip: 2).each_with_index do (frame, index) {
# If the frame originates from this particular module, we ignore it. This
# way we ignore any frames produced by this handler itself.
frame.file == module_path
frame.path == module_path
.if_false {
output.push("\n ")
output.push(index.to_string)
output.push(': ')
output.push(frame.file.to_string.inspect)
output.push(frame.path.to_string.inspect)
output.push(', line ')
output.push(frame.line.to_string)
output.push(', in ')
......
......@@ -21,6 +21,7 @@ import test::std::test_array_iter
import test::std::test_block
import test::std::test_boolean
import test::std::test_byte_array
import test::std::test_debug
import test::std::test_env
import test::std::test_error
import test::std::test_ffi
......
......@@ -4,7 +4,7 @@ import std::test::assert
import std::test::error::TestFailure
def test_failure -> TestFailure {
let frame = CallFrame.new(file: 'test.inko', name: 'test', line: 1)
let frame = CallFrame.new(path: 'test.inko', name: 'test', line: 1)
TestFailure.new(message: 'oops', location: frame)
}
......@@ -13,7 +13,7 @@ test.group('std::test::error::TestFailure.location') do (g) {
g.test('Obtaining the CallFrame of a TestFailure') {
let failure = test_failure
assert.equal(failure.location.file.to_string, 'test.inko')
assert.equal(failure.location.path.to_string, 'test.inko')
assert.equal(failure.location.name, 'test')
assert.equal(failure.location.line, 1)
}
......
......@@ -9,7 +9,7 @@ import std::test::test::Test
import std::time::duration
def example_test -> Test {
let frame = CallFrame.new(file: 'test.inko', name: 'test', line: 1)
let frame = CallFrame.new(path: 'test.inko', name: 'test', line: 1)
let test = Test.new(
name: 'test name',
group_name: 'group name',
......@@ -30,7 +30,7 @@ test.group('std::test::formatters::ProgressFormatter.failure_title') do (g) {
test.group('std::test::formatters::ProgressFormatter.failure_location') do (g) {
g.test('Generating the failure location description for a failed test') {
let fmt = ProgressFormatter.new
let frame = CallFrame.new(file: 'test.inko', name: 'test', line: 1)
let frame = CallFrame.new(path: 'test.inko', name: 'test', line: 1)
let failure = TestFailure.new(message: 'oops', location: frame)
assert.equal(fmt.failure_location(failure), 'test.inko:1')
......
......@@ -12,7 +12,7 @@ import std::test::test::Test
import std::time::duration
def example_test -> Test {
let frame = CallFrame.new(file: 'test.inko', name: 'test', line: 1)
let frame = CallFrame.new(path: 'test.inko', name: 'test', line: 1)
Test.new(
name: 'test name',
......
......@@ -5,7 +5,7 @@ import std::test::assert
import std::test::test::Test
def example_test -> Test {
let frame = CallFrame.new(file: 'test.inko', name: 'test', line: 1)
let frame = CallFrame.new(path: 'test.inko', name: 'test', line: 1)
Test.new(
name: 'test name',
......@@ -42,7 +42,7 @@ test.group('std::test::test::Test.location') do (g) {
g.test('Obtaining the CallFrame of a test') {
let location = example_test.location
assert.equal(location.file.to_string, 'test.inko')
assert.equal(location.path.to_string, 'test.inko')
assert.equal(location.name, 'test')
assert.equal(location.line, 1)
}
......
......@@ -35,7 +35,7 @@ test.group('std::test::test_group::TestGroup.test') do (g) {
let mod_mirror = mirror.reflect_module(ThisModule)
let test = add_test
assert.equal(test.location.file, mod_mirror.path)
assert.equal(test.location.path, mod_mirror.path)
assert.equal(test.location.line, 14)
}
}
import std::debug::(self, CallFrame)
import std::mirror
import std::test
import std::test::assert
test.group('std::debug::CallFrame.path') do (g) {
g.test('Obtaining the file path of a CallFrame') {
let frame = CallFrame.new(path: 'foo.inko', name: 'foo', line: 1)
assert.equal(frame.path.to_string, 'foo.inko')
}
}
test.group('std::debug::CallFrame.name') do (g) {
g.test('Obtaining the name of a CallFrame') {
let frame = CallFrame.new(path: 'foo.inko', name: 'foo', line: 1)
assert.equal(frame.name, 'foo')
}
}
test.group('std::debug::CallFrame.line') do (g) {
g.test('Obtaining the line number of a CallFrame') {
let frame = CallFrame.new(path: 'foo.inko', name: 'foo', line: 1)
assert.equal(frame.line, 1)
}
}
test.group('std::debug::CallFrame.to_string') do (g) {
g.test('Converting a CallFrame to a String') {
let frame = CallFrame.new(path: 'foo.inko', name: 'foo', line: 1)
assert.equal(frame.to_string, '"foo.inko", line 1, in "foo"')
}
}
test.group('std::debug.stacktrace') do (g) {
g.test('Obtaining a stacktrace to the caller') {
let trace = debug.stacktrace
let mirror = mirror.reflect_module(ThisModule)
let last = *trace[-1]
assert.true(trace.length > 0)
assert.equal(last.name, '<block>')
assert.equal(last.line, 40)
assert.equal(last.path, mirror.path)
}
g.test('Limiting the number of call frames in a stacktrace') {
let trace = debug.stacktrace(limit: 1)
assert.equal(trace.length, 1)
}
g.test('Skipping a number of call frames in a stacktrace') {
let trace = debug.stacktrace(skip: 2)
let mirror = mirror.reflect_module(ThisModule)
assert.true(trace.length > 0)
assert.not_equal(trace[-1].path, mirror.path)
}
}
test.group('std::debug.last_call_frame_in') do (g) {
g.test('Obtaining the last call frame of a file') {
let mirror = mirror.reflect_module(ThisModule)
let frame = debug.last_call_frame_in(mirror.path)
assert.equal(frame.name, '<block>')
assert.equal(frame.path, mirror.path)
assert.equal(frame.line, 68)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment