Skip to content

Commit

Permalink
Start using it
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmach committed Jun 27, 2020
1 parent 4c39954 commit 01df255
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
19 changes: 7 additions & 12 deletions lib/elixir/test/elixir/enum_test.exs
Expand Up @@ -1956,20 +1956,15 @@ defmodule EnumTest.SideEffects do
end

test "take/2 does not consume next without a need" do
path = tmp_path("oneliner.txt")
File.mkdir(Path.dirname(path))
path = Path.join([tmp_dir!(), "oneliner.txt"])

try do
File.write!(path, "ONE")
File.write!(path, "ONE")

File.open!(path, [], fn file ->
iterator = IO.stream(file, :line)
assert Enum.take(iterator, 1) == ["ONE"]
assert Enum.take(iterator, 5) == []
end)
after
File.rm(path)
end
File.open!(path, [], fn file ->
iterator = IO.stream(file, :line)
assert Enum.take(iterator, 1) == ["ONE"]
assert Enum.take(iterator, 5) == []
end)
end

test "take/2 with no elements works as no-op" do
Expand Down
16 changes: 8 additions & 8 deletions lib/ex_unit/test/ex_unit/failures_manifest_test.exs
Expand Up @@ -4,7 +4,7 @@ defmodule ExUnit.FailuresManifestTest do
use ExUnit.Case, async: false

import ExUnit.FailuresManifest
import ExUnit.TestHelpers, only: [tmp_path: 0, in_tmp: 2]
import ExUnit.TestHelpers, only: [in_tmp: 2]

@passed nil
@skipped {:skipped, "reason"}
Expand Down Expand Up @@ -96,14 +96,16 @@ defmodule ExUnit.FailuresManifestTest do

@manifest_path "example.manifest"

defp manifest_path() do
Path.join([tmp_dir!(), "example.manifest"])
end

describe "write!/2" do
test "stores a manifest that can later be read with read/1", context do
manifest = non_blank_manifest(context)

in_tmp(context.test, fn ->
assert write!(manifest, @manifest_path) == :ok
assert read(@manifest_path) == manifest
end)
assert write!(manifest, manifest_path()) == :ok
assert read(manifest_path()) == manifest
end

test "prunes tests from files that no longer exist", context do
Expand Down Expand Up @@ -143,9 +145,7 @@ defmodule ExUnit.FailuresManifestTest do

describe "read/1" do
test "returns a blank manifest when loading a file that does not exit" do
path = tmp_path() <> "missing.manifest"
refute File.exists?(path)
assert read(path) == new()
assert read(tmp_dir!() <> "missing.manifest") == new()
end

test "returns a blank manifest when the file is corrupted", context do
Expand Down
3 changes: 1 addition & 2 deletions lib/mix/test/mix/shell_test.exs
Expand Up @@ -20,8 +20,7 @@ defmodule Mix.ShellTest do

test "with :cd" do
Mix.shell(Mix.Shell.IO)
tmp_dir = System.tmp_dir()
File.mkdir_p!(tmp_dir)
tmp_dir = tmp_dir!()
{pwd, 0} = System.cmd("pwd", [], cd: tmp_dir)

assert ExUnit.CaptureIO.capture_io(fn ->
Expand Down

0 comments on commit 01df255

Please sign in to comment.