Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code coverage #154

Merged
merged 8 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 42 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
runs-on: ubuntu-20.04
env:
MIX_ENV: test
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

strategy:
fail-fast: false
matrix:
Expand All @@ -22,34 +24,59 @@ jobs:
elixir: "1.16"
otp: "26.2"
lint: lint
coverage: coverage
steps:
- uses: actions/checkout@v4
- name: Check out this repository
uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
- name: Set up Erlang and Elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{matrix.pair.otp}}
elixir-version: ${{matrix.pair.elixir}}
otp-version: ${{ matrix.pair.otp }}
elixir-version: ${{ matrix.pair.elixir }}

- uses: actions/cache@v4
- name: Restored cached Mix dependencies (downloaded and compiled)
uses: actions/cache/restore@v4
id: restore-mix-deps-cache
with:
path: |
deps
_build
key: ${{ runner.os }}-mix-${{matrix.pair.elixir}}-${{matrix.pair.otp}}-${{ hashFiles('**/mix.lock') }}
restore-keys: |
${{ runner.os }}-mix-
key: |
${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-${{ hashFiles('**/mix.lock') }}-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-${{ hashFiles('**/mix.lock') }}-
${{ runner.os }}-mix-${{ matrix.pair.elixir }}-${{ matrix.pair.otp }}-

- run: mix deps.get --check-locked
- name: Fetch and compile Mix dependencies
run: mix do deps.get --check-locked, deps.compile

- run: mix format --check-formatted
if: ${{ matrix.lint }}
- name: Cache compiled Mix dependencies
uses: actions/cache/save@v4
with:
path: |
deps
_build
key: ${{ steps.restore-mix-deps-cache.outputs.cache-primary-key }}

- run: mix deps.unlock --check-unused
- name: Check for formatted files
run: mix format --check-formatted
if: ${{ matrix.lint }}

- run: mix deps.compile
- name: Check for unused dependencies
run: mix deps.unlock --check-unused
if: ${{ matrix.lint }}

- run: mix compile --warnings-as-errors
- name: Check compilation warnings
run: mix compile --warnings-as-errors
if: ${{ matrix.lint }}

- run: mix test
# We always need to run tests because code coverage forces us to skip some
# tests, so better to run normal tests on the whole matrix and the coverage
# only on the latest version.
- name: Run tests
run: mix test

- name: Run tests with coverage
if: ${{ matrix.coverage }}
run: mix coveralls.github --exclude fails_on_coverage
15 changes: 12 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ defmodule Mox.MixProject do
description: "Mocks and explicit contracts for Elixir",
deps: deps(),
docs: docs(),
package: package()
package: package(),
test_coverage: [tool: ExCoveralls],
preferred_cli_env: [
coveralls: :test,
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test
]
]
end

Expand All @@ -30,8 +37,10 @@ defmodule Mox.MixProject do

defp deps do
[
{:nimble_ownership, "~> 0.3.0"},
{:ex_doc, "~> 0.16", only: :docs}
{:nimble_ownership, "~> 0.3"},
{:castore, "~> 1.0", only: :test},
{:ex_doc, "~> 0.16", only: :docs},
{:excoveralls, "~> 0.18", only: :test}
]
end

Expand Down
5 changes: 4 additions & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
%{
"castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"},
"earmark_parser": {:hex, :earmark_parser, "1.4.26", "f4291134583f373c7d8755566122908eb9662df4c4b63caa66a0eabe06569b0a", [:mix], [], "hexpm", "48d460899f8a0c52c5470676611c01f64f3337bad0b26ddab43648428d94aabc"},
"ex_doc": {:hex, :ex_doc, "0.28.5", "3e52a6d2130ce74d096859e477b97080c156d0926701c13870a4e1f752363279", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "d2c4b07133113e9aa3e9ba27efb9088ba900e9e51caa383919676afdf09ab181"},
"excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.0", "f8c570a0d33f8039513fbccaf7108c5d750f47d8defd44088371191b76492b0b", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "28b2cbdc13960a46ae9a8858c4bebdec3c9a6d7b4b9e7f4ed1502f8159f338e7"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_ownership": {:hex, :nimble_ownership, "0.3.0", "29514f8779b26f50f9c07109677c98c0cc0b8025e89f82964dafa9cf7d657ec0", [:mix], [], "hexpm", "76c605106bc1e60f5b028b20203a1e0c90b4350b08e4b8a33f68bb50dcb6e837"},
"nimble_ownership": {:hex, :nimble_ownership, "0.3.1", "99d5244672fafdfac89bfad3d3ab8f0d367603ce1dc4855f86a1c75008bce56f", [:mix], [], "hexpm", "4bf510adedff0449a1d6e200e43e57a814794c8b5b6439071274d248d272a549"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.3", "244836e6e3f1200c7f30cb56733fd808744eca61fd182f731eac4af635cc6d0b", [:mix], [], "hexpm", "c8d789e39b9131acf7b99291e93dae60ab48ef14a7ee9d58c6964f59efb570b0"},
}
3 changes: 3 additions & 0 deletions test/cluster_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ if otp_release >= 25 do
use ExUnit.Case
import Mox

# These tests don't work if code coverage is enabled.
@moduletag :fails_on_coverage

setup_all do
Task.start_link(fn ->
System.cmd("epmd", [])
Expand Down