|
| 1 | +#!/usr/bin/env lua5.4 |
| 2 | + |
| 3 | +-- Copyright 2023 Cartesi Pte. Ltd. |
| 4 | +-- |
| 5 | +-- This file is part of the machine-emulator. The machine-emulator is free |
| 6 | +-- software: you can redistribute it and/or modify it under the terms of the GNU |
| 7 | +-- Lesser General Public License as published by the Free Software Foundation, |
| 8 | +-- either version 3 of the License, or (at your option) any later version. |
| 9 | +-- |
| 10 | +-- The machine-emulator is distributed in the hope that it will be useful, but |
| 11 | +-- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | +-- FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License |
| 13 | +-- for more details. |
| 14 | +-- |
| 15 | +-- You should have received a copy of the GNU Lesser General Public License |
| 16 | +-- along with the machine-emulator. If not, see http://www.gnu.org/licenses/. |
| 17 | +-- |
| 18 | + |
| 19 | +local lester = require("spec.util.lester") |
| 20 | +local fs = require("spec.util.fs") |
| 21 | +local cartesi = require("cartesi") |
| 22 | +local describe, it, expect = lester.describe, lester.it, lester.expect |
| 23 | + |
| 24 | +describe("machine clua", function() |
| 25 | + local dummy_machine <close> = cartesi.machine({ |
| 26 | + ram = { length = 0x4000 }, |
| 27 | + rom = { image_filename = fs.rom_image }, |
| 28 | + }) |
| 29 | + |
| 30 | + it("should fail when trying to pass non machine to a a machine API", function() |
| 31 | + local read_mcycle = dummy_machine.read_mcycle |
| 32 | + expect.fail(function() read_mcycle(1) end, "expected cartesi machine object") |
| 33 | + expect.fail(function() read_mcycle(nil) end, "expected cartesi machine object") |
| 34 | + expect.fail(function() read_mcycle() end, "expected cartesi machine object") |
| 35 | + expect.fail(function() read_mcycle({}) end, "expected cartesi machine object") |
| 36 | + expect.fail(function() read_mcycle(setmetatable({}, {})) end, "expected cartesi machine object") |
| 37 | + end) |
| 38 | + |
| 39 | + it("should be able to convert a machine to a string", function() |
| 40 | + local s = tostring(dummy_machine) |
| 41 | + expect.truthy(s) |
| 42 | + expect.equal(s:match("[a-z ]+"), "cartesi machine object") |
| 43 | + end) |
| 44 | +end) |
0 commit comments