[Mono-dev] System.Diagnostics.Process behaves differently in and outside of a NUnit test case

Ludovic Henry ludovic at xamarin.com
Thu Oct 15 11:47:43 UTC 2015


Hi Dan,

As I am currently working on the Process class, I am getting a look at your
bug.

Does setting  StandardOutputEncoding = Console.OutputEncoding on the
ProcessStartInfo passed to Start fixes your issue? This is the behaviour on
.NET, so this is the behaviour that we are going to adopt (at least for bug
compatibility).

Thank you! :)

Ludovic

---------- Forwarded message ---------
From: Dan Liew <dan at su-root.co.uk>
Date: Fri, 9 Oct 2015, 14:40
Subject: [Mono-dev] System.Diagnostics.Process behaves differently in and
outside of a NUnit test case
To: <mono-devel-list at lists.ximian.com>


Hi,

This is an issue that I was bitten by a while ago but I didn't post
here because I managed to work around it but it looks like something
inside mono changed between 3.12 and 4.0.4 which my broke my
workaround.

The issue basically is I observed my code failing when called from an
NUnit test but when run from an executable it would work fine. The
code in question [1] calls out to an external process using
``System.Diagnostics.Process`` where the standard input is redirected.
When running from an NUnit test a UTF-8 BOM gets sent to the process's
standard input and when running from an executable the UTF-8 BOM does
not get sent.

I looked at this again and I've noticed two things

* In System.Diagnostics.Process.Start_noshell() the encoding for the
writable end of the pipe connected to the child process's standard
input is taken from ``Console.Out.Encoding``. Is this really a good
idea? Depending on this global value seems like a bad idea and could
introduce weird race conditions if the Console.Out encoding is changed
in some way (e.g. ``Console.OutputEncoding = new
System.Text.UTF8Encoding(false);`` seems to do this and this the new
workaround I ended up using)

* When running in an executable the value of
``Console.Out.Encoding.emitUTF8Identifier`` is false but when running
in an NUnit test the value of
````Console.Out.Encoding.emitUTF8Identifier`` is true!
I'm not sure if this is Mono's or NUnit's fault but this seems very wrong
to me.

I've filled a bug at [2] and [3] but thought I'd post about it here
too as this issue seems partially tied to some of mono's internal
implementation details.

[1] https://bugzilla.xamarin.com/attachment.cgi?id=13247
[2] https://bugzilla.xamarin.com/show_bug.cgi?id=21374
[3] https://github.com/nunit/nunit/issues/881

Thanks,
Dan.
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20151015/eff6da87/attachment.html>


More information about the Mono-devel-list mailing list