 defmodule Kernel.CLI.InitTest do
   use ExUnit.Case, async: true
 
-  test :code_init do
+  test "handles code on initialization" do
     assert elixir('-e "IO.puts [?3]"') == '3\n'
 
     result = elixir('-e "IO.puts inspect(System.argv)" #{fixture_path("init_sample.exs")} -o 1 2 3')

  end
end

defmodule Kernel.CLI.SyntaxErrorTest do
  use ExUnit.Case, async: true

  defp check_output(elixir_cmd, expected_msg) do
    o = elixir(elixir_cmd)
    assert :string.str(o, expected_msg) == 1, "Expected this output: `#{expected_msg}`\nbut got this output: `#{o}`"
  end

  test :syntax_code_error do
    check_output('-e "[1,2"', '** (TokenMissingError) nofile:1: missing terminator: ]')
    check_output('-e "case 1 end"', %C"** (SyntaxError) nofile:1: unexpected token: end")
  end
end

defmodule Kernel.CLI.CompileTest do
  use ExUnit.Case, async: true

  test :compile_code do
    fixture = fixture_path "compile_sample.ex"
    assert elixirc('#{fixture} -o #{tmp_path}') == ''
    assert File.regular?(tmp_path "Elixir.CompileSample.beam")

    File.rm(tmp_path("Elixir.CompileSample.beam"))
  end

  test "fails on missing patterns" do
    fixture = fixture_path "compile_sample.ex"
    output = elixirc('#{fixture} non_existing.ex -o #{tmp_path}')
    assert :string.str(output, 'non_existing.ex') > 0, "expected non_existing.ex to be mentionned"
