Deterministic output for testing

28 views
Skip to first unread message

Julian Hyde

unread,
Jul 14, 2019, 4:24:37 AM7/14/19
to jline-users
I am using JLine3 in my application and I am trying to write some tests to ensure that a given input produces a given output. For example, for input

  1 + 2;

my application should produce the output

  1 + 2;
  = 1 + 2;
  val it = 3 : int

(The line '= 1 + 2;' is expected because JLine re-displays the input with a  '= ' prompt.)

Unfortunately the output is non-deterministic. Sometimes the output is as follows:

  = 1 + 2;
  1 + 2;
  val it = 3 : int

I think this happens because the pump (a thread that copies from input to output) is running slower than usual.

Is this non-determinism expected? Is there any way to make the results deterministic? How do other people test applications that use JLine?

Julian

Guillaume Nodet

unread,
Aug 11, 2019, 11:09:17 AM8/11/19
to jline...@googlegroups.com
You can test using the same stuff that JLine actually use in its own tests.

--
You received this message because you are subscribed to the Google Groups "jline-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jline-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jline-users/cf1761d5-9103-4828-b079-6986b99b91f0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Julian Hyde

unread,
Aug 12, 2019, 3:18:04 PM8/12/19
to jline...@googlegroups.com
Thanks; I’ll give that a try.

By the way, I found a workaround which is to sleep for 10 milliseconds at the start of the test to wait for classes to load[1]. With that workaround tests seem to run consistently in practice.

Julian

Reply all
Reply to author
Forward
0 new messages