Rename some test helpers
parent
779c450545
commit
1c00c543e3
|
@ -9,32 +9,46 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
end
|
||||
|
||||
test "point", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim, %{x: 100, y: 200, z: 300})
|
||||
:ok = simulate_syscall(shim, %{x: 100, y: 200, z: 300})
|
||||
|
||||
assert %{x: 100, y: 200, z: 300} =
|
||||
SysCalls.point(TestSysCalls, "Peripheral", 1)
|
||||
|
||||
assert_receive {:point, ["Peripheral", 1]}
|
||||
|
||||
:ok = shim_fun_error(shim, "point error")
|
||||
:ok = simulate_syscall_error(shim, "point error")
|
||||
|
||||
assert {:error, "point error"} ==
|
||||
SysCalls.point(TestSysCalls, "Peripheral", 1)
|
||||
end
|
||||
|
||||
test "point groups", %{shim: shim} do
|
||||
:ok = simulate_syscall(shim, %{x: 100, y: 200, z: 300})
|
||||
|
||||
assert %{x: 100, y: 200, z: 300} =
|
||||
SysCalls.point(TestSysCalls, "Peripheral", 1)
|
||||
|
||||
assert_receive {:point, ["Peripheral", 1]}
|
||||
|
||||
:ok = simulate_syscall_error(shim, "point error")
|
||||
|
||||
assert {:error, "point error"} ==
|
||||
SysCalls.point(TestSysCalls, "Peripheral", 1)
|
||||
end
|
||||
|
||||
test "move_absolute", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim)
|
||||
:ok = simulate_syscall(shim)
|
||||
assert :ok = SysCalls.move_absolute(TestSysCalls, 1, 2, 3, 4)
|
||||
assert_receive {:move_absolute, [1, 2, 3, 4]}
|
||||
|
||||
:ok = shim_fun_error(shim, "move failed!")
|
||||
:ok = simulate_syscall_error(shim, "move failed!")
|
||||
|
||||
assert {:error, "move failed!"} ==
|
||||
SysCalls.move_absolute(TestSysCalls, 1, 2, 3, 4)
|
||||
end
|
||||
|
||||
test "get current positions", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim, 100.00)
|
||||
:ok = simulate_syscall(shim, 100.00)
|
||||
assert 100.00 = SysCalls.get_current_x(TestSysCalls)
|
||||
assert 100.00 = SysCalls.get_current_y(TestSysCalls)
|
||||
assert 100.00 = SysCalls.get_current_z(TestSysCalls)
|
||||
|
@ -43,7 +57,7 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
assert_receive {:get_current_y, []}
|
||||
assert_receive {:get_current_z, []}
|
||||
|
||||
:ok = shim_fun_error(shim, "firmware error")
|
||||
:ok = simulate_syscall_error(shim, "firmware error")
|
||||
|
||||
assert {:error, "firmware error"} == SysCalls.get_current_x(TestSysCalls)
|
||||
assert {:error, "firmware error"} == SysCalls.get_current_y(TestSysCalls)
|
||||
|
@ -51,7 +65,7 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
end
|
||||
|
||||
test "write_pin", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim)
|
||||
:ok = simulate_syscall(shim)
|
||||
assert :ok = SysCalls.write_pin(TestSysCalls, 1, 0, 1)
|
||||
|
||||
assert :ok =
|
||||
|
@ -64,43 +78,43 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
assert_receive {:write_pin, [%{type: "boxled", id: 4}, 0, 1]}
|
||||
assert_receive {:write_pin, [%{type: "boxled", id: 3}, 1, 123]}
|
||||
|
||||
:ok = shim_fun_error(shim, "firmware error")
|
||||
:ok = simulate_syscall_error(shim, "firmware error")
|
||||
|
||||
assert {:error, "firmware error"} ==
|
||||
SysCalls.write_pin(TestSysCalls, 1, 0, 1)
|
||||
end
|
||||
|
||||
test "read_pin", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim, 1)
|
||||
:ok = simulate_syscall(shim, 1)
|
||||
assert 1 == SysCalls.read_pin(TestSysCalls, 10, 0)
|
||||
assert 1 == SysCalls.read_pin(TestSysCalls, 77, nil)
|
||||
assert_receive {:read_pin, [10, 0]}
|
||||
assert_receive {:read_pin, [77, nil]}
|
||||
|
||||
:ok = shim_fun_error(shim, "firmware error")
|
||||
:ok = simulate_syscall_error(shim, "firmware error")
|
||||
|
||||
assert {:error, "firmware error"} == SysCalls.read_pin(TestSysCalls, 1, 0)
|
||||
end
|
||||
|
||||
test "wait", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim)
|
||||
:ok = simulate_syscall(shim)
|
||||
assert :ok = SysCalls.wait(TestSysCalls, 1000)
|
||||
assert_receive {:wait, [1000]}
|
||||
end
|
||||
|
||||
test "named_pin", %{shim: shim} do
|
||||
# Peripheral and Sensor are on the Arduino
|
||||
:ok = shim_fun_ok(shim, 44)
|
||||
:ok = simulate_syscall(shim, 44)
|
||||
assert 44 == SysCalls.named_pin(TestSysCalls, "Peripheral", 5)
|
||||
assert 44 == SysCalls.named_pin(TestSysCalls, "Sensor", 1999)
|
||||
|
||||
# BoxLed is on the GPIO
|
||||
:ok = shim_fun_ok(shim, %{type: "BoxLed", id: 3})
|
||||
:ok = simulate_syscall(shim, %{type: "BoxLed", id: 3})
|
||||
|
||||
assert %{type: "BoxLed", id: 3} ==
|
||||
SysCalls.named_pin(TestSysCalls, "BoxLed", 3)
|
||||
|
||||
:ok = shim_fun_ok(shim, %{type: "BoxLed", id: 4})
|
||||
:ok = simulate_syscall(shim, %{type: "BoxLed", id: 4})
|
||||
|
||||
assert %{type: "BoxLed", id: 4} ==
|
||||
SysCalls.named_pin(TestSysCalls, "BoxLed", 4)
|
||||
|
@ -110,14 +124,14 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
assert_receive {:named_pin, ["BoxLed", 3]}
|
||||
assert_receive {:named_pin, ["BoxLed", 4]}
|
||||
|
||||
:ok = shim_fun_error(shim, "error finding resource")
|
||||
:ok = simulate_syscall_error(shim, "error finding resource")
|
||||
|
||||
assert {:error, "error finding resource"} ==
|
||||
SysCalls.named_pin(TestSysCalls, "Peripheral", 888)
|
||||
end
|
||||
|
||||
test "send_message", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim)
|
||||
:ok = simulate_syscall(shim)
|
||||
|
||||
assert :ok =
|
||||
SysCalls.send_message(TestSysCalls, "success", "hello world", [
|
||||
|
@ -126,7 +140,7 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
|
||||
assert_receive {:send_message, ["success", "hello world", ["email"]]}
|
||||
|
||||
:ok = shim_fun_error(shim, "email machine broke")
|
||||
:ok = simulate_syscall_error(shim, "email machine broke")
|
||||
|
||||
assert {:error, "email machine broke"} ==
|
||||
SysCalls.send_message(TestSysCalls, "error", "goodbye world", [
|
||||
|
@ -135,34 +149,34 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
end
|
||||
|
||||
test "find_home", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim)
|
||||
:ok = simulate_syscall(shim)
|
||||
assert :ok = SysCalls.find_home(TestSysCalls, "x")
|
||||
assert_receive {:find_home, ["x"]}
|
||||
|
||||
:ok = shim_fun_error(shim, "home lost")
|
||||
:ok = simulate_syscall_error(shim, "home lost")
|
||||
|
||||
assert {:error, "home lost"} == SysCalls.find_home(TestSysCalls, "x")
|
||||
end
|
||||
|
||||
test "execute_script", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim)
|
||||
:ok = simulate_syscall(shim)
|
||||
assert :ok = SysCalls.execute_script(TestSysCalls, "take-photo", %{})
|
||||
assert_receive {:execute_script, ["take-photo", %{}]}
|
||||
|
||||
:ok = shim_fun_error(shim, "not installed")
|
||||
:ok = simulate_syscall_error(shim, "not installed")
|
||||
|
||||
assert {:error, "not installed"} ==
|
||||
SysCalls.execute_script(TestSysCalls, "take-photo", %{})
|
||||
end
|
||||
|
||||
test "set_servo_angle errors", %{shim: shim} do
|
||||
:ok = shim_fun_ok(shim)
|
||||
:ok = simulate_syscall(shim)
|
||||
arg0 = [5, 40]
|
||||
assert :ok = SysCalls.set_servo_angle(TestSysCalls, "set_servo_angle", arg0)
|
||||
assert_receive {:set_servo_angle, arg0}
|
||||
|
||||
arg1 = [40, -5]
|
||||
:ok = shim_fun_error(shim, "boom")
|
||||
:ok = simulate_syscall_error(shim, "boom")
|
||||
|
||||
assert {:error, "boom"} ==
|
||||
SysCalls.set_servo_angle(TestSysCalls, "set_servo_angle", arg1)
|
||||
|
@ -170,7 +184,7 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
|
||||
test "get_sequence", %{shim: shim} do
|
||||
:ok =
|
||||
shim_fun_ok(shim, %AST{
|
||||
simulate_syscall(shim, %AST{
|
||||
kind: :sequence,
|
||||
args: %{locals: %AST{kind: :scope_declaration, args: %{}}}
|
||||
})
|
||||
|
@ -178,13 +192,13 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
assert %{} = SysCalls.get_sequence(TestSysCalls, 123)
|
||||
assert_receive {:get_sequence, [123]}
|
||||
|
||||
:ok = shim_fun_error(shim, "sequence not found")
|
||||
:ok = simulate_syscall_error(shim, "sequence not found")
|
||||
|
||||
assert {:error, "sequence not found"} ==
|
||||
SysCalls.get_sequence(TestSysCalls, 123)
|
||||
end
|
||||
|
||||
def shim_fun_ok(shim, val \\ :ok) do
|
||||
def simulate_syscall(shim, val \\ :ok) do
|
||||
pid = self()
|
||||
|
||||
:ok =
|
||||
|
@ -194,7 +208,7 @@ defmodule FarmbotCeleryScript.SysCallsTest do
|
|||
end)
|
||||
end
|
||||
|
||||
def shim_fun_error(shim, val) when is_binary(val) do
|
||||
def simulate_syscall_error(shim, val) when is_binary(val) do
|
||||
:ok =
|
||||
TestSysCalls.handle(shim, fn _kind, _args ->
|
||||
{:error, val}
|
||||
|
|
Loading…
Reference in New Issue