Skip to content

Commit 73962ef

Browse files
committed
Fix tests.
1 parent e2f09d7 commit 73962ef

File tree

13 files changed

+50
-82
lines changed

13 files changed

+50
-82
lines changed

data/toolbox/command.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,9 @@ def parse(self, argument_string):
150150
converted_options[option_name] = option_default
151151

152152
# Validate flags
153+
flag_names = {flag[0] for flag in self.flags}
153154
for flag_name in arguments.flags:
154-
if flag_name not in self.flags:
155+
if flag_name not in flag_names:
155156
raise ValueError(f"Unknown flag: --{flag_name}")
156157

157158
# Return new Arguments with converted options

data/toolbox/context.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import debugger
44
import command
55
import format
6-
import value
6+
import value as rvalue
77
import rexception
88

99

@@ -194,7 +194,7 @@ def print_info(self, terminal):
194194
terminal.print(f" $cfp = <unavailable>")
195195

196196
# Storage info
197-
if storage is not None and not value.is_nil(storage):
197+
if storage is not None and not rvalue.is_nil(storage):
198198
terminal.print(f" Storage: ", end='')
199199
terminal.print_type_tag('VALUE', int(storage), None)
200200
terminal.print()
@@ -330,7 +330,7 @@ def invoke(self, arguments, terminal):
330330
return
331331

332332
# Check if it's nil
333-
if value.is_nil(storage_val):
333+
if rvalue.is_nil(storage_val):
334334
print("Fiber storage: nil")
335335
return
336336

data/toolbox/fiber.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# Import command parser
1313
import command
1414
import constants
15-
import value
15+
import value as rvalue
1616
import format
1717
import heap
1818
import rexception
@@ -162,7 +162,7 @@ def exception(self):
162162
errinfo_val = self.ec['errinfo']
163163

164164
# Only process if it's a real object (not nil or other immediate value)
165-
if value.is_object(errinfo_val) and not value.is_nil(errinfo_val):
165+
if rvalue.is_object(errinfo_val) and not rvalue.is_nil(errinfo_val):
166166
try:
167167
self._exception = rexception.RException(errinfo_val)
168168
except Exception:
@@ -501,8 +501,8 @@ class RubyFiberScanSwitchHandler:
501501
def invoke(self, arguments, terminal):
502502
global _fiber_cache
503503

504-
if not arg or not arg.strip():
505-
self.usage()
504+
if not arguments.expressions or not arguments.expressions[0].strip():
505+
command.print_usage(RubyFiberScanSwitchHandler.USAGE, terminal)
506506
return
507507

508508
# Check if cache is populated
@@ -512,10 +512,10 @@ def invoke(self, arguments, terminal):
512512

513513
# Parse index
514514
try:
515-
index = int(arg.strip())
515+
index = int(arguments.expressions[0].strip())
516516
except ValueError:
517-
print(f"Error: Invalid index '{arg}'. Must be an integer.")
518-
self.usage()
517+
print(f"Error: Invalid index '{arguments.expressions[0]}'. Must be an integer.")
518+
command.print_usage(RubyFiberScanSwitchHandler.USAGE, terminal)
519519
return
520520

521521
# Validate index
@@ -532,7 +532,7 @@ def invoke(self, arguments, terminal):
532532
# Delegate to rb-fiber-switch command
533533
# This command manages the global _current_fiber state
534534
try:
535-
debugger.execute(f"rb-fiber-switch 0x{int(fiber_value):x}", from_tty=from_tty)
535+
RubyFiberSwitchHandler().invoke(command.Arguments([f"0x{int(fiber_value):x}"], {}, []), terminal)
536536
except debugger.Error as e:
537537
print(f"Error switching to fiber: {e}")
538538
import traceback
@@ -758,18 +758,13 @@ def invoke(self, arguments, terminal):
758758
if not is_special:
759759
debugger.set_convenience_variable('errinfo', errinfo_val)
760760

