|
| 1 | +defmodule MixTestInteractive.CommandLineFormatterTest do |
| 2 | + use ExUnit.Case, async: true |
| 3 | + |
| 4 | + alias MixTestInteractive.CommandLineFormatter |
| 5 | + |
| 6 | + describe "formatting a command line with proper quoting" do |
| 7 | + test "formats simple commands without quoting" do |
| 8 | + assert CommandLineFormatter.call("mix", ["test", "--stale", "file.exs"]) == |
| 9 | + ~s(mix test --stale file.exs) |
| 10 | + end |
| 11 | + |
| 12 | + test "double-quotes arguments with spaces" do |
| 13 | + assert CommandLineFormatter.call("mix", ["test", "file with spaces.txt"]) == |
| 14 | + ~s(mix test "file with spaces.txt") |
| 15 | + end |
| 16 | + |
| 17 | + test "double-quotes arguments with special characters" do |
| 18 | + args = ["do", "eval", "Application.put_env(:elixir,:ansi_enabled,true)", ",", "test"] |
| 19 | + expected = ~s[mix do eval "Application.put_env(:elixir,:ansi_enabled,true)" , test] |
| 20 | + |
| 21 | + assert CommandLineFormatter.call("mix", args) == expected |
| 22 | + end |
| 23 | + |
| 24 | + test "single-quotes arguments containing only double quotes" do |
| 25 | + args = ["do", "eval", ~s[IO.puts("running tests!")], ",", "test"] |
| 26 | + expected = ~s[mix do eval 'IO.puts("running tests!")' , test] |
| 27 | + |
| 28 | + assert CommandLineFormatter.call("mix", args) == expected |
| 29 | + end |
| 30 | + |
| 31 | + test "double-quotes arguments with mixed single and double quotes" do |
| 32 | + args = ["do", "eval", ~s[IO.puts("I'm testing")], ",", "test"] |
| 33 | + expected = ~s[mix do eval 'IO.puts(\"I'\\''m testing\")' , test] |
| 34 | + |
| 35 | + assert CommandLineFormatter.call("mix", args) == expected |
| 36 | + end |
| 37 | + end |
| 38 | +end |
0 commit comments