35
.github/workflows/elixir.yml
vendored
Normal file
35
.github/workflows/elixir.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
name: Elixir CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
name: Build and test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: System dependencies
|
||||
run: |
|
||||
sudo apt update
|
||||
sudo apt install -y inotify-tools
|
||||
- name: Set up Elixir
|
||||
uses: erlef/setup-beam@988e02bfe678367a02564f65ca2e37726dc0268f
|
||||
with:
|
||||
elixir-version: '1.12.3' # Define the elixir version [required]
|
||||
otp-version: '24.1' # Define the OTP version [required]
|
||||
- name: Restore dependencies cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: deps
|
||||
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
|
||||
restore-keys: ${{ runner.os }}-mix-
|
||||
- name: Install dependencies
|
||||
run: mix deps.get
|
||||
- name: Run tests
|
||||
run: mix test
|
||||
@@ -14,31 +14,31 @@ defmodule Agents do
|
||||
end
|
||||
|
||||
koan "Update to update the state" do
|
||||
Agent.start_link(fn -> "Hi there" end, name: __MODULE__)
|
||||
Agent.start_link(fn -> "Hi there" end, name: :greeter)
|
||||
|
||||
Agent.update(__MODULE__, fn old ->
|
||||
Agent.update(:greeter, fn old ->
|
||||
String.upcase(old)
|
||||
end)
|
||||
|
||||
assert Agent.get(__MODULE__, & &1) == ___
|
||||
assert Agent.get(:greeter, & &1) == ___
|
||||
end
|
||||
|
||||
koan "Use get_and_update when you need to read and change a value in one go" do
|
||||
Agent.start_link(fn -> ["Milk"] end, name: __MODULE__)
|
||||
Agent.start_link(fn -> ["Milk"] end, name: :groceries)
|
||||
|
||||
old_list =
|
||||
Agent.get_and_update(__MODULE__, fn old ->
|
||||
Agent.get_and_update(:groceries, fn old ->
|
||||
{old, ["Bread" | old]}
|
||||
end)
|
||||
|
||||
assert old_list == ___
|
||||
assert Agent.get(__MODULE__, & &1) == ___
|
||||
assert Agent.get(:groceries, & &1) == ___
|
||||
end
|
||||
|
||||
koan "Somebody has to switch off the light at the end of the day" do
|
||||
{:ok, pid} = Agent.start_link(fn -> ["Milk"] end, name: __MODULE__)
|
||||
{:ok, pid} = Agent.start_link(fn -> "Fin." end, name: :stoppable)
|
||||
|
||||
Agent.stop(__MODULE__)
|
||||
Agent.stop(:stoppable)
|
||||
|
||||
assert Process.alive?(pid) == ___
|
||||
end
|
||||
|
||||
@@ -12,9 +12,13 @@ defmodule GenServers do
|
||||
{:ok, args}
|
||||
end
|
||||
|
||||
def start_link(init_password) do
|
||||
def start(init_password) do
|
||||
# The __MODULE__ macro returns the current module name as an atom
|
||||
GenServer.start_link(__MODULE__, init_password, name: __MODULE__)
|
||||
GenServer.start(__MODULE__, init_password, name: __MODULE__)
|
||||
end
|
||||
|
||||
def stop do
|
||||
GenServer.stop(__MODULE__)
|
||||
end
|
||||
|
||||
def unlock(password) do
|
||||
@@ -134,20 +138,24 @@ defmodule GenServers do
|
||||
end
|
||||
|
||||
koan "Our server works but it's pretty ugly to use; so lets use a cleaner interface" do
|
||||
Laptop.start_link("EL!73")
|
||||
Laptop.start("EL!73")
|
||||
assert Laptop.unlock("EL!73") == ___
|
||||
end
|
||||
|
||||
koan "Let's use the remaining functions in the external API" do
|
||||
Laptop.start_link("EL!73")
|
||||
Laptop.start("EL!73")
|
||||
|
||||
{_, response} = Laptop.unlock("EL!73")
|
||||
assert response == ___
|
||||
|
||||
Laptop.change_password("EL!73", "Elixir")
|
||||
|
||||
{_, response} = Laptop.unlock("EL!73")
|
||||
assert response == ___
|
||||
|
||||
{_, response} = Laptop.owner_name()
|
||||
assert response == ___
|
||||
|
||||
:ok = Laptop.stop()
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,7 +4,6 @@ defmodule MapSetsTest do
|
||||
|
||||
test "MapSets" do
|
||||
answers = [
|
||||
1,
|
||||
3,
|
||||
{:multiple, [false, true]},
|
||||
true,
|
||||
|
||||
@@ -4,8 +4,8 @@ defmodule ProtocolsTests do
|
||||
|
||||
test "Protocols" do
|
||||
answers = [
|
||||
{:multiple, ["Andre signed up for violin", "Darcy enrolled for ballet"]},
|
||||
"Pupil enrolled at school",
|
||||
{:multiple, ["Andre played violin", "Darcy performed ballet"]},
|
||||
"Artist showed performance",
|
||||
Protocol.UndefinedError
|
||||
]
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
ExUnit.start()
|
||||
timeout = 1000 # ms
|
||||
ExUnit.start(timeout: timeout)
|
||||
|
||||
defmodule TestHarness do
|
||||
import ExUnit.Assertions
|
||||
|
||||
Reference in New Issue
Block a user