Skip to content
This repository was archived by the owner on Nov 10, 2020. It is now read-only.

Commit d0dec77

Browse files
committed
Add unit tests, .travis.yml, prevent leaky globals, and update docs
1 parent d3a48b9 commit d0dec77

File tree

11 files changed

+184
-14
lines changed

11 files changed

+184
-14
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
path = vendor/neon
33
url = https://github.com/aw/neon-unofficial-mirror.git
44
ignore = dirty
5+
[submodule "vendor/picolisp-unit"]
6+
path = vendor/picolisp-unit
7+
url = https://github.com/aw/picolisp-unit.git

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: bash
2+
3+
before_install:
4+
- sudo apt-get update -qq
5+
- sudo apt-get install -y build-essential zlibc make autoconf libtool clang libxml2-dev picolisp libcurl4-openssl-dev
6+
7+
before_script:
8+
- ./build.sh
9+
- wget http://software-lab.de/picoLisp.tgz -O /tmp/picolisp.tgz
10+
- cd /tmp; tar -xf /tmp/picolisp.tgz
11+
- cd /tmp/picoLisp/src64 && make
12+
13+
script:
14+
- cd ${TRAVIS_BUILD_DIR} && /tmp/picoLisp/pil test.l

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## 0.30.1.6 (2015-03-24)
4+
5+
* Add unit tests and automated testing with travis-ci
6+
* Move MODULE_INFO to module.l
7+
* Update README.md
8+
* Prevent leaky namespace globals
9+
* Add update.sh script
10+
311
## 0.30.1.5 (2015-03-17)
412

513
* Version bump because it's 3am. I should sleep.

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HTTP(S) client for PicoLisp
22

