proposal - improve ExUnix assert_receive

43 views
Skip to first unread message

gasp...@gmail.com

unread,
Aug 3, 2017, 6:02:35 AM8/3/17
to elixir-lang-core

Hi all!

I often watch to check if message is received in tests and then only do comparison.

assert_receive(^result, 1000, "msg")

and

assert_receive(result, 1000, "msg")
assert result == correct_data

are totally different. Because first one makes selective receive and provides less readable matching diff, actually.

And in second case I want to check that message is received in specified timerange and then have nice diff.

The problem:

- in second case compiler complains that match will always happen (which is true)

Proposal:

- change assert_receive to determine that there is no pinned variables in first argument and just make sure that any message is received?
- create separate assert_XXXX function that handles just that

Do you think it is useful? Any other ideas how this scenario can be implemented? Am I doing something totally wrong? :)

/Gaspar

José Valim

unread,
Aug 3, 2017, 6:53:27 AM8/3/17
to elixir-l...@googlegroups.com
The warning is a bug. "assert_receive(message, 100)" should be valid. Please open up a bug report.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/e018244f-4ff0-41a6-8d24-fb4976dfb6de%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

gasp...@gmail.com

unread,
Aug 3, 2017, 7:06:45 AM8/3/17
to elixir-lang-core, jose....@plataformatec.com.br
Thank you :) I thought I was doing something ideologically wrong :)


On Thursday, August 3, 2017 at 1:53:27 PM UTC+3, José Valim wrote:
The warning is a bug. "assert_receive(message, 100)" should be valid. Please open up a bug report.



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Thu, Aug 3, 2017 at 12:02 PM, <gasp...@gmail.com> wrote:

Hi all!

I often watch to check if message is received in tests and then only do comparison.

assert_receive(^result, 1000, "msg")

and

assert_receive(result, 1000, "msg")
assert result == correct_data

are totally different. Because first one makes selective receive and provides less readable matching diff, actually.

And in second case I want to check that message is received in specified timerange and then have nice diff.

The problem:

- in second case compiler complains that match will always happen (which is true)

Proposal:

- change assert_receive to determine that there is no pinned variables in first argument and just make sure that any message is received?
- create separate assert_XXXX function that handles just that

Do you think it is useful? Any other ideas how this scenario can be implemented? Am I doing something totally wrong? :)

/Gaspar

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

gasp...@gmail.com

unread,
Aug 3, 2017, 7:17:01 AM8/3/17
to elixir-lang-core, jose....@plataformatec.com.br
What about

refute_receive(msg, 100, "got message")

Should it just fail compiling? Because it does not make any sense. Either variable should be pinned or it should be _ in there.

Separate bug report?



On Thursday, August 3, 2017 at 1:53:27 PM UTC+3, José Valim wrote:
The warning is a bug. "assert_receive(message, 100)" should be valid. Please open up a bug report.



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Thu, Aug 3, 2017 at 12:02 PM, <gasp...@gmail.com> wrote:

Hi all!

I often watch to check if message is received in tests and then only do comparison.

assert_receive(^result, 1000, "msg")

and

assert_receive(result, 1000, "msg")
assert result == correct_data

are totally different. Because first one makes selective receive and provides less readable matching diff, actually.

And in second case I want to check that message is received in specified timerange and then have nice diff.

The problem:

- in second case compiler complains that match will always happen (which is true)

Proposal:

- change assert_receive to determine that there is no pinned variables in first argument and just make sure that any message is received?
- create separate assert_XXXX function that handles just that

Do you think it is useful? Any other ideas how this scenario can be implemented? Am I doing something totally wrong? :)

/Gaspar

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.

José Valim

unread,
Aug 3, 2017, 12:50:44 PM8/3/17
to gasp...@gmail.com, elixir-lang-core
Please mention the refute_receive one on the same report.



José Valim
Skype: jv.ptec
Founder and Director of R&D

gasp...@gmail.com

unread,
Aug 3, 2017, 12:54:36 PM8/3/17
to elixir-lang-core, gasp...@gmail.com, jose....@plataformatec.com.br
Here we go


should I try to fix it and send PR?
Reply all
Reply to author
Forward
0 new messages