761-
# Create terminal for formatting
762-
terminal = format.create_terminal(from_tty)
763-
764761
# Print switch confirmation
765762
print(f"Switched to Fiber: ", end='')
766763
terminal.print_type_tag('T_DATA', int(fiber_value), None)
767764
print(' → ', end='')
768765
terminal.print_type_tag('struct rb_fiber_struct', fiber_obj.address, None)
769766
print()
770-
print(f" Status: {fiber_obj.status}")
771-
772-
# Print exception if present (catch errors for terminated fibers)
767+
print(f" Status: {fiber_obj.status}") # Print exception if present (catch errors for terminated fibers)
773768
try:
774769
exc_info = fiber_obj.exception_info
775770
if exc_info:
@@ -863,7 +858,7 @@ def invoke(self, arguments, terminal):
863858
print("-" * 80)
864859

865860
# Use stack.print_fiber_backtrace with the fiber pointer
866-
stack.print_fiber_backtrace(fiber_obj.pointer, from_tty=from_tty)
861+
stack.print_fiber_backtrace(fiber_obj.pointer)
867862

868863
except Exception as e:
869864
print(f"\nFiber #{i}: VALUE 0x{int(fiber_value):x}")

data/toolbox/format.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
import sys
9-
import value
9+
import value as rvalue
1010

1111
class Style:
1212
"""Sentinel object representing a style."""
@@ -120,7 +120,7 @@ def __init__(self, output=None):
120120
metadata: self.DIM, # Type tag brackets <>
121121
address: self.MAGENTA, # Memory addresses in type tags
122122
type: self.CYAN, # Type names (T_ARRAY, VALUE, etc.)
123-
value: '',
123+
value_style: '',
124124
string: self.GREEN,
125125
number: self.CYAN,
126126
symbol: self.YELLOW,
@@ -202,5 +202,5 @@ def print_value(self, ruby_value, depth):
202202
value_int = int(ruby_value)
203203
self.debug(f"print_value: value=0x{value_int:x}, depth={depth}")
204204

205-
ruby_object = value.interpret(ruby_value)
205+
ruby_object = rvalue.interpret(ruby_value)
206206
ruby_object.print_recursive(self, depth)

data/toolbox/heap.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import command
44
import constants
5+
import format
56

67
# Constants
78
RBASIC_FLAGS_TYPE_MASK = 0x1f
@@ -550,13 +551,9 @@ def _parse_type(self, type_arg):
550551

551552
return type_value
552553

553-
def invoke(self, arg, from_tty):
554+
def invoke(self, arguments, terminal):
554555
"""Execute the heap scan command."""
555556
try:
556-
# Parse arguments
557-
import command
558-
arguments = command.parse_arguments(arg if arg else "")
559-
560557
# Check if we're continuing from a previous scan
561558
from_option = arguments.get_option('from')
562559
if from_option is not None:
@@ -615,20 +612,14 @@ def invoke(self, arg, from_tty):
615612
print("(You may have reached the end of the heap)")
616613
return
617614

618-
# Import format for terminal output
619-
import format
620-
terminal = format.create_terminal(from_tty)
621-
622-
# Import value module for interpretation
623615
import value as value_module
624616

625617
print(f"Found {len(objects)} object(s):")
626618
print()
627619

628620
for i, obj in enumerate(objects):
629-
obj_int = int(obj)
630-
631621
# Set as convenience variable
622+
obj_int = int(obj)
632623
var_name = f"heap{i}"
633624
debugger.set_convenience_variable(var_name, obj)
634625

data/toolbox/print.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Import utilities
77
import command
88
import constants
9-
import value
9+
import value as rvalue
1010
import rstring
1111
import rarray
1212
import rhash
@@ -31,9 +31,9 @@ class RubyObjectPrinter:
3131
('debug', 'Show internal structure and debug information')
3232
],
3333
examples=[
34-
("rb-inspect $errinfo", "Print exception object"),
35-
("rb-inspect $ec->storage --depth 3", "Print fiber storage with depth 3"),
36-
("rb-inspect $ec->cfp->sp[-1] --debug", "Print top of stack with debug info")
34+
("rb-print $errinfo", "Print exception object"),
35+
("rb-print $ec->storage --depth 3", "Print fiber storage with depth 3"),
36+
("rb-print $ec->cfp->sp[-1] --debug", "Print top of stack with debug info")
3737
]
3838
)
3939