3-
[![GitHub release](https://img.shields.io/github/release/aw/picolisp-https.svg)](https://github.com/aw/picolisp-https) [![Dependency](https://img.shields.io/badge/[deps] Neon-0.30.1-ff69b4.svg)](https://github.com/aw/neon-unofficial-mirror)
3+
[![GitHub release](https://img.shields.io/github/release/aw/picolisp-https.svg)](https://github.com/aw/picolisp-https) [![Build Status](https://travis-ci.org/aw/picolisp-https.svg?branch=master)](https://travis-ci.org/aw/picolisp-https) [![Dependency](https://img.shields.io/badge/[deps] Neon-0.30.1-ff69b4.svg)](https://github.com/aw/neon-unofficial-mirror)
44

55
This library can be used to make HTTP and HTTPS requests in [PicoLisp](http://picolisp.com), with support for authentication.
66

@@ -12,9 +12,10 @@ Please read [EXPLAIN.md](EXPLAIN.md) to learn more about PicoLisp and this HTTPS
1212
2. [Getting Started](#getting-started)
1313
3. [Usage](#usage)
1414
4. [Examples](#examples)
15-
5. [Alternatives](#alternatives)
16-
6. [Contributing](#contributing)
17-
7. [License](#license)
15+
5. [Testing](#testing)
16+
6. [Alternatives](#alternatives)
17+
7. [Contributing](#contributing)
18+
8. [License](#license)
1819

1920
# Requirements
2021

@@ -39,9 +40,15 @@ Once compiled, the shared library is symlinked as:
3940

4041
The `https.l` file searches for `lib/libneon.so`, relative to its current directory.
4142

43+
### Updating
44+
45+
This library uses git submodules, type this keep everything updated:
46+
47+
./update.sh
48+
4249
# Usage
4350

44-
All functions are publicly accessible and namespaced with `(symbols 'https)` (or the prefix: `https~`), but only the following are necessary:
51+
Only the following functions are exported publicly, and namespaced with `(symbols 'https)` (or the prefix: `https~`):
4552

4653
* **(uriparse Url)** parses a sanitized URL into its separate parts
4754
- `Url` _String_: a URL string to be parsed (does not encode the URL)
@@ -64,6 +71,8 @@ All functions are publicly accessible and namespaced with `(symbols 'https)` (or
6471
- `Filename` _String_ or _Flag (optional)_: can be a full path to a filename to store the HTTP Body content, the flag `T` to generate a random filename and store in a tmp dir (`~/.pil/tmp`), or `NIL` to return the Body in the `Response` list
6572
* **(req Method Url Headers Filename Body)**: performs an HTTP requeste using the `Method` you provide. The arguments to `req` are the same as the convenience methods list above.
6673

74+
> **Note:** These functions are not namespace [local symbols](http://software-lab.de/doc/refL.html#local), which means they would redefine symbols with the same name in the `'pico` namespace
75+
6776
### Notes
6877

6978
* A successful result will return a list. Failures return `NIL` or throw an `'InternalError`.
@@ -262,6 +271,12 @@ s>^J")
262271
" . "text/html; charset=UTF-8")) )
263272
```
264273

274+
# Testing
275+
276+
This library now comes with full [unit tests](https://github.com/aw/picolisp-unit). To run the tests, run:
277+
278+
./test.l
279+
265280
# Alternatives
266281

267282
The following are alternatives written in pure PicoLisp. They are limited by pipe/read syscalls and shell exec commands.

https.l

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
# https.l
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2015 Alexander Williams, Unscramble <[email protected]>
6+
17
(symbols 'https 'pico)
28

3-
[setq MODULE_INFO
4-
'(("name" "https")
5-
("version" "0.30.1.5")
6-
("summary" "HTTP(S) client for PicoLisp")
7-
("source" "https://github.com/aw/picolisp-https.git")
8-
("author" "Alexander Williams")
9-
("license" "MIT")
10-
("copyright" "(c) 2015 Alexander Williams, Unscramble <[email protected]>")
11-
("install" "build.sh") ]
9+
(load (pack (car (file)) "local.l"))
10+
11+
(load (pack (car (file)) "module.l"))
1212

1313
(setq
1414
*Https (pack (car (file)) "lib/libneon.so")

local.l

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# local.l
2+
#
3+
# The MIT License (MIT)
4+
#
5+
# Copyright (c) 2015 Alexander Williams, Unscramble <[email protected]>
6+
7+
(local MODULE_INFO *Https *Buffer_size *Headers)
8+
(local *NE_FEATURE_SSL *NE_FEATURE_ZLIB *NE_FEATURE_IPV6 *NE_FEATURE_LFS *NE_FEATURE_SOCKS)
9+
(local *NE_FEATURE_TS_SSL *NE_FEATURE_I18N *NE_FEATURE_SSPI)
10+
(local *NE_ABUFSIZ *NE_OK *NE_ERROR *NE_LOOKUP *NE_AUTH *NE_PROXYAUTH *NE_CONNECT)
11+
(local *NE_TIMEOUT *NE_FAILED *NE_RETRY *NE_REDIRECT)
12+
13+
# ffi
14+
(local ne-sock-init ne-version-string ne-has-support ne-get-error ne-uri-parse ne-uri-defaultport)
15+
(local ne-add-request-header ne-session-create ne-ssl-trust-default-ca ne-request-create)
16+
(local ne-begin-request ne-end-request ne-read-response-block ne-read-response-to-fd ne-set-request-body-buffer)
17+
(local ne-request-destroy ne-close-connection ne-session-destroy ne-get-status ne-response-header-iterate)
18+
(local ne-set-server-auth ne-forget-auth)
19+
20+
# internal
21+
(local throw-error create-session-request create-session parse-uri get-port set-auth-credentials)
22+
(local do-auth del-auth-credentials set-headers set-request-body request-dispatch download-file random-filename random-id)
23+
(local process-body link-response-block pack-body parse-response get-headers end-request-session end-session)
24+
(local begin-request end-request)

module.l

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[de MODULE_INFO
2+
("name" "https")
3+
("version" "0.30.1.6")
4+
("summary" "HTTP(S) client for PicoLisp")
5+
("source" "https://github.com/aw/picolisp-https.git")
6+
("author" "Alexander Williams")
7+
("license" "MIT")
8+
("copyright" "(c) 2015 Alexander Williams, Unscramble <[email protected]>")
9+
("install" "build.sh")
10+
("update" "update.sh") ]

test.l

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env pil
2+
3+
(load "vendor/picolisp-unit/unit.l")
4+
5+
(chdir "test/"
6+
(mapcar load (filter '((N) (sub? "test_" N)) (dir "."))) )
7+
8+
(unit~report)

test/test_https.l

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
(load "../https.l")
2+
3+
(prinl "^J Testing HTTP(S) client for PicoLisp^J")
4+
5+
(symbols 'https)
6+
7+
(setq
8+
*My_tests_are_order_dependent NIL
9+
*Https_output (req-get "https://google.com/404" NIL T)
10+
*Donate_page (req-get "http://software-lab.de/donate.html" NIL NIL)
11+
*404_page (req-head "https://google.com/404") )
12+
13+
[de test-uriparse-success ()
14+
(unit~assert-equal '("http" "test.url" "user:pass" 443 "/test/file.txt" "question=answer" "section")
15+
(uriparse "http://user:[email protected]:443/test/file.txt?question=answer#section")
16+
"Successfully parse a valid URI" ]
17+
18+
[de test-uriparse-fail ()
19+
(unit~assert-throws 'InternalError
20+
'(HttpsError . "Unable to parse URI")
21+
'(uriparse "http://test.url/test/[test]")
22+
"Fail to parse an invalid URI" ]
23+
24+
[de test-get-404 ()
25+
(unit~assert-includes '("Code" . 404)
26+
*Https_output
27+
"Returns a 404 error page from HTTPS request" ]
28+
29+
[de test-get-tempfile ()
30+
(unit~assert-includes '("Filename")
31+
*Https_output
32+
"Downloads the body into a temporary filename" ]
33+
34+
[de test-get-headers ()
35+
(unit~assert-kind-of 'List
36+
(cdr (assoc "Headers" *Https_output))
37+
"Returns a list of HTTP Headers" ]
38+
39+
[de test-get-body ()
40+
(unit~assert-includes '("Body")
41+
*Donate_page
42+
"Returns the body as a result (not a file) from HTTP request" ]
43+
44+
[de test-get-url ()
45+
(unit~assert-equal '("Url" . "http://software-lab.de/donate.html")
46+
(assoc "Url" *Donate_page)
47+
"Returns the URL of the donate page for PicoLisp" ]
48+
49+
[de test-head-nobody ()
50+
(unit~assert-nil (cdr (assoc "Body" *404_page))
51+
"HEAD requests don't return a body" ]
52+
53+
[de test-head ()
54+
(unit~assert-includes '("Code" . 404)
55+
*404_page
56+
"HEAD requests work" ]
57+
58+
[de test-post ()
59+
(unit~assert-includes '("Body")
60+
(req-post
61+
"http://requestb.in/10l0pw01"
62+
'(("Content-Type" . "application/json"))
63+
NIL
64+
"{\"Hello\":\"World\"}" )
65+
"POST requests work" ]
66+
67+
[unit~execute
68+
'(test-uriparse-success)
69+
'(test-uriparse-fail)
70+
'(test-get-404)
71+
'(test-get-tempfile)
72+
'(test-get-headers)
73+
'(test-get-body)
74+
'(test-get-url)
75+
'(test-head-nobody)
76+
'(test-head)
77+
'(test-post) ]

update.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2015 Alexander Williams, Unscramble <[email protected]>
4+
# MIT License
5+
6+
set -u
7+
set -e
8+
9+
git pull
10+
./build.sh

0 commit comments

Comments
 (0)