Skip to content

Experiment: Try Motoko Debugger #327

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
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions src/SimpleDebuggerTest.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// Setup motoko debugger:
/// - git clone https://github.com/scalebit/ic-sdk to ~/ic-sdk
/// - cd ~/ic-sdk && cargo build
///
/// Run:
/// moc $(mops sources) -o MoDe.wasm -g src/SimpleDebuggerTest.mo && ~/ic-sdk/target/debug/dfx debug MoDe.wasm
///
/// Commands:
/// bp set -n main
/// run
/// bt
/// list
/// thread step-in Note: wrong line?
/// thread step-over Note: correct line!
/// thread step-over
/// thread step-out
/// local read Output: 1 . list : "HeapAddress: 2133695, tagged: Object, I32"
import List "List";
import Debug "Debug";

func main() {

let list = List.fromArray<Nat>([1, 2, 3]);
List.addAll(list, [4, 5, 6].vals());
Debug.print(debug_show (List.toArray(list)))
};

main()
28 changes: 28 additions & 0 deletions src/SimpleDebuggerTestWithBase.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// Setup motoko debugger:
/// - git clone https://github.com/scalebit/ic-sdk to ~/ic-sdk
/// - cd ~/ic-sdk && cargo build
///
/// Run:
/// moc $(mops sources) -o MoDe.wasm -g src/SimpleDebuggerTestWithBase.mo && ~/ic-sdk/target/debug/dfx debug MoDe.wasm
///
/// Commands:
/// bp set -n main
/// run
/// bt
/// list Output: File not found: "./internals"
/// thread step-in Note: wrong line?
/// thread step-over Output: File not found: "./internals"
/// thread step-over Output: File not found: "./internals"
/// list Output: File not found: "./internals"
import List "List";
import Debug "Debug";
import BaseArray "mo:base/Array";

func main() {
let baseArray = BaseArray.tabulate<Nat>(3, func i = i);
let list = List.fromArray<Nat>(baseArray);
List.addAll(list, [4, 5, 6].vals());
Debug.print(debug_show (List.toArray(list)))
};

main()
59 changes: 59 additions & 0 deletions test/SmallBlob.test.mo
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/// Setup motoko debugger:
/// - git clone https://github.com/scalebit/ic-sdk to ~/ic-sdk
/// - cd ~/ic-sdk && cargo build
///
/// Run:
/// moc $(mops sources) -o MoDe.wasm -g test/SmallBlob.test.mo && ~/ic-sdk/target/debug/dfx debug MoDe.wasm
///
/// Commands:
/// bp set -n breakpoint
/// run
/// bt
/// list Output: File not found: "<moc-asset>/prelude"
/// thread step-in Note: output seems to be wrong, points to a wrong line
/// bt
/// thread step-out
/// list Note: no output?
/// bt
/// thread step-out Output: File not found: "<moc-asset>/prelude"
/// thread step-over Output: File not found: "./internals"
import Blob "../src/Blob";
import { suite; test; expect } "mo:test";
import Debug "../src/Debug";

// placeholder for debugger breakpoint
func breakpoint() {
Debug.print("breakpoint"); // must be non-empty otherwise the debugger seems to skip it
};

suite(
"basic operations",
func() {
test(
"empty creates an empty blob",
func() {
let emptyBlob = Blob.empty();
breakpoint();
expect.nat(emptyBlob.size()).equal(0)
}
);

test(
"isEmpty identifies empty blobs",
func() {
breakpoint();
expect.bool(Blob.isEmpty(Blob.empty())).equal(true);
expect.bool(Blob.isEmpty("\FF\00" : Blob)).equal(false)
}
);

test(
"size returns correct byte count",
func() {
breakpoint();
expect.nat(Blob.size("\FF\00\AA" : Blob)).equal(3);
expect.nat(Blob.size(Blob.empty())).equal(0)
}
)
}
)
Loading