cli: bootstrap verified std bytes and math with source imports
This commit is contained in:
52 files changed
+1000
-22
No files matched your search
+18
-1
@@ -442,7 +442,7 @@ fn writeRecord(arena: std.mem.Allocator, module: aji.air.Module, outcome: aji.in
|
||||
try out.writeAll(text[0 .. text.len - 1]);
|
||||
var j: std.json.Stringify = .{ .writer = out };
|
||||
try out.writeAll(",\"source_location\":");
|
||||
try j.write(.{ .file = path, .line = s.start.line, .col = s.start.col });
|
||||
try j.write(.{ .file = s.file orelse path, .line = s.start.line, .col = s.start.col });
|
||||
try out.writeAll("}");
|
||||
}
|
||||
|
||||
@@ -479,3 +479,20 @@ test parseGrant {
|
||||
try std.testing.expect(parseGrant("out=io.write").?.scope == null);
|
||||
try std.testing.expect(parseGrant("io.write") == null);
|
||||
}
|
||||
|
||||
test "standard library trap record identifies the bundled source" {
|
||||
var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
|
||||
defer arena.deinit();
|
||||
const allocator = arena.allocator();
|
||||
const report = try aji.check.checkFile(allocator, "client.aji", "module t\nimport std.math;\nfn main() -> u64\neffects []\n{ return std.math.clamp_u64(5, 9, 4); }\n");
|
||||
try std.testing.expectEqual(aji.check.Status.accepted, report.status);
|
||||
const module = report.module.?;
|
||||
const outcome = try aji.interp.run(allocator, module, "main", .{ .fuel = 10000 });
|
||||
try std.testing.expect(outcome == .trapped);
|
||||
var output: std.Io.Writer.Allocating = .init(allocator);
|
||||
try writeRecord(allocator, module, outcome, null, report, "client.aji", &output.writer);
|
||||
const record = try std.json.parseFromSlice(std.json.Value, allocator, output.written(), .{});
|
||||
const location = record.value.object.get("source_location").?.object;
|
||||
try std.testing.expectEqualStrings("std/math.aji", location.get("file").?.string);
|
||||
try std.testing.expectEqual(@as(i64, 20), location.get("line").?.integer);
|
||||
}
|
||||
Reference in new issue
Block a user