Skip to content

Commit f9be7c5

Browse files
author
Andy Newton
committedJan 6, 2018
first commit
0 parents  commit f9be7c5

21 files changed

+1412
-0
lines changed
 

‎.gitignore

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### JetBrains template
3+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
4+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5+
6+
*.iml
7+
8+
# User-specific stuff:
9+
.idea/**/workspace.xml
10+
.idea/**/tasks.xml
11+
.idea/dictionaries
12+
13+
# Sensitive or high-churn files:
14+
.idea/**/dataSources/
15+
.idea/**/dataSources.ids
16+
.idea/**/dataSources.xml
17+
.idea/**/dataSources.local.xml
18+
.idea/**/sqlDataSources.xml
19+
.idea/**/dynamic.xml
20+
.idea/**/uiDesigner.xml
21+
22+
# Gradle:
23+
.idea/**/gradle.xml
24+
.idea/**/libraries
25+
26+
# CMake
27+
cmake-build-debug/
28+
29+
# Mongo Explorer plugin:
30+
.idea/**/mongoSettings.xml
31+
32+
## File-based project format:
33+
*.iws
34+
35+
## Plugin-specific files:
36+
37+
# IntelliJ
38+
out/
39+
40+
# mpeltonen/sbt-idea plugin
41+
.idea_modules/
42+
43+
# JIRA plugin
44+
atlassian-ide-plugin.xml
45+
46+
# Cursive Clojure plugin
47+
.idea/replstate.xml
48+
49+
# Crashlytics plugin (for Android Studio and IntelliJ)
50+
com_crashlytics_export_strings.xml
51+
crashlytics.properties
52+
crashlytics-build.properties
53+
fabric.properties
54+

‎.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
- postgresql
3+
4+
before_script:
5+
- before_script.sh
6+
7+
script:
8+
- test.sh

‎LICENSE

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Copyright (c) 2015, ARIN Engineering <>
2+
3+
Permission to use, copy, modify, and/or distribute this software for any
4+
purpose with or without fee is hereby granted, provided that the above
5+
copyright notice and this permission notice appear in all copies.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
10+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
12+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
13+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14+

‎README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
PostgreSQL IP Address Utility Functions
2+
=======================================
3+
4+
This repository contains some utility functions for working with IPv4 and
5+
IPv6 addresses. These functions supplement and use the PostgreSQL's excellent
6+
set of builtin `inet` functions.
7+
8+
These functions do the following:
9+
* Getting a reverse DNS (.arpa) domain name from an `inet`.
10+
* Conversion to and from array representations of IP addresses.
11+
* Padding and unpadding of IP addresses for lexical comparison.

‎assert.sh

