Adding test checking working Directory in childProcess (dotnet/corefx#28628)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Sat, 31 Mar 2018 01:31:57 +0000 (18:31 -0700)
committerGitHub <noreply@github.com>
Sat, 31 Mar 2018 01:31:57 +0000 (18:31 -0700)
Commit migrated from https://github.com/dotnet/corefx/commit/415e0aa8d5c9988ccb1cc73276bb0145f7901e11

src/libraries/CoreFx.Private.TestUtilities/src/System/Diagnostics/RemoteExecutorTestBase.cs
src/libraries/System.Diagnostics.Process/tests/ProcessStartInfoTests.cs

index ac039bd..bf8331c 100644 (file)
@@ -20,7 +20,7 @@ namespace System.Diagnostics
         public const int SuccessExitCode = 42;
 
         /// <summary>The name of the test console app.</summary>
-        protected static readonly string TestConsoleApp = "RemoteExecutorConsoleApp.exe";
+        protected static readonly string TestConsoleApp = Path.GetFullPath("RemoteExecutorConsoleApp.exe");
 
         /// <summary>Invokes the method from this assembly in another process using the specified arguments.</summary>
         /// <param name="method">The method to invoke.</param>
index ac99b18..5f6db29 100644 (file)
@@ -343,28 +343,21 @@ namespace System.Diagnostics.Tests
         }
 
         [Fact]
-        public void TestWorkingDirectoryProperty()
+        public void TestWorkingDirectoryPropertyDefaultCase()
         {
             CreateDefaultProcess();
 
             // check defaults
             Assert.Equal(string.Empty, _process.StartInfo.WorkingDirectory);
+        }
 
-            Process p = CreateProcessLong();
-            p.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
-
-            try
-            {
-                p.Start();
-                Assert.Equal(Directory.GetCurrentDirectory(), p.StartInfo.WorkingDirectory);
-            }
-            finally
-            {
-                if (!p.HasExited)
-                    p.Kill();
-
-                Assert.True(p.WaitForExit(WaitInMS));
-            }
+        [Fact]
+        public void TestWorkingDirectoryPropertyInChildProcess()
+        {
+            string workingDirectory = string.IsNullOrEmpty(Environment.SystemDirectory) ? TestDirectory : Environment.SystemDirectory ;
+            Assert.NotEqual(workingDirectory, Directory.GetCurrentDirectory());
+            var psi = new ProcessStartInfo { WorkingDirectory = workingDirectory };
+            RemoteInvoke(wd => { Assert.Equal(wd, Directory.GetCurrentDirectory()); return SuccessExitCode; }, workingDirectory, new RemoteInvokeOptions { StartInfo = psi }).Dispose();
         }
 
         [ActiveIssue(12696)]