M .hgignore +2 -0
@@ 5,3 5,5 @@ syntax: glob
*.link
*.o
*.so
+./chicken/
+./sq
M README.md +15 -2
@@ 17,16 17,17 @@ Think of it like [yq][], but for S-expre
## Installation
-Use your distribution's package manager to install CHICKEN 5.2 or newer, then
+Use your distribution's package manager to install [CHICKEN 5.2][] or newer, then
run:
``` sh
-chicken-install -s sq
+chicken-install sq
```
Because sq calls jq internally, you will also need to install jq according to
the [download instructions][jq/download] for your platform.
+[CHICKEN 5.2]: https://code.call-cc.org/
[jq/download]: https://stedolan.github.io/jq/download/
## Usage
@@ 83,6 84,18 @@ obviously useless since sq works by send
[SRFI-180]: https://srfi.schemers.org/srfi-180/srfi-180.html
+## Development
+
+To build this program you can run `chicken-install -no-install`.
+
+To run the tests, install [shelltestrunner][] and run `chicken-install
+-no-install -test`
+
+[Nix][] users can enter a development shell with `nix-shell`.
+
+[shelltestrunner]: https://github.com/simonmichael/shelltestrunner
+[Nix]: https://nixos.org/
+
## Known Problems
- Parsing is slow for large JSON outputs generated by jq.
A => tests/flags.test +20 -0
@@ 0,0 1,20 @@
+$ ./sq -h
+>
+Usage: sq [-j] [-- <jq-args>] [<jq-expr>]
+
+$ ./sq --help
+>
+Usage: sq [-j] [-- <jq-args>] [<jq-expr>]
+
+$ ./sq --version
+> /^(\(egg\)|[0-9]+\.[0-9]+(-[0-9]+-[a-z0-9]+)?)$/
+
+$ ./sq -- -h
+> /jq - commandline JSON processor/
+
+$ ./sq -- --help
+> /See the manpage for more options/
+
+$ ./sq --not-a-real-flag
+>2 /jq: Unknown option --not-a-real-flag/
+>= 2
A => tests/input.test +98 -0
@@ 0,0 1,98 @@
+# scheme scalars
+<
+1 "a" null #f #t
+$ ./sq
+>
+1
+"a"
+null
+#f
+#t
+>= 0
+
+# json scalars
+<
+1 "a" null false true
+$ ./sq
+>
+1
+"a"
+null
+#f
+#t
+>= 0
+
+# scheme vectors
+<
+((key . "value"))
+#(1 2 3)
+$ ./sq
+((key . "value"))
+#(1 2 3)
+>= 0
+
+# json vectors
+<
+{"key": "value"}
+[1, 2, 3]
+$ ./sq
+((key . "value"))
+#(1 2 3)
+>= 0
+
+# output flags
+<
+#("a")
+$ ./sq
+>
+#("a")
+>= 0
+
+$ ./sq .[0]
+>
+"a"
+>= 0
+
+$ ./sq '.[0] + "bc"'
+>
+"abc"
+>= 0
+
+$ ./sq --json
+>
+[
+ "a"
+]
+>= 0
+
+$ ./sq -j
+>
+[
+ "a"
+]
+>= 0
+
+$ ./sq --json --compact-output
+>
+["a"]
+>= 0
+
+$ ./sq -j -c
+>
+["a"]
+>= 0
+
+$ ./sq -jc
+>
+["a"]
+>= 0
+
+$ ./sq --raw-output .[0]
+>
+a
+>= 0
+
+$ ./sq -r .[0]
+>
+a
+>= 0
A => tests/run.scm +23 -0
@@ 0,0 1,23 @@
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;;
+;;; Tests for the sourcehut extension.
+;;;
+;;; Copyright (c) 2019-2020 Evan Hanson
+;;;
+;;; See LICENSE for details.
+;;;
+
+(import (chicken format)
+ (chicken pathname)
+ (chicken process)
+ (chicken process-context))
+
+(set! (current-directory)
+ (normalize-pathname (make-pathname (program-name) "../..")))
+
+(assert (zero? (system "./sq </dev/null >/dev/null --help")))
+(assert (zero? (system "./sq </dev/null >/dev/null --version")))
+
+(condition-case (process-execute "shelltest" (list "tests"))
+ ((exn process)
+ (print "shelltestrunner v1.9 is required, skipping tests")))