[T-004] Add comprehensive test suite for flux-py VM#1
[T-004] Add comprehensive test suite for flux-py VM#1SuperInstance wants to merge 1 commit intomainfrom
Conversation
- 84 tests across 3 test files covering VM core, assembler, disassembler, vocabulary, and interpreter - VM core: basic execution, arithmetic (IADD, IMUL, IDIV, DEC), control flow (JNZ, loops), error handling, register access - Assembler: all 7 opcodes, label resolution (forward/backward), comments, error cases, multi-instruction programs - Disassembler: all opcodes, unknown opcode handling, empty bytecode - Vocabulary: pattern matching, groups extraction, case insensitivity, built-in patterns - Interpreter: all 5 built-in commands (add, mul, factorial, double, square), custom vocabulary, no-match handling - Round-trip tests: assemble→execute, assemble→disassemble
| def test_max_cycles_limit(self): | ||
| """VM should stop after max_cycles even if not halted.""" | ||
| # MOVI R0, 1 — no HALT, so it would loop forever | ||
| bc = movi(0, 1) | ||
| vm = FluxVM(bc, max_cycles=5).execute() | ||
| assert not vm.halted | ||
| assert vm.cycles == 1 # only 1 instruction in bytecode |
There was a problem hiding this comment.
🟡 test_max_cycles_limit doesn't actually test the max_cycles limit
The test claims to verify "VM should stop after max_cycles even if not halted" but the bytecode movi(0, 1) is a single 4-byte instruction. After executing it, PC=4 equals len(bc)=4, so the VM loop exits due to the self.pc < len(self.bc) condition at flux_vm.py:64 — NOT because max_cycles=5 was reached. The self.cycles < self.max_cycles condition is never the limiting factor. If someone removed the max_cycles check from the VM's while loop, this test would still pass, providing a false sense of regression protection for that feature. The test needs bytecode containing a loop (e.g., using JNZ to jump backward) so that the max_cycles limit is actually what terminates execution.
| def test_max_cycles_limit(self): | |
| """VM should stop after max_cycles even if not halted.""" | |
| # MOVI R0, 1 — no HALT, so it would loop forever | |
| bc = movi(0, 1) | |
| vm = FluxVM(bc, max_cycles=5).execute() | |
| assert not vm.halted | |
| assert vm.cycles == 1 # only 1 instruction in bytecode | |
| def test_max_cycles_limit(self): | |
| """VM should stop after max_cycles even if not halted.""" | |
| # Infinite loop: MOVI R0, 1; JNZ R0, -4 (jumps back to JNZ itself) | |
| bc = movi(0, 1) + jnz(0, -4) | |
| vm = FluxVM(bc, max_cycles=5).execute() | |
| assert not vm.halted | |
| assert vm.cycles == 5 |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Test Coverage
VM Core (24 tests)
Assembler & Disassembler (32 tests)
Vocabulary & Interpreter (28 tests)
Testing