File tree Expand file tree Collapse file tree 7 files changed +133
-14
lines changed Expand file tree Collapse file tree 7 files changed +133
-14
lines changed Original file line number Diff line number Diff line change
1
+ name : CI
2
+ on :
3
+ pull_request :
4
+ push :
5
+ branches : main
6
+
7
+ jobs :
8
+ tests :
9
+ runs-on : ubuntu-latest
10
+ name : Test (${{matrix.elixir}}/${{matrix.otp}})
11
+
12
+ strategy :
13
+ fail-fast : false
14
+ matrix :
15
+ elixir : [1.17.x, 1.18.x]
16
+ otp : [26.x, 27.x]
17
+
18
+ steps :
19
+ - uses : actions/checkout@v4
20
+ - uses : erlef/setup-beam@v1
21
+ id : install
22
+ with :
23
+ otp-version : ${{matrix.otp}}
24
+ elixir-version : ${{matrix.elixir}}
25
+ - uses : actions/cache@v4
26
+ id : cache
27
+ with :
28
+ path : |
29
+ deps
30
+ key : ${{ runner.os }}-mix-${{steps.install.outputs.otp-version}}-${{steps.install.outputs.elixir-version}}-${{ hashFiles('**/mix.lock') }}
31
+ restore-keys : |
32
+ ${{ runner.os }}-mix-${{steps.install.outputs.otp-version}}-${{steps.install.outputs.elixir-version}}-
33
+
34
+ - name : Install Dependencies
35
+ if : steps.cache.outputs.cache-hit != 'true'
36
+ run : mix deps.get
37
+
38
+ - name : Run Tests
39
+ run : mix test
40
+
41
+ formatter :
42
+ runs-on : ubuntu-latest
43
+ name : Formatter (${{matrix.elixir}}/${{matrix.otp}})
44
+
45
+ strategy :
46
+ matrix :
47
+ otp : [27.x]
48
+ elixir : [1.17.x]
49
+
50
+ steps :
51
+ - uses : actions/checkout@v4
52
+ - uses : erlef/setup-beam@v1
53
+ id : install
54
+ with :
55
+ otp-version : ${{matrix.otp}}
56
+ elixir-version : ${{matrix.elixir}}
57
+ - uses : actions/cache@v4
58
+ id : cache
59
+ with :
60
+ path : |
61
+ deps
62
+ _build
63
+ key : ${{ runner.os }}-mix-${{steps.install.outputs.otp-version}}-${{steps.install.outputs.elixir-version}}-${{ hashFiles('**/mix.lock') }}
64
+ restore-keys : |
65
+ ${{ runner.os }}-mix-${{steps.install.outputs.otp-version}}-${{steps.install.outputs.elixir-version}}-
66
+
67
+ - name : Install Dependencies
68
+ if : steps.cache.outputs.cache-hit != 'true'
69
+ run : mix deps.get
70
+
71
+ - name : Run Formatter
72
+ run : mix format --check-formatted
Original file line number Diff line number Diff line change @@ -24,3 +24,5 @@ web_dev_utils-*.tar
24
24
25
25
# Temporary files, for example, from tests.
26
26
/tmp /
27
+
28
+ /test /support /editable.ex
Original file line number Diff line number Diff line change @@ -25,12 +25,12 @@ defmodule WebDevUtils.CodeReloader do
25
25
{ :ok , :nostate }
26
26
end
27
27
28
- def handle_call ( :reload , from , state ) do
29
- froms = all_waiting ( [ from ] )
30
- mix_compile ( Code . ensure_loaded ( Mix.Task ) )
31
- Enum . each ( froms , & GenServer . reply ( & 1 , :ok ) )
28
+ def handle_call ( :reload , _from , state ) do
29
+ froms = all_waiting ( [ ] )
30
+ result = mix_compile ( Code . ensure_loaded ( Mix.Task ) )
31
+ Enum . each ( froms , & GenServer . reply ( & 1 , result ) )
32
32
33
- { :noreply , state }
33
+ { :reply , result , state }
34
34
end
35
35
36
36
defp all_waiting ( acc ) do
@@ -43,10 +43,11 @@ defmodule WebDevUtils.CodeReloader do
43
43
44
44
defp mix_compile ( { :error , _reason } ) do
45
45
Logger . error ( "Could not find Mix" )
46
+ :error
46
47
end
47
48
48
49
defp mix_compile ( { :module , Mix.Task } ) do
49
50
Mix.Task . reenable ( "compile.elixir" )
50
- Mix.Task . run ( "compile.elixir" )
51
+ Mix.Task . run ( "compile.elixir" , [ "--return-errors" ] )
51
52
end
52
53
end
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ defmodule WebDevUtils.MixProject do
10
10
"Library to enable awesome local development for websites and web applications" ,
11
11
version: "0.2.0" ,
12
12
elixir: "~> 1.14" ,
13
+ elixirc_paths: elixirc_paths ( Mix . env ( ) ) ,
13
14
start_permanent: Mix . env ( ) == :prod ,
14
15
package: package ( ) ,
15
16
deps: deps ( )
@@ -23,6 +24,10 @@ defmodule WebDevUtils.MixProject do
23
24
]
24
25
end
25
26
27
+ # Specifies which paths to compile per environment.
28
+ defp elixirc_paths ( :test ) , do: [ "lib" , "test/support" ]
29
+ defp elixirc_paths ( _ ) , do: [ "lib" ]
30
+
26
31
# Run "mix help deps" to learn about dependencies.
27
32
defp deps do
28
33
[
Original file line number Diff line number Diff line change
1
+ defmodule WebDevUtils.CodeReloaderTest do
2
+ use ExUnit.Case , async: true
3
+ import ExUnit.CaptureIO
4
+
5
+ alias WebDevUtils.CodeReloader
6
+
7
+ setup do
8
+ on_exit ( fn ->
9
+ File . rm ( "test/support/editable.ex" )
10
+ end )
11
+
12
+ :ok
13
+ end
14
+
15
+ test "noops when nothing has changed" do
16
+ start_supervised! ( CodeReloader )
17
+
18
+ assert { _ , [ ] } = CodeReloader . reload ( )
19
+ assert { :noop , [ ] } == CodeReloader . reload ( )
20
+ end
21
+
22
+ test "recompiles code" do
23
+ File . write! ( "test/support/editable.ex" , """
24
+ defmodule Editable do
25
+ end
26
+ """ )
27
+
28
+ start_supervised! ( CodeReloader )
29
+
30
+ capture_io ( :stderr , fn ->
31
+ assert { :ok , [ ] } == CodeReloader . reload ( )
32
+ end )
33
+ end
34
+
35
+ test "recompiles code and something fails" do
36
+ File . write! ( "test/support/editable.ex" , """
37
+ defmodule Editable d
38
+ end
39
+ """ )
40
+
41
+ start_supervised! ( CodeReloader )
42
+
43
+ capture_io ( :stderr , fn ->
44
+ assert { :error , [ % Mix.Task.Compiler.Diagnostic { } ] } = CodeReloader . reload ( )
45
+ end )
46
+ end
47
+ end
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments