diff options
| -rw-r--r-- | test/unit/fixtures/posix.h | 11 | ||||
| -rw-r--r-- | test/unit/helpers.lua | 86 | ||||
| -rw-r--r-- | third-party/cmake/BuildLuarocks.cmake | 9 | 
3 files changed, 97 insertions, 9 deletions
| diff --git a/test/unit/fixtures/posix.h b/test/unit/fixtures/posix.h new file mode 100644 index 0000000000..f6f24cd9dc --- /dev/null +++ b/test/unit/fixtures/posix.h @@ -0,0 +1,11 @@ +#include <unistd.h> +#include <string.h> +#include <errno.h> +#include <sys/wait.h> +#include <stdlib.h> + +enum { +  kPOSIXErrnoEINTR = EINTR, +  kPOSIXErrnoECHILD = ECHILD, +  kPOSIXWaitWUNTRACED = WUNTRACED, +}; diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 20fdf6f85d..832cbcbd4a 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -238,7 +238,7 @@ if posix ~= nil then      wait = posix.wait,      exit = posix._exit,    } -else +elseif syscall ~= nil then    sc = {      fork = syscall.fork,      pipe = function() @@ -257,6 +257,90 @@ else      wait = syscall.wait,      exit = syscall.exit,    } +else +  cimport('./test/unit/fixtures/posix.h') +  sc = { +    fork = function() +      return tonumber(ffi.C.fork()) +    end, +    pipe = function() +      local ret = ffi.new('int[2]', {-1, -1}) +      ffi.errno(0) +      local res = ffi.C.pipe(ret) +      if (res ~= 0) then +        local err = ffi.errno(0) +        assert(res == 0, ("pipe() error: %u: %s"):format( +            err, ffi.string(ffi.C.strerror(err)))) +      end +      assert(ret[0] ~= -1 and ret[1] ~= -1) +      return ret[0], ret[1] +    end, +    read = function(rd, len) +      local ret = ffi.new('char[?]', len, {0}) +      local total_bytes_read = 0 +      ffi.errno(0) +      while total_bytes_read < len do +        local bytes_read = tonumber(ffi.C.read( +            rd, +            ffi.cast('void*', ret + total_bytes_read), +            len - total_bytes_read)) +        if bytes_read == -1 then +          local err = ffi.errno(0) +          if err ~= libnvim.kPOSIXErrnoEINTR then +            assert(false, ("read() error: %u: %s"):format( +                err, ffi.string(ffi.C.strerror(err)))) +          end +        elseif bytes_read == 0 then +          break +        else +          total_bytes_read = total_bytes_read + bytes_read +        end +      end +      return ffi.string(ret, total_bytes_read) +    end, +    write = function(wr, s) +      local wbuf = to_cstr(s) +      local total_bytes_written = 0 +      ffi.errno(0) +      while total_bytes_written < #s do +        local bytes_written = tonumber(ffi.C.write( +            wr, +            ffi.cast('void*', wbuf + total_bytes_written), +            #s - total_bytes_written)) +        if bytes_written == -1 then +          local err = ffi.errno(0) +          if err ~= libnvim.kPOSIXErrnoEINTR then +            assert(false, ("write() error: %u: %s"):format( +                err, ffi.string(ffi.C.strerror(err)))) +          end +        elseif bytes_written == 0 then +          break +        else +          total_bytes_written = total_bytes_written + bytes_written +        end +      end +      return total_bytes_written +    end, +    close = ffi.C.close, +    wait = function(pid) +      ffi.errno(0) +      while true do +        local r = ffi.C.waitpid(pid, nil, libnvim.kPOSIXWaitWUNTRACED) +        if r == -1 then +          local err = ffi.errno(0) +          if err == libnvim.kPOSIXErrnoECHILD then +            break +          elseif err ~= libnvim.kPOSIXErrnoEINTR then +            assert(false, ("waitpid() error: %u: %s"):format( +                err, ffi.string(ffi.C.strerror(err)))) +          end +        else +          assert(r == pid) +        end +      end +    end, +    exit = ffi.C._exit, +  }  end  local function gen_itp(it) diff --git a/third-party/cmake/BuildLuarocks.cmake b/third-party/cmake/BuildLuarocks.cmake index 6ab87b9bc3..9ea96b7cc5 100644 --- a/third-party/cmake/BuildLuarocks.cmake +++ b/third-party/cmake/BuildLuarocks.cmake @@ -172,12 +172,5 @@ if(USE_BUNDLED_BUSTED)    add_custom_target(nvim-client      DEPENDS ${HOSTDEPS_LIB_DIR}/luarocks/rocks/nvim-client) -  add_custom_command(OUTPUT ${HOSTDEPS_BIN_DIR}/luaposix -    COMMAND ${LUAROCKS_BINARY} -    ARGS build https://raw.githubusercontent.com/luaposix/luaposix/release-v33.4.0/luaposix-33.4.0-1.rockspec ${LUAROCKS_BUILDARGS} -    DEPENDS luarocks) -  add_custom_target(luaposix -    DEPENDS ${HOSTDEPS_BIN_DIR}/luaposix) - -  list(APPEND THIRD_PARTY_DEPS busted luacheck nvim-client luaposix) +  list(APPEND THIRD_PARTY_DEPS busted luacheck nvim-client)  endif() | 
