-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update underscore/1 to support Elixir 1.6's regex #275
Conversation
Would this change remain backward compatible, so if someone has project with Elixir <1.6 this still works? |
I ran Not sure how many versions back I need to test with? |
And these are the existing tests that should cover this change: /test/ex_machina/strategy_test.exs:
|
Thanks @unnawut for your answer. I don't think there is need to go back any further. From my point of view this one failing example between versions is indicative enough. |
I was just suggested a better solution with Macro.underscore/1. I'll update it so please refrain from merging. |
@pdawczak I've made the following changes to the PR:
Feel free to review and merge! :) |
@paulcsmith @jsteiner @germsvel Since this pretty much breaks ex_machina on Elixir 1.6, would you mind have a look at this PR, and perhaps make a new release for 1.6? |
Thanks for catching this @unnawut! |
Actually Apart from code formatting and adding an extra pattern matching for empty strings in the blame, nothing else has changed. So I think it's safe enough... |
@germsvel I have (two) good news and (one) bad news.... Good news # 1: Just to be sure here, I tested this PR against $ elixir --version
Erlang/OTP 20 [erts-9.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:10] [hipe] [kernel-poll:false]
Elixir 1.4.5
$ mix test
The database for ExMachina.TestRepo has been dropped
The database for ExMachina.TestRepo has been created
................................................................
Finished in 0.3 seconds
64 tests, 0 failures
Randomized with seed 544101 Good news # 2: The $ elixir --version
Erlang/OTP 19 [erts-8.3.5.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Elixir 1.3.4
$ mix test test/ex_machina/strategy_test.exs
The database for ExMachina.TestRepo has been dropped
The database for ExMachina.TestRepo has been created
..
Finished in 0.1 seconds
2 tests, 0 failures
Randomized with seed 468451 Bad news: Tests failed in other areas unrelated to this PR on $ elixir --version
Erlang/OTP 19 [erts-8.3.5.4] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Elixir 1.3.4
$ mix test
The database for ExMachina.TestRepo has been dropped
The database for ExMachina.TestRepo has been created
...........................................................
23:00:56.003 [error] GenServer ExMachina.Sequence terminating
** (UndefinedFunctionError) function List.pop_at/2 is undefined or private
(elixir) List.pop_at(["A", "B", "C"], 0)
(ex_machina) lib/ex_machina/sequence.ex:68: anonymous fn/4 in ExMachina.Sequence.next/2
(elixir) lib/agent/server.ex:16: Agent.Server.handle_call/3
(stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:647: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
1) test traverses a list each time it is called (ExMachina.SequenceTest)
test/ex_machina/sequence_test.exs:15
** (exit) exited in: GenServer.call(ExMachina.Sequence, {:get_and_update, #Function<1.78584464/1 in ExMachina.Sequence.next/2>}, 5000)
** (EXIT) an exception was raised:
** (UndefinedFunctionError) function List.pop_at/2 is undefined or private
(elixir) List.pop_at(["A", "B", "C"], 0)
(ex_machina) lib/ex_machina/sequence.ex:68: anonymous fn/4 in ExMachina.Sequence.next/2
(elixir) lib/agent/server.ex:16: Agent.Server.handle_call/3
(stdlib) gen_server.erl:615: :gen_server.try_handle_call/4
(stdlib) gen_server.erl:647: :gen_server.handle_msg/5
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
stacktrace:
(elixir) lib/gen_server.ex:604: GenServer.call/3
test/ex_machina/sequence_test.exs:16: (test)
2) test updates different sequences independently (ExMachina.SequenceTest)
test/ex_machina/sequence_test.exs:22
** (exit) exited in: GenServer.call(ExMachina.Sequence, {:update, #Function<3.78584464/1 in ExMachina.Sequence.reset/0>}, 5000)
** (EXIT) no process
stacktrace:
(elixir) lib/gen_server.ex:596: GenServer.call/3
test/ex_machina/sequence_test.exs:1: ExMachina.SequenceTest.__ex_unit__/2
3) test increments the sequence each time it is called (ExMachina.SequenceTest)
test/ex_machina/sequence_test.exs:10
** (exit) exited in: GenServer.call(ExMachina.Sequence, {:update, #Function<3.78584464/1 in ExMachina.Sequence.reset/0>}, 5000)
** (EXIT) no process
stacktrace:
(elixir) lib/gen_server.ex:596: GenServer.call/3
test/ex_machina/sequence_test.exs:1: ExMachina.SequenceTest.__ex_unit__/2
4) test can reset sequences (ExMachina.SequenceTest)
test/ex_machina/sequence_test.exs:40
** (exit) exited in: GenServer.call(ExMachina.Sequence, {:update, #Function<3.78584464/1 in ExMachina.Sequence.reset/0>}, 5000)
** (EXIT) no process
stacktrace:
(elixir) lib/gen_server.ex:596: GenServer.call/3
test/ex_machina/sequence_test.exs:1: ExMachina.SequenceTest.__ex_unit__/2
5) test let's you quickly create sequences (ExMachina.SequenceTest)
test/ex_machina/sequence_test.exs:29
** (exit) exited in: GenServer.call(ExMachina.Sequence, {:update, #Function<3.78584464/1 in ExMachina.Sequence.reset/0>}, 5000)
** (EXIT) no process
stacktrace:
(elixir) lib/gen_server.ex:596: GenServer.call/3
test/ex_machina/sequence_test.exs:1: ExMachina.SequenceTest.__ex_unit__/2
Finished in 0.3 seconds
64 tests, 5 failures
Randomized with seed 594070 ... in which My suggestion is to drop support for |
Awesome. Thanks for all the research @unnawut! That was super helpful. I think this is definitely good then. |
@unnawut I released version 2.2.0 of ex_machina today. Please open an issue if you find any problems, and thanks again for contributing! |
Thank you! |
Regex.split/3
's behavior was changed in Elixir 1.6 and causedExMachina.Strategy.underscore/1
to return an extra underscore and broke all factory names that are generated byExMachina.Strategy.name_from_struct/1
.This PR does
2 things1 thing:Fixes the regex insideExMachina.Strategy.underscore/1
to do negative lookbehind for a start of line.Use a singleRegex.replace/4
instead ofRegex.split/3
+Enum.join/2
which, according to Jose Valim, is equivalent.Macro.underscore/1
instead ofRegex.split/3
+Enum.join/2
to convert module name to snake case. (Thanks @vernomcrp for the suggestion!)Before
Elixir 1.5.3 (success)
Elixir 1.6.2 (failed)
After
Elixir 1.5.3 (success)
Elixir 1.6.2 (success)