8000 Fix TypeManager test for running on .NET Core under linux/OSX · pythonnet/pythonnet@9b74cce · GitHub
[go: up one dir, main page]

Skip to content

Commit 9b74cce

Browse files
author
Benoit Hudson
committed
Fix TypeManager test for running on .NET Core under linux/OSX
We can't check memory protections in an NUnit tests under Microsoft .NET runtimes. I was assuming that meant windows only, but the travis CI pointed out that it can mean linux as well.
1 parent 4096a95 commit 9b74cce

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/embed_tests/TestTypeManager.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,23 @@ public static void TestMemoryMapping()
3131
Assert.That(() => { Marshal.WriteInt64(page, 17); }, Throws.Nothing);
3232
Assert.That(Marshal.ReadInt64(page), Is.EqualTo(17));
3333

34-
// Mark it read-execute, now we can't write anymore.
35-
//
36-
// We can't actually test access protection under Windows, because
37-
// AccessViolationException is assumed to mean we're in a corrupted
38-
// state:
39-
// https://stackoverflow.com/questions/3469368/how-to-handle-accessviolationexception
34+
// Mark it read-execute. We can still read, haven't changed any values.
4035
mapper.SetReadExec(page, len);
4136
Assert.That(Marshal.ReadInt64(page), Is.EqualTo(17));
42-
if (Runtime.Runtime.OperatingSystem != Runtime.Runtime.OperatingSystemType.Windows)
37+
38+
// Test that we can't write.
39+
//
40+
// We can't actually test access protection under Microsoft
41+
// versions of .NET, because AccessViolationException is assumed to
42+
// mean we're in a corrupted state:
43+
// https://stackoverflow.com/questions/3469368/how-to-handle-accessviolationexception
44+
//
45+
// We can test under Mono but it throws NRE instead of AccessViolationException.
46+
//
47+
// We can't use compiler flags because we compile with MONO_LINUX
48+
// while running on the Microsoft .NET Core during continuous
49+
// integration tests.
50+
if (System.Type.GetType ("Mono.Runtime") != null)
4351
{
4452
// Mono throws NRE instead of AccessViolationException for some reason.
4553
Assert.That(() => { Marshal.WriteInt64(page, 73); }, Throws.TypeOf<System.NullReferenceException>());

0 commit comments

Comments
 (0)
0