Skip to content

"mix test" doesn't work on Windows #281

@wingyplus

Description

@wingyplus

If I run mix test on Windows, the project will raise error:

PS C:\Users\WingyMomo\src\github.com\elixir-protobuf\protobuf> mix test  
Generated protobuf app
Generated escript protoc-gen-elixir with MIX_ENV=test
Running: protoc --plugin=./protoc-gen-elixir --elixir_out="./generated" -I c:/Users/WingyMomo/src/github.com/elixir-protobuf/protobuf/deps/google_protobuf/src -I src -I test/protobuf/protoc/proto test/protobuf/protoc/proto/extension.proto
--elixir_out: protoc-gen-elixir: %1 is not a valid Win32 application.

** (Mix) Command exited with non-zero status: 1

After I investigate, I found that mix escript.build generate only unix shell script that run escript binary but not for Windows shell script. I try temporary by create protoc-gen-elixir.bat:

@echo off
@escript "%~dpn0" %*

NOTE: I copied this script from mix escript.install.

And modify mix.exs with:

diff --git a/mix.exs b/mix.exs
index 707526a..866b128 100644
--- a/mix.exs
+++ b/mix.exs
@@ -227,7 +227,7 @@ defmodule Protobuf.Mixfile do
     args =
       [
         ~s(protoc),
-        ~s(--plugin=./protoc-gen-elixir),
+        ~s(--plugin=./protoc-gen-elixir.bat),
         ~s(--elixir_out="#{elixir_out}"),
         args
       ] ++ files_to_generate

After run mix test will change to:

Generated protobuf app
Generated escript protoc-gen-elixir with MIX_ENV=test
Running: protoc --plugin=./protoc-gen-elixir.bat --elixir_out="./generated" -I c:/Users/WingyMomo/src/github.com/elixir-protobuf/protobuf/deps/google_protobuf/src -I src -I test/protobuf/protoc/proto test/protobuf/protoc/proto/extension.proto
** (Protobuf.DecodeError) cannot decode binary data, unknown wire type: 6
    (protobuf 0.10.1-dev) lib/protobuf/decoder.ex:80: Protobuf.Decoder.handle_field/5
    (protobuf 0.10.1-dev) lib/protobuf/decoder.ex:17: Protobuf.Decoder.decode/2
    (protobuf 0.10.1-dev) lib/protobuf/decoder.ex:231: Protobuf.Decoder.value_for_field/3
    (protobuf 0.10.1-dev) lib/protobuf/decoder.ex:382: Protobuf.Decoder.update_in_message/3
    (protobuf 0.10.1-dev) lib/protobuf/decoder.ex:176: Protobuf.Decoder.handle_value/6
    (protobuf 0.10.1-dev) lib/protobuf/decoder.ex:17: Protobuf.Decoder.decode/2
    (protobuf 0.10.1-dev) lib/protobuf/decoder.ex:231: Protobuf.Decoder.value_for_field/3
    (protobuf 0.10.1-dev) lib/protobuf/decoder.ex:382: Protobuf.Decoder.update_in_message/3
--elixir_out: protoc-gen-elixir: Plugin failed with status code 1.
** (Mix) Command exited with non-zero status: 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions