|
2 | 2 | # SPDX-FileCopyrightText: 2021 The Elixir Team |
3 | 3 | # SPDX-FileCopyrightText: 2012 Plataformatec |
4 | 4 |
|
5 | | -# Beam files compiled on demand |
6 | | -path = Path.expand("../../tmp/beams", __DIR__) |
7 | | -File.rm_rf!(path) |
8 | | -File.mkdir_p!(path) |
9 | | -Code.prepend_path(path) |
10 | | - |
11 | 5 | Application.put_env(:elixir, :ansi_enabled, true) |
12 | 6 | Code.compiler_options(debug_info: true, infer_signatures: [:elixir]) |
13 | 7 |
|
14 | | -defmodule PathHelpers do |
15 | | - def fixture_path() do |
16 | | - Path.expand("fixtures", __DIR__) |
17 | | - end |
18 | | - |
19 | | - def tmp_path() do |
20 | | - Path.expand("../../tmp", __DIR__) |
21 | | - end |
22 | | - |
23 | | - def fixture_path(extra) do |
24 | | - Path.join(fixture_path(), extra) |
25 | | - end |
26 | | - |
27 | | - def tmp_path(extra) do |
28 | | - Path.join(tmp_path(), extra) |
29 | | - end |
30 | | - |
31 | | - def elixir(args, executable_extension \\ "") do |
32 | | - run_cmd(elixir_executable(executable_extension), args) |
33 | | - end |
34 | | - |
35 | | - def elixir_executable(extension \\ "") do |
36 | | - executable_path("elixir", extension) |
37 | | - end |
38 | | - |
39 | | - def elixirc(args, executable_extension \\ "") do |
40 | | - run_cmd(elixirc_executable(executable_extension), args) |
41 | | - end |
42 | | - |
43 | | - def elixirc_executable(extension \\ "") do |
44 | | - executable_path("elixirc", extension) |
45 | | - end |
46 | | - |
47 | | - def iex(args, executable_extension \\ "") do |
48 | | - run_cmd(iex_executable(executable_extension), args) |
49 | | - end |
50 | | - |
51 | | - def iex_executable(extension \\ "") do |
52 | | - executable_path("iex", extension) |
53 | | - end |
54 | | - |
55 | | - def write_beam({:module, name, bin, _} = res) do |
56 | | - File.mkdir_p!(unquote(path)) |
57 | | - beam_path = Path.join(unquote(path), Atom.to_string(name) <> ".beam") |
58 | | - File.write!(beam_path, bin) |
59 | | - res |
60 | | - end |
61 | | - |
62 | | - defp run_cmd(executable, args) do |
63 | | - ~c"#{executable} #{IO.chardata_to_string(args)}#{redirect_std_err_on_win()}" |
64 | | - |> :os.cmd() |
65 | | - |> :unicode.characters_to_binary() |
66 | | - end |
67 | | - |
68 | | - defp executable_path(name, extension) do |
69 | | - Path.expand("../../../../bin/#{name}#{extension}", __DIR__) |
70 | | - end |
71 | | - |
72 | | - if match?({:win32, _}, :os.type()) do |
73 | | - def windows?, do: true |
74 | | - def executable_extension, do: ".bat" |
75 | | - def redirect_std_err_on_win, do: " 2>&1" |
76 | | - else |
77 | | - def windows?, do: false |
78 | | - def executable_extension, do: "" |
79 | | - def redirect_std_err_on_win, do: "" |
80 | | - end |
81 | | -end |
| 8 | +Code.eval_file("../../scripts/path_helpers.exs", __DIR__) |
82 | 9 |
|
83 | 10 | defmodule CodeFormatterHelpers do |
84 | 11 | defmacro assert_same(good, opts \\ []) do |
|
0 commit comments