Skip to content

Commit

Permalink
fix test failure
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 12, 2019
1 parent 20d32df commit e4b3c8a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
21 changes: 10 additions & 11 deletions lib/pure/os.nim
Expand Up @@ -1287,13 +1287,16 @@ proc moveFile*(source, dest: string) {.rtl, extern: "nos$1",
discard tryRemoveFile(dest)
raise

proc exitStatusLikeShell*(status: cint): cint {.noNimScript.} =
proc exitStatusLikeShell*(status: cint): cint =
## converts exit code from `c_system` into a shell exit code
if WIFSIGNALED(status):
# like the shell!
128 + WTERMSIG(status)
when defined(posix) and not weirdTarget:
if WIFSIGNALED(status):
# like the shell!
128 + WTERMSIG(status)
else:
WEXITSTATUS(status)
else:
WEXITSTATUS(status)
status

proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
tags: [ExecIOEffect], noNimScript.} =
Expand All @@ -1303,12 +1306,8 @@ proc execShellCmd*(command: string): int {.rtl, extern: "nos$1",
## line arguments given to program. The proc returns the error code
## of the shell when it has finished. The proc does not return until
## the process has finished. To execute a program without having a
## shell involved, use the `execProcess` proc of the `osproc`
## module.
when defined(posix):
result = exitStatusLikeShell(c_system(command))
else:
result = c_system(command)
## shell involved, use `osproc.execProcess`.
result = exitStatusLikeShell(c_system(command))

# Templates for filtering directories and files
when defined(windows) and not weirdTarget:
Expand Down
8 changes: 3 additions & 5 deletions tests/stdlib/tosproc.nim
@@ -1,10 +1,7 @@
discard """
output: ""
"""
# test the osproc module

import compiler/unittest_light
import std/special_paths
import "../.." / compiler/unittest_light

when defined(case_testfile): # compiled test file for child process
from posix import exitnow
Expand Down Expand Up @@ -75,7 +72,8 @@ else:
runTest("c_exit2_139", 139)
runTest("quit_139", 139)
runTest("exit_array", 1)
runTest("exit_recursion", SIGSEGV.int + 128) # bug #10273: was returning 0
when defined(posix): # on windows, -1073741571
runTest("exit_recursion", SIGSEGV.int + 128) # bug #10273: was returning 0

assertEquals exitStatusLikeShell(SIGSEGV), SIGSEGV + 128.cint

Expand Down

0 comments on commit e4b3c8a

Please sign in to comment.