aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-08-23 16:16:00 -0500
committerGanesh Viswanathan <dev@genotrance.com>2019-10-02 15:30:49 -0500
commitba2bd6e40a1a4b954fd0d508f5cc98d0f06d62bc (patch)
tree8812d2574b73eaaf35d05b99ac196cf57f43cf3c
parent182d473973294585a5348d6fc1d01dd209136a4c (diff)
downloadnimterop-ba2bd6e40a1a4b954fd0d508f5cc98d0f06d62bc.tar.gz
nimterop-ba2bd6e40a1a4b954fd0d508f5cc98d0f06d62bc.zip
Add getheader test
-rw-r--r--.travis.yml4
-rw-r--r--nimterop/types.nim24
-rw-r--r--tests/getheader.nims42
-rw-r--r--tests/lzma.nim41
4 files changed, 99 insertions, 12 deletions
diff --git a/.travis.yml b/.travis.yml
index f323941..e56a392 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,13 +6,13 @@ language: c
env:
- BRANCH=0.19.6
- - BRANCH=0.20.0
+ - BRANCH=0.20.2
- BRANCH=devel
cache:
directories:
- "$HOME/.choosenim/toolchains/nim-0.19.6"
- - "$HOME/.choosenim/toolchains/nim-0.20.0"
+ - "$HOME/.choosenim/toolchains/nim-0.20.2"
install:
# `set -u` failed for ubuntu: /home/travis/.travis/job_stages: line 107: secure: unbound variable
diff --git a/nimterop/types.nim b/nimterop/types.nim
index 5b4ad5f..709aa79 100644
--- a/nimterop/types.nim
+++ b/nimterop/types.nim
@@ -13,25 +13,29 @@ when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
type Time {.importc: "time_t", header: "<time.h>".} = distinct int64
elif defined(posix):
import posix
- type time_t* = Time
+ type
+ time_t* = Time
+ wchar_t* {.importc.} = object
else:
import std/time_t as time_t_temp
type time_t* = time_t_temp.Time
+ when defined(c):
+ # http://www.cplusplus.com/reference/cwchar/wchar_t/
+ # In C++, wchar_t is a distinct fundamental type (and thus it is
+ # not defined in <cwchar> nor any other header).
+ type
+ wchar_t* {.importc, header:"<cwchar>".} = object
+ elif defined(cpp):
+ type
+ wchar_t* {.importc.} = object
+
type
ptrdiff_t* = ByteAddress
type
va_list* {.importc, header:"<stdarg.h>".} = object
-when defined(c):
- # http://www.cplusplus.com/reference/cwchar/wchar_t/ In C++, wchar_t is a distinct fundamental type (and thus it is not defined in <cwchar> nor any other header).
- type
- wchar_t* {.importc, header:"<cwchar>".} = object
-elif defined(cpp):
- type
- wchar_t* {.importc.} = object
-
template enumOp*(op, typ, typout) =
proc op*(x: typ, y: int): typout {.borrow.}
proc op*(x: int, y: typ): typout {.borrow.}
@@ -75,4 +79,4 @@ template defineEnum*(typ) =
proc `/`*(x: typ, y: int): typ = `/`(x, y.typ)
proc `/`*(x: int, y: typ): typ = `/`(x.typ, y)
- proc `$` *(x: typ): string {.borrow.} \ No newline at end of file
+ proc `$` *(x: typ): string {.borrow.}
diff --git a/tests/getheader.nims b/tests/getheader.nims
new file mode 100644
index 0000000..57584a6
--- /dev/null
+++ b/tests/getheader.nims
@@ -0,0 +1,42 @@
+import strutils
+
+proc testCall(cmd, output: string, exitCode: int, delete = true) =
+ if delete:
+ rmDir("build/liblzma")
+ echo cmd
+ var
+ ccmd =
+ when defined(windows):
+ "cmd /c " & cmd
+ else:
+ cmd
+ (outp, exitC) = gorgeEx(ccmd)
+ echo outp
+ doAssert exitC == exitCode, $exitC
+ doAssert outp.contains(output), outp
+
+var
+ cmd = "nim c -f"
+ rcmd = " -r lzma.nim"
+ exp = "liblzma version = "
+
+when defined(linux):
+ testCall(cmd & rcmd, "No build files found", 1)
+
+ # stdlib
+ testCall(cmd & " -d:lzmaStd" & rcmd, exp, 0)
+ testCall(cmd & " -d:lzmaStd -d:lzmaStatic" & rcmd, exp, 0)
+
+ # git
+ testCall(cmd & " -d:lzmaGit" & rcmd, exp, 0)
+ testCall(cmd & " -d:lzmaGit -d:lzmaStatic" & rcmd, exp, 0, delete = false)
+
+ # git tag
+ testCall(cmd & " -d:lzmaGit -d:lzmaVersion=v5.2.0" & rcmd, exp & "5.2.0", 0)
+ testCall(cmd & " -d:lzmaGit -d:lzmaStatic -d:lzmaVersion=v5.2.0" & rcmd, exp & "5.2.0", 0, delete = false)
+ testCall("cd build/liblzma && git branch", "v5.2.0", 0, delete = false)
+
+ # dl
+ testCall(cmd & " -d:lzmaDL" & rcmd, "Need version", 1)
+ testCall(cmd & " -d:lzmaDL -d:lzmaVersion=v5.2.4" & rcmd, exp & "5.2.4", 0)
+ testCall(cmd & " -d:lzmaDL -d:lzmaStatic -d:lzmaVersion=v5.2.4" & rcmd, exp & "5.2.4", 0, delete = false)
diff --git a/tests/lzma.nim b/tests/lzma.nim
new file mode 100644
index 0000000..0cb92f5
--- /dev/null
+++ b/tests/lzma.nim
@@ -0,0 +1,41 @@
+import os, strutils
+
+import nimterop/[build, cimport]
+
+const
+ baseDir = currentSourcePath.parentDir()/"build/liblzma"
+
+static:
+ cDebug()
+
+getHeader(
+ "lzma.h",
+ giturl = "https://github.com/xz-mirror/xz",
+ dlurl = "https://github.com/xz-mirror/xz/archive/$1.zip",
+ outdir = baseDir,
+ conFlags = "--disable-xz --disable-xzdec --disable-lzmadec --disable-lzmainfo"
+)
+
+cPlugin:
+ import strutils
+
+ proc onSymbol*(sym: var Symbol) {.exportc, dynlib.} =
+ sym.name = sym.name.strip(chars = {'_'})
+
+cOverride:
+ type
+ lzma_internal = object
+ lzma_index = object
+ lzma_index_hash = object
+
+ lzma_options_lzma = object
+ lzma_stream_flags = object
+ lzma_block = object
+ lzma_index_iter = object
+
+when not defined(lzmaStatic):
+ cImport(lzmaPath, recurse = true, dynlib = "lzmaLPath")
+else:
+ cImport(lzmaPath, recurse = true)
+
+echo "liblzma version = " & $lzma_version_string() \ No newline at end of file