victorolinasc / junit-formatter

A JUnit XML report exporter for Elixir's ExUnit
https://hexdocs.pm/junit_formatter/
Apache License 2.0
111 stars 37 forks source link

Error writing report file when test failed with unicode characters #35

Closed seehait closed 5 years ago

seehait commented 5 years ago

My code produce some result which contains unicode characters (in Thai language), then it cannot product the test report file.

Example console output:

  1) test GET / (xxxxxTest)
     test/xxxxx_test.exs:4
     Assertion with =~ failed
     code:  assert html_response(conn, 200) =~ "Welcome to Phoenix!"
     left:  "ยินดีต้อนรับ"
     right: "Welcome to Phoenix!"
     stacktrace:
       test/xxxxx_test.exs:6: (test)

Finished in 0.01 seconds
3 tests, 1 failure

Randomized with seed 47473
11:01:05.156 [error] GenServer #PID<0.508.0> terminating
** (File.Error) could not write to file "./report_file_test.xml": bad argument
    (elixir) lib/file.ex:1050: File.write!/3
    (junit_formatter) lib/formatter.ex:77: JUnitFormatter.handle_cast/2
    (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
    (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:suite_finished, 15823, nil}}
11:01:05.157 [error] Task #PID<0.492.0> started from #PID<0.93.0> terminating
** (stop) exited in: GenServer.stop(#PID<0.508.0>, :normal, 30000)
    ** (EXIT) exited in: :sys.terminate(#PID<0.508.0>, :normal, :infinity)
        ** (EXIT) an exception was raised:
            ** (File.Error) could not write to file "./report_file_test.xml": bad argument
                (elixir) lib/file.ex:1050: File.write!/3
                (junit_formatter) lib/formatter.ex:77: JUnitFormatter.handle_cast/2
                (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
                (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
                (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
    (elixir) lib/gen_server.ex:968: GenServer.stop/3
    (ex_unit) lib/ex_unit/event_manager.ex:22: anonymous fn/2 in ExUnit.EventManager.stop/1
    (elixir) lib/enum.ex:1948: Enum."-reduce/3-lists^foldl/2-0-"/3
    (ex_unit) lib/ex_unit/event_manager.ex:21: ExUnit.EventManager.stop/1
    (ex_unit) lib/ex_unit/runner.ex:28: ExUnit.Runner.run/2
    (elixir) lib/task/supervised.ex:90: Task.Supervised.invoke_mfa/2
    (elixir) lib/task/supervised.ex:35: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Function: &ExUnit.run/0
    Args: []
** (EXIT from #PID<0.93.0>) exited in: GenServer.stop(#PID<0.508.0>, :normal, 30000)
    ** (EXIT) exited in: :sys.terminate(#PID<0.508.0>, :normal, :infinity)
        ** (EXIT) an exception was raised:
            ** (File.Error) could not write to file "./report_file_test.xml": bad argument
                (elixir) lib/file.ex:1050: File.write!/3
                (junit_formatter) lib/formatter.ex:77: JUnitFormatter.handle_cast/2
                (stdlib) gen_server.erl:637: :gen_server.try_dispatch/4
                (stdlib) gen_server.erl:711: :gen_server.handle_msg/6
                (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

In the other hand, if my code produce only English character result, everything will be working fine.

Elixir version: 1.9.0 OS: Ubuntu 18.04 LTS junit-formatter version: 3.0

victorolinasc commented 5 years ago

Sorry for the long delay...

We do have tests for unusual unicode characters here. This is strange...

I will take a look at it later this week. Could you run the test suite and see if it fails for you on your system? Simply:

git clone git@github.com:victorolinasc/junit-formatter.git
cd junit-formatter
mix deps.get
mix test

Thanks for pointing it out!

seehait commented 5 years ago

Thanks @victorolinasc , It's very strange... All tests you suggest me to run on my machine are passed.

seehait commented 5 years ago

@victorolinasc

I'm not sure whether https://github.com/victorolinasc/junit-formatter/pull/34 is related with this problems or not. Btw, the current release 3.0.0 is released before the prior pull request is merged.

May you create the next release with the prior pull request?

Thank you for helping us.

victorolinasc commented 5 years ago

You are totally right! My bad =/

I have released a PATCH version now. Thanks once again for pointing it out and sorry for not releasing it before. Here it is on hex: https://hex.pm/packages/junit_formatter/3.0.1

If that works for you I'll close this issue.

seehait commented 5 years ago

@victorolinasc Thank you very much. It works perfectly now. 👍