Skip to content

Commit

Permalink
Improve tests (#16)
Browse files Browse the repository at this point in the history
* Ensure smoke test doctests are valid doctests

* Test that integer formats are kept

* Reorganize formatter tests

* Fix smoke test results

* Format

* Make integer test elixir-version agnostic
  • Loading branch information
angelikatyborska authored Mar 29, 2024
1 parent 26b491a commit 7915b2b
Show file tree
Hide file tree
Showing 17 changed files with 312 additions and 284 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.diff]
trim_trailing_whitespace=false
5 changes: 2 additions & 3 deletions bin/smoke_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ Enum.each(projects, fn project ->
{_, 0} = System.cmd("mix", ["compile"], cd: project_path)
end

{_, 0} = System.cmd("mix", ["test"], cd: project_path)
{_, 0} = System.cmd("mix", ["format"], cd: project_path)
{diff, 0} = System.cmd("git", ["diff"], cd: project_path)

Code.eval_file("#{project_path}/expected_diff.ex")

expected_diff = ExpectedDiff.diff()
expected_diff = File.read!("#{project_path}/expected_diff.diff")

:code.delete(ExpectedDiff)
:code.purge(ExpectedDiff)
Expand Down
Empty file.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule ProjectWithFormattedCode do
...> |> ProjectWithFormattedCode.add(2)
3
iex> 3 + "3"
iex> ProjectWithFormattedCode.add(3, "3")
** (ArithmeticError) bad argument in arithmetic expression
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex b/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex
index 5b65e4d..98f817c 100644
--- a/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex
+++ b/smoke_test_data/elixir-1-13/project_with_unformatted_code/lib/project_with_unformatted_code.ex
@@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do
@moduledoc """
Documentation for `ProjectWithUnformattedCode`.

- iex> ProjectWithUnformattedCode.add(5,5)
+ iex> ProjectWithUnformattedCode.add(5, 5)
10
"""

@@ -15,7 +15,7 @@ defmodule ProjectWithUnformattedCode do
3

iex> 1
- ...> |> ProjectWithUnformattedCode.add(2)
+ ...> |> ProjectWithUnformattedCode.add(2)
3

"""
@@ -24,12 +24,28 @@ defmodule ProjectWithUnformattedCode do
end

@doc """
- iex> ProjectWithUnformattedCode.subtract( 5, 4 )
+ iex> ProjectWithUnformattedCode.subtract(5, 4)
1

- iex> [100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000, 700_000_000_000]
+ iex> [
+ ...> 100_000_000_000,
+ ...> 200_000_000_000,
+ ...> 300_000_000_000,
+ ...> 400_000_000_000,
+ ...> 500_000_000_000,
+ ...> 600_000_000_000,
+ ...> 700_000_000_000
+ ...> ]
...> |> Enum.map(&ProjectWithUnformattedCode.subtract(&1, 100_000_000_000))
- [0, 100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000]
+ [
+ 0,
+ 100_000_000_000,
+ 200_000_000_000,
+ 300_000_000_000,
+ 400_000_000_000,
+ 500_000_000_000,
+ 600_000_000_000
+ ]
"""
def subtract(a, b) do
a - b

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do
@moduledoc """
Documentation for `ProjectWithUnformattedCode`.
iex> ProjectWithFormattedCode.add(5,5)
iex> ProjectWithUnformattedCode.add(5,5)
10
"""

Expand All @@ -16,7 +16,7 @@ defmodule ProjectWithUnformattedCode do
iex> 1
...> |> ProjectWithUnformattedCode.add(2)
3
3
"""
def add(a, b) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
defmodule ProjectWithUnformattedCodeTest do
use ExUnit.Case
doctest ProjectWithUnformattedCode

test "greets the world" do
assert ProjectWithUnformattedCode.hello() == :world
end
end
Empty file.
5 changes: 0 additions & 5 deletions smoke_test_data/project_with_formatted_code/expected_diff.ex

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule ProjectWithFormattedCode do
...> |> ProjectWithFormattedCode.add(2)
3
iex> 3 + "3"
iex> ProjectWithFormattedCode.add(3, "3")
** (ArithmeticError) bad argument in arithmetic expression
"""
Expand Down
54 changes: 54 additions & 0 deletions smoke_test_data/project_with_unformatted_code/expected_diff.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
diff --git a/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex b/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex
index 5b65e4d..98f817c 100644
--- a/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex
+++ b/smoke_test_data/project_with_unformatted_code/lib/project_with_unformatted_code.ex
@@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do
@moduledoc """
Documentation for `ProjectWithUnformattedCode`.

- iex> ProjectWithUnformattedCode.add(5,5)
+ iex> ProjectWithUnformattedCode.add(5, 5)
10
"""

@@ -15,7 +15,7 @@ defmodule ProjectWithUnformattedCode do
3

iex> 1
- ...> |> ProjectWithUnformattedCode.add(2)
+ ...> |> ProjectWithUnformattedCode.add(2)
3

"""
@@ -24,12 +24,28 @@ defmodule ProjectWithUnformattedCode do
end

@doc """
- iex> ProjectWithUnformattedCode.subtract( 5, 4 )
+ iex> ProjectWithUnformattedCode.subtract(5, 4)
1

- iex> [100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000, 700_000_000_000]
+ iex> [
+ ...> 100_000_000_000,
+ ...> 200_000_000_000,
+ ...> 300_000_000_000,
+ ...> 400_000_000_000,
+ ...> 500_000_000_000,
+ ...> 600_000_000_000,
+ ...> 700_000_000_000
+ ...> ]
...> |> Enum.map(&ProjectWithUnformattedCode.subtract(&1, 100_000_000_000))
- [0, 100_000_000_000, 200_000_000_000, 300_000_000_000, 400_000_000_000, 500_000_000_000, 600_000_000_000]
+ [
+ 0,
+ 100_000_000_000,
+ 200_000_000_000,
+ 300_000_000_000,
+ 400_000_000_000,
+ 500_000_000_000,
+ 600_000_000_000
+ ]
"""
def subtract(a, b) do
a - b
62 changes: 0 additions & 62 deletions smoke_test_data/project_with_unformatted_code/expected_diff.ex

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule ProjectWithUnformattedCode do
@moduledoc """
Documentation for `ProjectWithUnformattedCode`.
iex> ProjectWithFormattedCode.add(5,5)
iex> ProjectWithUnformattedCode.add(5,5)
10
"""

Expand All @@ -16,7 +16,7 @@ defmodule ProjectWithUnformattedCode do
iex> 1
...> |> ProjectWithUnformattedCode.add(2)
3
3
"""
def add(a, b) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
defmodule ProjectWithUnformattedCodeTest do
use ExUnit.Case
doctest ProjectWithUnformattedCode

test "greets the world" do
assert ProjectWithUnformattedCode.hello() == :world
end
end
Loading

0 comments on commit 7915b2b

Please sign in to comment.