Ver Fonte

[sys] Make `getCwd()` consistent between targets (#10461)

* Add slash to `Sys.getCwd()` on cs, lua, python

So that it matches other targets.

* Add test for trailing slash in `Sys.getCwd()`
tobil4sk há 3 anos atrás
pai
commit
f3161ae43b
4 ficheiros alterados com 10 adições e 4 exclusões
  1. 1 1
      std/cs/_std/Sys.hx
  2. 1 1
      std/lua/_std/Sys.hx
  3. 1 1
      std/python/_std/Sys.hx
  4. 7 1
      tests/sys/src/TestSys.hx

+ 1 - 1
std/cs/_std/Sys.hx

@@ -83,7 +83,7 @@ class Sys {
 	}
 
 	public static inline function getCwd():String {
-		return cs.system.io.Directory.GetCurrentDirectory();
+		return haxe.io.Path.addTrailingSlash(cs.system.io.Directory.GetCurrentDirectory());
 	}
 
 	public static inline function setCwd(s:String):Void {

+ 1 - 1
std/lua/_std/Sys.hx

@@ -89,7 +89,7 @@ class Sys {
 	}
 
 	public inline static function getCwd():String
-		return Misc.cwd();
+		return haxe.io.Path.addTrailingSlash(Misc.cwd());
 
 	public inline static function setCwd(s:String):Void
 		Misc.chdir(s);

+ 1 - 1
std/python/_std/Sys.hx

@@ -89,7 +89,7 @@ class Sys {
 	}
 
 	public static function getCwd():String {
-		return python.lib.Os.getcwd();
+		return haxe.io.Path.addTrailingSlash(python.lib.Os.getcwd());
 	}
 
 	public static function setCwd(s:String):Void {

+ 7 - 1
tests/sys/src/TestSys.hx

@@ -85,8 +85,14 @@ class TestSys extends TestCommandBase {
 		#end
 	}
 
+	function testGetCwd() {
+		final current = Sys.getCwd();
+		// ensure it has a trailing slash
+		Assert.notEquals(current, haxe.io.Path.removeTrailingSlashes(current));
+	}
+
 	#if !java
-	function testCwd() {
+	function testSetCwd() {
 		var cur = Sys.getCwd();
 		Sys.setCwd("../");
 		var newCwd = haxe.io.Path.join([cur, "../"]);