From 88611ace4c4ffbd409a462b79337e8e48645c8f6 Mon Sep 17 00:00:00 2001 From: Nat Quayle Nelson Date: Sat, 18 Feb 2023 11:56:49 -0700 Subject: [PATCH] tryProcess return null on failure --- src/kiss/Prelude.hx | 12 ++++++------ src/test/cases/BasicTestCase.hx | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/kiss/Prelude.hx b/src/kiss/Prelude.hx index 243a713..dd97f60 100644 --- a/src/kiss/Prelude.hx +++ b/src/kiss/Prelude.hx @@ -675,7 +675,7 @@ class Prelude { for (line in inputLines) { if (line.indexOf("\n") != -1) { handleError('newline is not allowed in the middle of a process input line: "${line.replace("\n", "\\n")}"'); - return ""; + return null; } } } @@ -703,7 +703,7 @@ class Prelude { p.stdout.readall().decode().trim(); } else { handleError('process $command $args failed:\n${p.stdout.readall().decode().trim() + p.stderr.readall().decode().trim();}'); - return ""; + return null; } } else { // The haxe extern for FileIO.readline() says it's a string, but it's not, it's bytes! @@ -735,7 +735,7 @@ class Prelude { p.stdout.readAll().toString().trim(); } else { handleError('process $command $args failed:\n${p.stdout.readAll().toString().trim() + p.stderr.readAll().toString().trim()}'); - return ""; + return null; } } else #end @@ -750,7 +750,7 @@ class Prelude { return output; } catch (e) { handleError('process $command $args failed: $e'); - return ""; + return null; } #elseif hxnodejs var p = if (inputLines != null) { @@ -769,12 +769,12 @@ class Prelude { var error:Buffer = p.stderr; if (error == null) error = Buffer.alloc(0); handleError('process $command $args failed:\n${output.toString() + error.toString()}'); - return ""; + return null; } return output; #else handleError("Can't run a subprocess on this target."); - return ""; + return null; #end } diff --git a/src/test/cases/BasicTestCase.hx b/src/test/cases/BasicTestCase.hx index 1d5f582..55c9a08 100644 --- a/src/test/cases/BasicTestCase.hx +++ b/src/test/cases/BasicTestCase.hx @@ -406,7 +406,9 @@ class BasicTestCase extends Test { #if (sys || hxnodejs) function testTryProcess() { - Assert.equals("", Prelude.tryProcess("_ThisCoMMaNDWillSURElYFaiLLLLLL", [], error->{return;})); + // tryProcess returns null on failure: + Assert.equals(null, Prelude.tryProcess("_ThisCoMMaNDWillSURElYFaiLLLLLL", [], error->{return;})); + // tryProcess returns output on success: Assert.equals("4.2.5", Prelude.tryProcess("haxe", ["--version"], error->{throw error;})); } #end