aboutsummaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
authorThiago de Arruda <tpadilha84@gmail.com>2014-07-27 14:01:22 -0300
committerThiago de Arruda <tpadilha84@gmail.com>2014-07-27 14:01:22 -0300
commit66bc13163398786c88e20b7cdd61c66978b4d3fb (patch)
tree8bc79d3fd093b5f5ec5d3417cda53ecdbc6cecf8 /test/unit
parent9550beda61ea74a2a9738e9c10423fa817b7b897 (diff)
parent974752c53b7c84a19f3028286b9ea88195eb3d4e (diff)
downloadrneovim-66bc13163398786c88e20b7cdd61c66978b4d3fb.tar.gz
rneovim-66bc13163398786c88e20b7cdd61c66978b4d3fb.tar.bz2
rneovim-66bc13163398786c88e20b7cdd61c66978b4d3fb.zip
Merge pull request #978 '[RDY] implement system() with pipes'
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/formatc.lua9
-rw-r--r--test/unit/helpers.moon4
-rw-r--r--test/unit/os/shell_spec.lua74
3 files changed, 82 insertions, 5 deletions
diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua
index e63ff369f2..dc1fb3fd9c 100644
--- a/test/unit/formatc.lua
+++ b/test/unit/formatc.lua
@@ -176,9 +176,10 @@ local function formatc(str)
end_at_brace = false
end
elseif typ == 'identifier' then
- -- static usually indicates an inline header function, which has no
- -- trailing ';', so we have to add a newline after the '}' ourselves.
- if token[1] == 'static' then
+ -- static and/or inline usually indicate an inline header function,
+ -- which has no trailing ';', so we have to add a newline after the
+ -- '}' ourselves.
+ if token[1] == 'static' or token[1] == 'inline' then
end_at_brace = true
end
elseif typ == 'preprocessor' then
@@ -217,6 +218,8 @@ local function standalone(...)
require "moonscript"
Preprocess = require("preprocess")
Preprocess.add_to_include_path('./../../src')
+ Preprocess.add_to_include_path('./../../build/include')
+ Preprocess.add_to_include_path('./../../.deps/usr/include')
input = Preprocess.preprocess_stream(arg[1])
local raw = input:read('*all')
diff --git a/test/unit/helpers.moon b/test/unit/helpers.moon
index 438f36811c..8064537d93 100644
--- a/test/unit/helpers.moon
+++ b/test/unit/helpers.moon
@@ -88,9 +88,9 @@ cimport './src/nvim/types.h'
-- take a pointer to a C-allocated string and return an interned
-- version while also freeing the memory
-internalize = (cdata) ->
+internalize = (cdata, len) ->
ffi.gc cdata, ffi.C.free
- return ffi.string cdata
+ return ffi.string cdata, len
cstr = ffi.typeof 'char[?]'
diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua
new file mode 100644
index 0000000000..870034aad9
--- /dev/null
+++ b/test/unit/os/shell_spec.lua
@@ -0,0 +1,74 @@
+-- not all operating systems support the system()-tests, as of yet.
+local allowed_os = {
+ Linux = true,
+ OSX = true,
+ BSD = true,
+ POSIX = true
+}
+
+if allowed_os[jit.os] ~= true then
+ return
+end
+
+local helpers = require('test.unit.helpers')
+local shell = helpers.cimport(
+ './src/nvim/os/shell.h',
+ './src/nvim/option_defs.h',
+ './src/nvim/os/event.h',
+ './src/nvim/misc1.h'
+)
+local ffi, eq, neq = helpers.ffi, helpers.eq, helpers.neq
+local intern = helpers.internalize
+local to_cstr = helpers.to_cstr
+local NULL = ffi.cast('void *', 0)
+
+describe('shell functions', function()
+ setup(function()
+ -- the logging functions are complain if I don't do this
+ shell.init_homedir()
+
+ shell.event_init()
+
+ -- os_system() can't work when the p_sh and p_shcf variables are unset
+ shell.p_sh = to_cstr('/bin/bash')
+ shell.p_shcf = to_cstr('-c')
+ end)
+
+ teardown(function()
+ shell.event_teardown()
+ end)
+
+ local function os_system(cmd, input)
+ local input_or = input and to_cstr(input) or NULL
+ local input_len = (input ~= nil) and string.len(input) or 0
+ local output = ffi.new('char *[1]')
+ local nread = ffi.new('size_t[1]')
+
+ local status = shell.os_system(to_cstr(cmd), input_or, input_len, output, nread)
+
+ return status, intern(output[0], nread[0])
+ end
+
+ describe('os_system', function()
+ it('can echo some output (shell builtin)', function()
+ local cmd, text = 'echo -n', 'some text'
+ local status, output = os_system(cmd .. ' ' .. text)
+ eq(text, output)
+ eq(0, status)
+ end)
+
+ it('can deal with empty output', function()
+ local cmd = 'echo -n'
+ local status, output = os_system(cmd)
+ eq('', output)
+ eq(0, status)
+ end)
+
+ it('can pass input on stdin', function()
+ local cmd, input = 'cat -', 'some text\nsome other text'
+ local status, output = os_system(cmd, input)
+ eq(input, output)
+ eq(0, status)
+ end)
+ end)
+end)