+186
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/bin/bash
2+
# assert.sh 1.1 - bash unit testing framework
3+
# Copyright (C) 2009-2015 Robert Lehmann
4+
#
5+
# http://github.com/lehmannro/assert.sh
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Lesser General Public License as published
9+
# by the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
20+
export DISCOVERONLY=${DISCOVERONLY:-}
21+
export DEBUG=${DEBUG:-}
22+
export STOP=${STOP:-}
23+
export INVARIANT=${INVARIANT:-}
24+
export CONTINUE=${CONTINUE:-}
25+
26+
args="$(getopt -n "$0" -l \
27+
verbose,help,stop,discover,invariant,continue vhxdic $*)" \
28+
|| exit -1
29+
for arg in $args; do
30+
case "$arg" in
31+
-h)
32+
echo "$0 [-vxidc]" \
33+
"[--verbose] [--stop] [--invariant] [--discover] [--continue]"
34+
echo "`sed 's/./ /g' <<< "$0"` [-h] [--help]"
35+
exit 0;;
36+
--help)
37+
cat <<EOF
38+
Usage: $0 [options]
39+
Language-agnostic unit tests for subprocesses.
40+
41+
Options:
42+
-v, --verbose generate output for every individual test case
43+
-x, --stop stop running tests after the first failure
44+
-i, --invariant do not measure timings to remain invariant between runs
45+
-d, --discover collect test suites only, do not run any tests
46+
-c, --continue do not modify exit code to test suite status
47+
-h show brief usage information and exit
48+
--help show this help message and exit
49+
EOF
50+
exit 0;;
51+
-v|--verbose)
52+
DEBUG=1;;
53+
-x|--stop)
54+
STOP=1;;
55+
-i|--invariant)
56+
INVARIANT=1;;
57+
-d|--discover)
58+
DISCOVERONLY=1;;
59+
-c|--continue)
60+
CONTINUE=1;;
61+
esac
62+
done
63+
64+
_indent=$'\n\t' # local format helper
65+
66+
_assert_reset() {
67+
tests_ran=0
68+
tests_failed=0
69+
tests_errors=()
70+
tests_starttime="$(date +%s%N)" # nanoseconds_since_epoch
71+
}
72+
73+
assert_end() {
74+
# assert_end [suite ..]
75+
tests_endtime="$(date +%s%N)"
76+
# required visible decimal place for seconds (leading zeros if needed)
77+
local tests_time="$( \
78+
printf "%010d" "$(( ${tests_endtime/%N/000000000}
79+
- ${tests_starttime/%N/000000000} ))")" # in ns
80+
tests="$tests_ran ${*:+$* }tests"
81+
[[ -n "$DISCOVERONLY" ]] && echo "collected $tests." && _assert_reset && return
82+
[[ -n "$DEBUG" ]] && echo
83+
# to get report_time split tests_time on 2 substrings:
84+
# ${tests_time:0:${#tests_time}-9} - seconds
85+
# ${tests_time:${#tests_time}-9:3} - milliseconds
86+
[[ -z "$INVARIANT" ]] \
87+
&& report_time=" in ${tests_time:0:${#tests_time}-9}.${tests_time:${#tests_time}-9:3}s" \
88+
|| report_time=
89+
90+
if [[ "$tests_failed" -eq 0 ]]; then
91+
echo "all $tests passed$report_time."
92+
else
93+
for error in "${tests_errors[@]}"; do echo "$error"; done
94+
echo "$tests_failed of $tests failed$report_time."
95+
fi
96+
tests_failed_previous=$tests_failed
97+
[[ $tests_failed -gt 0 ]] && tests_suite_status=1
98+
_assert_reset
99+
}
100+
101+
assert() {
102+
# assert <command> <expected stdout> [stdin]
103+
(( tests_ran++ )) || :
104+
[[ -z "$DISCOVERONLY" ]] || return
105+
expected=$(echo -ne "${2:-}")
106+
result="$(eval 2>/dev/null $1 <<< ${3:-})" || true
107+
if [[ "$result" == "$expected" ]]; then
108+
[[ -z "$DEBUG" ]] || echo -n .
109+
return
110+
fi
111+
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")"
112+
[[ -z "$result" ]] && result="nothing" || result="\"$result\""
113+
[[ -z "$2" ]] && expected="nothing" || expected="\"$2\""
114+
_assert_fail "expected $expected${_indent}got $result" "$1" "$3"
115+
}
116+
117+
assert_raises() {
118+
# assert_raises <command> <expected code> [stdin]
119+
(( tests_ran++ )) || :
120+
[[ -z "$DISCOVERONLY" ]] || return
121+
status=0
122+
(eval $1 <<< ${3:-}) > /dev/null 2>&1 || status=$?
123+
expected=${2:-0}
124+
if [[ "$status" -eq "$expected" ]]; then
125+
[[ -z "$DEBUG" ]] || echo -n .
126+
return
127+
fi
128+
_assert_fail "program terminated with code $status instead of $expected" "$1" "$3"
129+
}
130+
131+
_assert_fail() {
132+
# _assert_fail <failure> <command> <stdin>
133+
[[ -n "$DEBUG" ]] && echo -n X
134+
report="test #$tests_ran \"$2${3:+ <<< $3}\" failed:${_indent}$1"
135+
if [[ -n "$STOP" ]]; then
136+
[[ -n "$DEBUG" ]] && echo
137+
echo "$report"
138+
exit 1
139+
fi
140+
tests_errors[$tests_failed]="$report"
141+
(( tests_failed++ )) || :
142+
}
143+
144+
skip_if() {
145+
# skip_if <command ..>
146+
(eval $@) > /dev/null 2>&1 && status=0 || status=$?
147+
[[ "$status" -eq 0 ]] || return
148+
skip
149+
}
150+
151+
skip() {
152+
# skip (no arguments)
153+
shopt -q extdebug && tests_extdebug=0 || tests_extdebug=1
154+
shopt -q -o errexit && tests_errexit=0 || tests_errexit=1
155+
# enable extdebug so returning 1 in a DEBUG trap handler skips next command
156+
shopt -s extdebug
157+
# disable errexit (set -e) so we can safely return 1 without causing exit
158+
set +o errexit
159+
tests_trapped=0
160+
trap _skip DEBUG
161+
}
162+
_skip() {
163+
if [[ $tests_trapped -eq 0 ]]; then
164+
# DEBUG trap for command we want to skip. Do not remove the handler
165+
# yet because *after* the command we need to reset extdebug/errexit (in
166+
# another DEBUG trap.)
167+
tests_trapped=1
168+
[[ -z "$DEBUG" ]] || echo -n s
169+
return 1
170+
else
171+
trap - DEBUG
172+
[[ $tests_extdebug -eq 0 ]] || shopt -u extdebug
173+
[[ $tests_errexit -eq 1 ]] || set -o errexit
174+
return 0
175+
fi
176+
}
177+
178+
179+
_assert_reset
180+
: ${tests_suite_status:=0} # remember if any of the tests failed so far
181+
_assert_cleanup() {
182+
local status=$?
183+
# modify exit code if it's not already non-zero
184+
[[ $status -eq 0 && -z $CONTINUE ]] && exit $tests_suite_status
185+
}
186+
trap _assert_cleanup EXIT

‎before_script.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env sh
2+
psql -c "create extension if not exists dblink;"
3+
psql -f pgunit-1.0/PGUnit.sql

0 commit comments

Comments
 (0)
Please sign in to comment.