[wasm][filesystem] add arg to testharness for setting working dir (#42020)
authorTammy Qiu <tammy.qiu@yahoo.com>
Thu, 17 Sep 2020 20:44:33 +0000 (16:44 -0400)
committerGitHub <noreply@github.com>
Thu, 17 Sep 2020 20:44:33 +0000 (16:44 -0400)
* [wasm][tests] Fix failing System.IO.Tests.DirectoryInfo_Name.CurrentDirectory

Co-authored-by: Ankit Jain <radical@gmail.com>
eng/testing/tests.mobile.targets
src/libraries/System.IO.FileSystem/tests/DirectoryInfo/Name.cs
src/libraries/System.IO.FileSystem/tests/DirectoryInfo/test-dir/dummy.txt [new file with mode: 0644]
src/libraries/System.IO.FileSystem/tests/System.IO.FileSystem.Tests.csproj
src/mono/wasm/runtime-test.js

index e3d033b..0a3f5f4 100644 (file)
@@ -14,7 +14,7 @@
 
   <PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
     <!-- We need to set this in order to get extensibility on xunit category traits and other arguments we pass down to xunit via MSBuild properties -->
-    <RunScriptCommand>$HARNESS_RUNNER wasm test --engine=$(JSEngine) $(JSEngineArgs) --js-file=runtime.js -v --output-directory=$XHARNESS_OUT -- --run WasmTestRunner.dll $(AssemblyName).dll</RunScriptCommand>
+    <RunScriptCommand>$HARNESS_RUNNER wasm test --engine=$(JSEngine) $(JSEngineArgs) --js-file=runtime.js -v --output-directory=$XHARNESS_OUT --  $(RunTestsJSArguments) --run WasmTestRunner.dll $(AssemblyName).dll</RunScriptCommand>
   </PropertyGroup>
 
   <ItemGroup>
index 3002175..52e08f5 100644 (file)
@@ -8,7 +8,6 @@ namespace System.IO.Tests
     public class DirectoryInfo_Name : FileSystemTest
     {
         [Fact]
-        [ActiveIssue("https://github.com/dotnet/runtime/issues/39998", TestPlatforms.Browser)]
         public void CurrentDirectory()
         {
             var info = new DirectoryInfo(".");
diff --git a/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/test-dir/dummy.txt b/src/libraries/System.IO.FileSystem/tests/DirectoryInfo/test-dir/dummy.txt
new file mode 100644 (file)
index 0000000..e69de29
index 7115d41..4a921fc 100644 (file)
@@ -3,6 +3,8 @@
     <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
     <IncludeRemoteExecutor>true</IncludeRemoteExecutor>
     <TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix;$(NetCoreAppCurrent)-Browser</TargetFrameworks>
+
+    <RunTestsJSArguments>--working-dir=/test-dir</RunTestsJSArguments>
   </PropertyGroup>
   <ItemGroup>
     <Compile Include="Base\BaseGetSetAttributes.cs" />
              Link="Common\System\IO\TempFile.cs" />
     <Compile Include="$(CommonTestPath)System\IO\PathFeatures.cs"
              Link="Common\System\IO\PathFeatures.cs" />
+
+    <Content Include="DirectoryInfo\test-dir\dummy.txt"
+             Link="test-dir\dummy.txt" />
   </ItemGroup>
 </Project>
index 21b3f11..b3fbf5d 100644 (file)
@@ -119,6 +119,7 @@ setenv = {};
 runtime_args = [];
 enable_gc = true;
 enable_zoneinfo = false;
+working_dir='/';
 while (args !== undefined && args.length > 0) {
        if (args [0].startsWith ("--profile=")) {
                var arg = args [0].substring ("--profile=".length);
@@ -140,6 +141,10 @@ while (args !== undefined && args.length > 0) {
        } else if (args [0] == "--disable-on-demand-gc") {
                enable_gc = false;
                args = args.slice (1);
+       } else if (args [0].startsWith ("--working-dir=")) {
+               var arg = args [0].substring ("--working-dir=".length);
+               working_dir = arg;
+               args = args.slice (1);
        } else {
                break;
        }
@@ -191,6 +196,13 @@ var Module = {
                }
 
                config.loaded_cb = function () {
+                       let wds = FS.stat (working_dir);
+                       if (wds === undefined || !FS.isDir (wds.mode)) {
+                               fail_exec (`Could not find working directory ${working_dir}`);
+                               return;
+                       }
+
+                       FS.chdir (working_dir);
                        App.init ();
                };
                config.fetch_file_cb = function (asset) {