@@ -63,7 +63,7 @@ def invoke(self, arguments, terminal):
6363
ruby_value = debugger.parse_and_eval(expression)
6464

6565
# Interpret the value and let it print itself recursively
66-
ruby_object = value.interpret(ruby_value)
66+
ruby_object = rvalue.interpret(ruby_value)
6767
ruby_object.print_recursive(printer, max_depth)
6868
except debugger.Error as e:
6969
print(f"Error evaluating expression '{expression}': {e}")

data/toolbox/rclass.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import debugger
22
import constants
3-
import value
3+
import value as rvalue
44
import rstring
55

66
class RClass:
@@ -103,9 +103,9 @@ def _get_class_name(self):
103103
except:
104104
classpath_val = None
105105

106-
if classpath_val and int(classpath_val) != 0 and not value.is_nil(classpath_val):
106+
if classpath_val and int(classpath_val) != 0 and not rvalue.is_nil(classpath_val):
107107
# Decode the classpath string
108-
class_name_obj = value.interpret(classpath_val)
108+
class_name_obj = rvalue.interpret(classpath_val)
109109
if hasattr(class_name_obj, 'to_str'):
110110
class_name = class_name_obj.to_str()
111111
if class_name and not class_name.startswith('<'):

data/toolbox/rexception.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import debugger
22
import constants
33
import format
4-
import value
4+
import value as rvalue
55
import rstring
66
import rclass
77

@@ -21,7 +21,7 @@ def __init__(self, exception_value):
2121
self._message = None
2222

2323
# Validate it's an object
24-
if value.is_immediate(exception_value):
24+
if rvalue.is_immediate(exception_value):
2525
raise ValueError("Exception VALUE cannot be an immediate value")
2626

2727
@property
@@ -116,7 +116,7 @@ def is_exception(val):
116116
Returns:
117117
True if the value appears to be an exception object, False otherwise
118118
"""
119-
if not value.is_object(val):
119+
if not rvalue.is_object(val):
120120
return False
121121

122122
try:

data/toolbox/rfloat.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,11 @@ def __str__(self):
5454
return f"<T_FLOAT@0x{addr:x}> {self.float_value()}"
5555

5656
def print_to(self, terminal):
57-
"""Return formatted float representation."""
57+
"""Print formatted float representation."""
5858
addr = int(self.value.address)
59-
tag = terminal.print(
60-
format.metadata, '<',
61-
format.type, 'T_FLOAT',
62-
format.metadata, f'@0x{addr:x}>',
63-
format.reset
64-
)
65-
num_val = terminal.print(format.number, str(self.float_value()), format.reset)
66-
return f"{tag} {num_val}"
59+
terminal.print_type_tag('T_FLOAT', addr)
60+
terminal.print(' ', end='')
61+
terminal.print(format.number, str(self.float_value()), format.reset, end='')
6762

6863
def print_recursive(self, printer, depth):
6964
"""Print this float (no recursion needed)."""

data/toolbox/rstring.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ def print_to(self, terminal):
7272
storage = "embedded" if self._is_embedded() else "heap"
7373
content = self.to_str()
7474
details = f"{storage} length={self.length()}"
75-
tag = terminal.print_type_tag('T_STRING', addr, details)
75+
terminal.print_type_tag('T_STRING', addr, details)
76+
terminal.print(' ', end='')
7677
# Use repr() to properly escape quotes, newlines, etc.
77-
string_val = terminal.print(format.string, repr(content), format.reset)
78-
return f"{tag} {string_val}"
78+
terminal.print(format.string, repr(content), format.reset, end='')
7979

8080
def print_recursive(self, printer, depth):
8181
"""Print this string (no recursion needed for strings)."""

0 commit comments

Comments
 (0)