Clean up Elixir path related tests
This commit is contained in:
@@ -1,13 +1,30 @@
|
||||
Code.require_file "test_helper.exs", __DIR__
|
||||
|
||||
defmodule FileTest do
|
||||
use ExUnit.Case
|
||||
|
||||
defmodule Elixir.FileCase do
|
||||
use ExUnit.CaseTemplate
|
||||
import PathHelpers
|
||||
|
||||
using do
|
||||
quote do
|
||||
import PathHelpers
|
||||
end
|
||||
end
|
||||
|
||||
setup _ do
|
||||
File.mkdir_p!(tmp_path)
|
||||
end
|
||||
|
||||
teardown _ do
|
||||
File.rm_rf(tmp_path)
|
||||
end
|
||||
end
|
||||
|
||||
defmodule FileTest do
|
||||
use Elixir.FileCase
|
||||
import Regex, only: [escape: 1]
|
||||
|
||||
defmodule Cp do
|
||||
use ExUnit.Case
|
||||
use Elixir.FileCase
|
||||
|
||||
test :cp_with_src_file_and_dest_file do
|
||||
src = fixture_path("file.txt")
|
||||
@@ -347,9 +364,11 @@ defmodule FileTest do
|
||||
end
|
||||
|
||||
test :cp_preserves_mode do
|
||||
src = fixture_path("cp_mode")
|
||||
File.mkdir_p!(tmp_path("tmp"))
|
||||
src = fixture_path("cp_mode")
|
||||
dest = tmp_path("tmp/cp_mode")
|
||||
File.cp! src, dest
|
||||
|
||||
File.cp!(src, dest)
|
||||
File.Stat[mode: src_mode] = File.stat! src
|
||||
File.Stat[mode: dest_mode] = File.stat! dest
|
||||
assert src_mode == dest_mode
|
||||
@@ -404,7 +423,7 @@ defmodule FileTest do
|
||||
end
|
||||
|
||||
defmodule OpenReadWrite do
|
||||
use ExUnit.Case
|
||||
use Elixir.FileCase
|
||||
|
||||
test :read_with_binary do
|
||||
assert { :ok, "FOO\n" } = File.read(fixture_path("file.txt"))
|
||||
@@ -546,7 +565,7 @@ defmodule FileTest do
|
||||
end
|
||||
|
||||
defmodule Mkdir do
|
||||
use ExUnit.Case
|
||||
use Elixir.FileCase
|
||||
|
||||
test :mkdir_with_binary do
|
||||
fixture = tmp_path("tmp_test")
|
||||
@@ -687,7 +706,7 @@ defmodule FileTest do
|
||||
end
|
||||
|
||||
defmodule Rm do
|
||||
use ExUnit.Case
|
||||
use Elixir.FileCase
|
||||
|
||||
test :rm_file do
|
||||
fixture = tmp_path("tmp_test.txt")
|
||||
@@ -767,19 +786,24 @@ defmodule FileTest do
|
||||
end
|
||||
|
||||
test :rm_rf_with_symlink do
|
||||
fixture = tmp_path("tmp/link")
|
||||
from = tmp_path("tmp/from")
|
||||
to = tmp_path("tmp/to")
|
||||
|
||||
File.mkdir_p(tmp_path("tmp"))
|
||||
:file.make_symlink(fixture_path, fixture)
|
||||
if File.exists?(fixture) or !match?({:win32,_},:os.type) do
|
||||
assert File.exists?(fixture)
|
||||
File.mkdir_p!(to)
|
||||
File.write!(Path.join(to, "hello"), "world")
|
||||
:file.make_symlink(to, from)
|
||||
|
||||
{ :ok, files } = File.rm_rf(fixture)
|
||||
if File.exists?(from) or not is_win? do
|
||||
assert File.exists?(from)
|
||||
|
||||
{ :ok, files } = File.rm_rf(from)
|
||||
assert length(files) == 1
|
||||
|
||||
assert File.exists?(fixture_path("file.txt"))
|
||||
refute File.exists?(fixture)
|
||||
end
|
||||
assert File.exists?(Path.join(to, "hello"))
|
||||
refute File.exists?(from)
|
||||
end
|
||||
after
|
||||
File.rm(tmp_path("tmp/from"))
|
||||
end
|
||||
|
||||
test :rm_rf_with_char_list do
|
||||
@@ -1126,11 +1150,11 @@ defmodule FileTest do
|
||||
stat = File.stat!(fixture)
|
||||
assert stat.mode == 0100666
|
||||
|
||||
if !match? { :win32, _ }, :os.type do
|
||||
unless is_win? do
|
||||
assert File.chmod(fixture, 0100777) == :ok
|
||||
stat = File.stat!(fixture)
|
||||
assert stat.mode == 0100777
|
||||
end
|
||||
end
|
||||
after
|
||||
File.rm(fixture)
|
||||
end
|
||||
@@ -1145,11 +1169,11 @@ defmodule FileTest do
|
||||
stat = File.stat!(fixture)
|
||||
assert stat.mode == 0100666
|
||||
|
||||
if !match? { :win32, _ }, :os.type do
|
||||
unless is_win? do
|
||||
assert File.chmod!(fixture, 0100777) == :ok
|
||||
stat = File.stat!(fixture)
|
||||
assert stat.mode == 0100777
|
||||
end
|
||||
end
|
||||
after
|
||||
File.rm(fixture)
|
||||
end
|
||||
@@ -1193,7 +1217,7 @@ defmodule FileTest do
|
||||
fixture = tmp_path("tmp_test.txt")
|
||||
File.rm(fixture)
|
||||
|
||||
assert File.chown(fixture, 1) == {:error,:enoent}
|
||||
assert File.chown(fixture, 1) == {:error,:enoent}
|
||||
end
|
||||
|
||||
test :chown_with_failue! do
|
||||
@@ -1206,7 +1230,6 @@ defmodule FileTest do
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
defp last_year do
|
||||
last_year :calendar.local_time
|
||||
end
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
Code.require_file "../test_helper.exs", __DIR__
|
||||
|
||||
import PathHelpers
|
||||
|
||||
defmodule Kernel.CLI.InitTest do
|
||||
use ExUnit.Case, async: true
|
||||
import PathHelpers
|
||||
|
||||
test :code_init do
|
||||
assert elixir('-e "IO.puts 3"') == '3\n'
|
||||
@@ -14,7 +15,6 @@ end
|
||||
|
||||
defmodule Kernel.CLI.OptionParsingTest do
|
||||
use ExUnit.Case, async: true
|
||||
import PathHelpers
|
||||
|
||||
test :path do
|
||||
root = fixture_path("../../..") |> to_char_list
|
||||
@@ -33,7 +33,6 @@ end
|
||||
|
||||
defmodule Kernel.CLI.AtExitTest do
|
||||
use ExUnit.Case, async: true
|
||||
import PathHelpers
|
||||
|
||||
test :at_exit do
|
||||
assert elixir(fixture_path("at_exit.exs") |> to_char_list) ==
|
||||
@@ -43,7 +42,6 @@ end
|
||||
|
||||
defmodule Kernel.CLI.ErrorTest do
|
||||
use ExUnit.Case, async: true
|
||||
import PathHelpers
|
||||
|
||||
test :code_error do
|
||||
assert :string.str('** (throw) 1', elixir('-e "throw 1"')) == 0
|
||||
@@ -56,7 +54,6 @@ end
|
||||
|
||||
defmodule Kernel.CLI.SyntaxErrorTest do
|
||||
use ExUnit.Case, async: true
|
||||
import PathHelpers
|
||||
|
||||
test :syntax_code_error do
|
||||
message = '** (TokenMissingError) nofile:1: syntax error: expression is incomplete'
|
||||
@@ -72,13 +69,14 @@ end
|
||||
|
||||
defmodule Kernel.CLI.CompileTest do
|
||||
use ExUnit.Case, async: true
|
||||
import PathHelpers
|
||||
|
||||
test :compile_code do
|
||||
fixture = fixture_path "compile_sample.ex"
|
||||
assert elixirc('#{fixture} -o #{tmp_path}') ==
|
||||
'Compiled #{fixture}\n'
|
||||
assert File.regular?(tmp_path "Elixir.CompileSample.beam")
|
||||
after
|
||||
File.rm(tmp_path("Elixir.CompileSample.beam"))
|
||||
end
|
||||
|
||||
test :possible_deadlock do
|
||||
@@ -93,7 +91,6 @@ end
|
||||
|
||||
defmodule Kernel.CLI.ParallelCompilerTest do
|
||||
use ExUnit.Case
|
||||
import PathHelpers
|
||||
import ExUnit.CaptureIO
|
||||
|
||||
test :files do
|
||||
|
||||
@@ -2,10 +2,10 @@ Code.require_file "test_helper.exs", __DIR__
|
||||
|
||||
defmodule PathTest do
|
||||
use ExUnit.Case, async: true
|
||||
import PathHelpers
|
||||
|
||||
if :file.native_name_encoding == :utf8 do
|
||||
test :wildcard do
|
||||
import PathHelpers
|
||||
File.mkdir_p(tmp_path("héllò"))
|
||||
assert Path.wildcard(tmp_path("héllò")) == [tmp_path("héllò")]
|
||||
after
|
||||
@@ -13,71 +13,70 @@ defmodule PathTest do
|
||||
end
|
||||
end
|
||||
|
||||
case :os.type do
|
||||
{ :unix, _ } ->
|
||||
test :relative do
|
||||
assert Path.relative("/usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("../usr/local/bin") == "../usr/local/bin"
|
||||
if is_win? do
|
||||
test :relative do
|
||||
assert Path.relative("C:/usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("C:\\usr\\local\\bin") == "usr\\local\\bin"
|
||||
assert Path.relative("C:usr\\local\\bin") == "usr\\local\\bin"
|
||||
|
||||
assert Path.relative('/usr/local/bin') == 'usr/local/bin'
|
||||
assert Path.relative('usr/local/bin') == 'usr/local/bin'
|
||||
assert Path.relative('../usr/local/bin') == '../usr/local/bin'
|
||||
assert Path.relative("/usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("../usr/local/bin") == "../usr/local/bin"
|
||||
|
||||
assert List.flatten(Path.relative(['/usr/', 'local/bin'])) == 'usr/local/bin'
|
||||
assert List.flatten(Path.relative(['usr/', 'local/bin'])) == 'usr/local/bin'
|
||||
assert List.flatten(Path.relative(['../usr', '/local/bin'])) == '../usr/local/bin'
|
||||
end
|
||||
assert Path.relative('/usr/local/bin') == 'usr/local/bin'
|
||||
assert Path.relative('usr/local/bin') == 'usr/local/bin'
|
||||
assert Path.relative('../usr/local/bin') == '../usr/local/bin'
|
||||
|
||||
test :type do
|
||||
assert Path.type("/usr/local/bin") == :absolute
|
||||
assert Path.type("usr/local/bin") == :relative
|
||||
assert Path.type("../usr/local/bin") == :relative
|
||||
assert List.flatten(Path.relative(['/usr/', 'local/bin'])) == 'usr/local/bin'
|
||||
assert List.flatten(Path.relative(['usr/', 'local/bin'])) == 'usr/local/bin'
|
||||
assert List.flatten(Path.relative(['../usr', '/local/bin'])) == '../usr/local/bin'
|
||||
end
|
||||
|
||||
assert Path.type('/usr/local/bin') == :absolute
|
||||
assert Path.type('usr/local/bin') == :relative
|
||||
assert Path.type('../usr/local/bin') == :relative
|
||||
test :type do
|
||||
assert Path.type("C:/usr/local/bin") == :absolute
|
||||
assert Path.type("C:\\usr\\local\\bin") == :absolute
|
||||
assert Path.type("C:usr\\local\\bin") == :volumerelative
|
||||
|
||||
assert Path.type(['/usr/', 'local/bin']) == :absolute
|
||||
assert Path.type(['usr/', 'local/bin']) == :relative
|
||||
assert Path.type(['../usr', '/local/bin']) == :relative
|
||||
end
|
||||
{ :win32, _ } ->
|
||||
test :relative do
|
||||
assert Path.relative("C:/usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("C:\\usr\\local\\bin") == "usr\\local\\bin"
|
||||
assert Path.relative("C:usr\\local\\bin") == "usr\\local\\bin"
|
||||
assert Path.type("/usr/local/bin") == :volumerelative
|
||||
assert Path.type("usr/local/bin") == :relative
|
||||
assert Path.type("../usr/local/bin") == :relative
|
||||
|
||||
assert Path.relative("/usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("../usr/local/bin") == "../usr/local/bin"
|
||||
assert Path.type('/usr/local/bin') == :volumerelative
|
||||
assert Path.type('usr/local/bin') == :relative
|
||||
assert Path.type('../usr/local/bin') == :relative
|
||||
|
||||
assert Path.relative('/usr/local/bin') == 'usr/local/bin'
|
||||
assert Path.relative('usr/local/bin') == 'usr/local/bin'
|
||||
assert Path.relative('../usr/local/bin') == '../usr/local/bin'
|
||||
assert Path.type(['/usr/', 'local/bin']) == :volumerelative
|
||||
assert Path.type(['usr/', 'local/bin']) == :relative
|
||||
assert Path.type(['../usr', '/local/bin']) == :relative
|
||||
end
|
||||
else
|
||||
test :relative do
|
||||
assert Path.relative("/usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("usr/local/bin") == "usr/local/bin"
|
||||
assert Path.relative("../usr/local/bin") == "../usr/local/bin"
|
||||
|
||||
assert List.flatten(Path.relative(['/usr/', 'local/bin'])) == 'usr/local/bin'
|
||||
assert List.flatten(Path.relative(['usr/', 'local/bin'])) == 'usr/local/bin'
|
||||
assert List.flatten(Path.relative(['../usr', '/local/bin'])) == '../usr/local/bin'
|
||||
end
|
||||
assert Path.relative('/usr/local/bin') == 'usr/local/bin'
|
||||
assert Path.relative('usr/local/bin') == 'usr/local/bin'
|
||||
assert Path.relative('../usr/local/bin') == '../usr/local/bin'
|
||||
|
||||
test :type do
|
||||
assert Path.type("C:/usr/local/bin") == :absolute
|
||||
assert Path.type("C:\\usr\\local\\bin") == :absolute
|
||||
assert Path.type("C:usr\\local\\bin") == :volumerelative
|
||||
assert List.flatten(Path.relative(['/usr/', 'local/bin'])) == 'usr/local/bin'
|
||||
assert List.flatten(Path.relative(['usr/', 'local/bin'])) == 'usr/local/bin'
|
||||
assert List.flatten(Path.relative(['../usr', '/local/bin'])) == '../usr/local/bin'
|
||||
end
|
||||
|
||||
assert Path.type("/usr/local/bin") == :volumerelative
|
||||
assert Path.type("usr/local/bin") == :relative
|
||||
assert Path.type("../usr/local/bin") == :relative
|
||||
test :type do
|
||||
assert Path.type("/usr/local/bin") == :absolute
|
||||
assert Path.type("usr/local/bin") == :relative
|
||||
assert Path.type("../usr/local/bin") == :relative
|
||||
|
||||
assert Path.type('/usr/local/bin') == :volumerelative
|
||||
assert Path.type('usr/local/bin') == :relative
|
||||
assert Path.type('../usr/local/bin') == :relative
|
||||
assert Path.type('/usr/local/bin') == :absolute
|
||||
assert Path.type('usr/local/bin') == :relative
|
||||
assert Path.type('../usr/local/bin') == :relative
|
||||
|
||||
assert Path.type(['/usr/', 'local/bin']) == :volumerelative
|
||||
assert Path.type(['usr/', 'local/bin']) == :relative
|
||||
assert Path.type(['../usr', '/local/bin']) == :relative
|
||||
end
|
||||
assert Path.type(['/usr/', 'local/bin']) == :absolute
|
||||
assert Path.type(['usr/', 'local/bin']) == :relative
|
||||
assert Path.type(['../usr', '/local/bin']) == :relative
|
||||
end
|
||||
end
|
||||
|
||||
test :absname_with_binary do
|
||||
@@ -251,7 +250,7 @@ defmodule PathTest do
|
||||
assert Path.split('/foo/bar') == ['/', 'foo', 'bar']
|
||||
end
|
||||
|
||||
if match? { :win32, _ }, :os.type do
|
||||
if is_win? do
|
||||
defp strip_drive_letter_if_windows([_d,?:|rest]), do: rest
|
||||
defp strip_drive_letter_if_windows(<<_d,?:,rest::binary>>), do: rest
|
||||
else
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
Code.require_file "test_helper.exs", __DIR__
|
||||
|
||||
require :os, as: OS
|
||||
|
||||
defmodule SystemTest do
|
||||
use ExUnit.Case, async: true
|
||||
import PathHelpers
|
||||
@@ -19,7 +17,6 @@ defmodule SystemTest do
|
||||
|
||||
if :file.native_name_encoding == :utf8 do
|
||||
test :cwd_with_utf8 do
|
||||
import PathHelpers
|
||||
File.mkdir_p(tmp_path("héllò"))
|
||||
|
||||
File.cd!(tmp_path("héllò"), fn ->
|
||||
|
||||
@@ -42,9 +42,11 @@ defmodule PathHelpers do
|
||||
end
|
||||
|
||||
if match? { :win32, _ }, :os.type do
|
||||
def is_win?, do: true
|
||||
def executable_extension, do: ".bat"
|
||||
def redirect_std_err_on_win, do: " 2>&1"
|
||||
else
|
||||
def is_win?, do: false
|
||||
def executable_extension, do: ""
|
||||
def redirect_std_err_on_win, do: ""
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user