From 7ecafe66313d7941aaffd3baf1b0c20252c61c01 Mon Sep 17 00:00:00 2001 From: James Harton Date: Thu, 9 Dec 2021 20:10:07 +1300 Subject: [PATCH] chore: fix tests with Elixir 1.13.0. --- config/config.exs | 2 +- test/dll_test.exs | 2 +- test/drivers/circuits_gpio_dispatcher_test.exs | 12 ++++++------ test/drivers/circuits_i2c_test.exs | 5 ++--- test/drivers/elixir_ale_i2c_test.exs | 5 ++--- test/interrupt_registry_test.exs | 1 - test/support/test_utils.exs | 14 ++++++++++---- 7 files changed, 22 insertions(+), 19 deletions(-) diff --git a/config/config.exs b/config/config.exs index e9145ab..b3f9f90 100644 --- a/config/config.exs +++ b/config/config.exs @@ -1,4 +1,4 @@ -use Mix.Config +import Config config :wafer, Wafer.Driver.Fake, warn: Mix.env() != :test diff --git a/test/dll_test.exs b/test/dll_test.exs index 620da31..e61ae10 100644 --- a/test/dll_test.exs +++ b/test/dll_test.exs @@ -12,7 +12,7 @@ defmodule WaferDLLTest do assert Tx.complete?(tx) assert Rx.complete?(rx) - assert {:ok, value} = Rx.value(rx) + assert {:ok, ^value} = Rx.value(rx) end def transmit(%Tx{} = tx, %Rx{} = rx) do diff --git a/test/drivers/circuits_gpio_dispatcher_test.exs b/test/drivers/circuits_gpio_dispatcher_test.exs index 9b41b88..b769b60 100644 --- a/test/drivers/circuits_gpio_dispatcher_test.exs +++ b/test/drivers/circuits_gpio_dispatcher_test.exs @@ -23,7 +23,7 @@ defmodule WaferDriverCircuits.GPIO.DispatcherTest do :ok end) - assert {:reply, {:ok, conn}, _state} = + assert {:reply, {:ok, _conn}, _state} = Dispatcher.handle_call({:enable, conn, :rising}, nil, state()) end @@ -37,7 +37,7 @@ defmodule WaferDriverCircuits.GPIO.DispatcherTest do :ok end) - assert {:reply, {:ok, conn}, _state} = + assert {:reply, {:ok, _conn}, _state} = Dispatcher.handle_call({:enable, conn, :falling}, nil, state()) end @@ -51,7 +51,7 @@ defmodule WaferDriverCircuits.GPIO.DispatcherTest do :ok end) - assert {:reply, {:ok, conn}, _state} = + assert {:reply, {:ok, _conn}, _state} = Dispatcher.handle_call({:enable, conn, :both}, nil, state()) end @@ -63,7 +63,7 @@ defmodule WaferDriverCircuits.GPIO.DispatcherTest do Dispatcher.handle_call({:enable, conn, :rising}, nil, state()) - assert {:reply, {:ok, conn}, _state} = + assert {:reply, {:ok, _conn}, _state} = Dispatcher.handle_call({:disable, conn, :rising}, nil, state()) end @@ -75,7 +75,7 @@ defmodule WaferDriverCircuits.GPIO.DispatcherTest do Dispatcher.handle_call({:enable, conn, :falling}, nil, state()) - assert {:reply, {:ok, conn}, _state} = + assert {:reply, {:ok, _conn}, _state} = Dispatcher.handle_call({:disable, conn, :falling}, nil, state()) end @@ -87,7 +87,7 @@ defmodule WaferDriverCircuits.GPIO.DispatcherTest do Dispatcher.handle_call({:enable, conn, :both}, nil, state()) - assert {:reply, {:ok, conn}, _state} = + assert {:reply, {:ok, _conn}, _state} = Dispatcher.handle_call({:disable, conn, :both}, nil, state()) refute IR.subscribers?({Dispatcher, 1}, :both) diff --git a/test/drivers/circuits_i2c_test.exs b/test/drivers/circuits_i2c_test.exs index 6314637..85dd95e 100644 --- a/test/drivers/circuits_i2c_test.exs +++ b/test/drivers/circuits_i2c_test.exs @@ -23,7 +23,7 @@ defmodule WaferCircuits.I2CTest do [address] end) - assert {:ok, %Subject{} = conn} = Subject.acquire(bus_name: busname, address: address) + assert {:ok, %Subject{}} = Subject.acquire(bus_name: busname, address: address) end test "when the device is not present on the bus" do @@ -59,8 +59,7 @@ defmodule WaferCircuits.I2CTest do [] end) - assert {:ok, %Subject{} = conn} = - Subject.acquire(bus_name: busname, address: address, force: true) + assert {:ok, %Subject{}} = Subject.acquire(bus_name: busname, address: address, force: true) end test "when the bus name is not specified it returns an error" do diff --git a/test/drivers/elixir_ale_i2c_test.exs b/test/drivers/elixir_ale_i2c_test.exs index c56e725..c764904 100644 --- a/test/drivers/elixir_ale_i2c_test.exs +++ b/test/drivers/elixir_ale_i2c_test.exs @@ -24,7 +24,7 @@ defmodule WaferElixirALE.I2CTest do [address] end) - assert {:ok, %Subject{} = conn} = Subject.acquire(bus_name: busname, address: address) + assert {:ok, %Subject{}} = Subject.acquire(bus_name: busname, address: address) end test "when the device is not present on the bus" do @@ -62,8 +62,7 @@ defmodule WaferElixirALE.I2CTest do [] end) - assert {:ok, %Subject{} = conn} = - Subject.acquire(bus_name: busname, address: address, force: true) + assert {:ok, %Subject{}} = Subject.acquire(bus_name: busname, address: address, force: true) end test "when the bus name is not specified it returns an error" do diff --git a/test/interrupt_registry_test.exs b/test/interrupt_registry_test.exs index 38228a5..d997e5d 100644 --- a/test/interrupt_registry_test.exs +++ b/test/interrupt_registry_test.exs @@ -100,7 +100,6 @@ defmodule WaferInterruptRegistryTest do end test "returns false if there are no subscribers for `key` and `pin_condition`" do - receiver = self() :ok = IR.subscribe(:key, :rising, :conn, :metadata) refute IR.subscribers?(:key, :falling) diff --git a/test/support/test_utils.exs b/test/support/test_utils.exs index 6485942..abcf188 100644 --- a/test/support/test_utils.exs +++ b/test/support/test_utils.exs @@ -1,12 +1,18 @@ defmodule TestUtils do @moduledoc false + @chars ~w[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] + def random_module_name do - name = - 16 - |> :crypto.strong_rand_bytes() - |> Base.encode64(padding: false) + name = random_string("", 16) Module.concat(__MODULE__, name) end + + defp random_string(str, 0), do: str + + defp random_string(str, count) do + "#{str}#{Enum.random(@chars)}" + |> random_string(count - 1) + end end