Skip to content

Commit

Permalink
Test coverage, makefile target to run script to fetch test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanogilvie committed Jan 24, 2020
1 parent 0692d64 commit 8eba01e
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 2 deletions.
7 changes: 6 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ install-doc: doc
$(INSTALL_DATA) $$i $(DESTDIR)$(mandir)/mann ; \
done

test: binaries libraries
test: binaries libraries tests/JSONTestSuite/test_parsing
$(TCLSH) `@CYGPATH@ $(srcdir)/tests/all.tcl` $(TESTFLAGS) \
-load "package ifneeded ${PACKAGE_NAME} ${PACKAGE_VERSION} \
[list load `@CYGPATH@ $(PKG_LIB_FILE)` $(PACKAGE_NAME)]"
Expand All @@ -253,6 +253,11 @@ test_valgrind_full: binaries libraries
-load "package ifneeded ${PACKAGE_NAME} ${PACKAGE_VERSION} \
[list load `@CYGPATH@ $(PKG_LIB_FILE)` $(PACKAGE_NAME)]"

tests/JSONTestSuite/test_parsing: binaries libraries
$(TCLSH) `@CYGPATH@ $(srcdir)/fetch_test_cases.tcl` \
-load "package ifneeded ${PACKAGE_NAME} ${PACKAGE_VERSION} \
[list load `@CYGPATH@ $(PKG_LIB_FILE)` $(PACKAGE_NAME)]"

benchmark: binaries libraries
$(TCLSH) `@CYGPATH@ $(srcdir)/bench/run.tcl` $(TESTFLAGS)

Expand Down
7 changes: 7 additions & 0 deletions tests/omap.test
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ test omap-13.3 {iteration result is a dict, 2 entry} -body { #<<<
} -result {{"a":1,"a2":11,"bb":2,"bb2":12,"ccc":3,"ccc2":13}}
#>>>

test omap-20.5 {too few args} -body { #<<<
json omap x {false}
} -cleanup {
unset -nocomplain x
} -returnCodes error -result {Wrong # of arguments. Must be "omap varlist datalist ?varlist datalist ...? script"}
#>>>

::tcltest::cleanupTests
return

Expand Down
32 changes: 31 additions & 1 deletion tests/pretty.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ package require parse_args
namespace path {::rl_json ::parse_args}

test pretty-1.1 {Basic pretty-print} -body { #<<<
json pretty {{"foo":null,"hello, world":"bar","This is a much longer key":["str",123,123.4,true,false,null,{"inner": "obj"}]}}
json pretty {{"foo":null,"empty":{},"emptyarr":[],"hello, world":"bar","This is a much longer key":["str",123,123.4,true,false,null,{"inner": "obj"}]}}
} -result {{
"foo": null,
"empty": {},
"emptyarr": [],
"hello, world": "bar",
"This is a much longer key": [
"str",
Expand All @@ -25,6 +27,34 @@ test pretty-1.1 {Basic pretty-print} -body { #<<<
]
}}
#>>>
test pretty-1.1 {Basic pretty-print, different indent} -body { #<<<
json pretty {{"foo":null,"empty":{},"emptyarr":[],"hello, world":"bar","This is a much longer key":["str",123,123.4,true,false,null,{"inner": "obj"}]}} " "
} -result {{
"foo": null,
"empty": {},
"emptyarr": [],
"hello, world": "bar",
"This is a much longer key": [
"str",
123,
123.4,
true,
false,
null,
{
"inner": "obj"
}
]
}}
#>>>
test pretty-2.1 {too few args} -body { #<<<
json pretty
} -returnCodes error -result {Wrong # of arguments. Must be "pretty json_val ?indent?"}
#>>>
test pretty-2.2 {too many args} -body { #<<<
json pretty {"foo"} 8 bar
} -returnCodes error -result {Wrong # of arguments. Must be "pretty json_val ?indent?"}
#>>>

::tcltest::cleanupTests
return
Expand Down
4 changes: 4 additions & 0 deletions tests/string.test
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ test string-1.7 {Create a json string, template literal} -body { #<<<
json string "~L:~S:foo"
} -result {"~L:~S:foo"}
#>>>
test string-1.8 {Create a json string, undef} -body { #<<<
json string "~X:foo"
} -result {"~X:foo"}
#>>>
test string-2.1 {Too few args} -body { #<<<
set code [catch {
json string
Expand Down
18 changes: 18 additions & 0 deletions tests/template.test
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@ try { # Check string quoting
unset -nocomplain c char expect range i special
}

test template-5.1 {Not quite a template} -body { #<<<
json template {
{
"foo": "~X:bar",
"~s:bar": null
}
}
} -result {{"foo":"~X:bar","~s:bar":null}}
#>>>
test template-6.1 {too few args} -body { #<<<
json template
} -returnCodes error -result {Wrong # of arguments. Must be "template json_template ?source_dict?"}
#>>>
test template-6.2 {too many args} -body { #<<<
json template {"~S:foo"} bar baz
} -returnCodes error -result {Wrong # of arguments. Must be "template json_template ?source_dict?"}
#>>>

::tcltest::cleanupTests
return

Expand Down
130 changes: 130 additions & 0 deletions tests/unset.test
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,136 @@ test unset-6.4 {Unset an element in an array, end-relative, 2 beyond end} -setup
unset -nocomplain json
} -result {{"foo":["a","b","c"]}}
#>>>
test unset-7.1 {Unset an element in an array, end-relative} -setup { #<<<
set json {
{
"foo": ["a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo end-1 1
set json
} -cleanup {
unset -nocomplain json
} -result {{"foo":["a",["1","3"],"c"]}}
#>>>
test unset-7.2 {Unset an element in an array, end-relative, invalid} -setup { #<<<
set json {
{
"foo": ["a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo end/1 1
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Expected an integer index or end(+/-integer)?, got end/1}
#>>>
test unset-7.3 {Unset an element in an array, end-relative, invalid} -setup { #<<<
set json {
{
"foo": ["a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo en 1
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Expected an integer index or end(+/-integer)?, got en}
#>>>
test unset-7.4 {Unset an element in an array, end-relative, invalid} -setup { #<<<
set json {
{
"foo": ["a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo end-1x 1
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Expected an integer index or end(+/-integer)?, got end-1x}
#>>>
test unset-7.5 {Unset an element in an array, invalid} -setup { #<<<
set json {
{
"foo": ["a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo -1 1
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Path element "foo -1" doesn't exist}
#>>>
test unset-7.6 {Unset an element in an array, invalid} -setup { #<<<
set json {
{
"foo": ["a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo 4 1
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Path element "foo 4" doesn't exist}
#>>>
test unset-7.7 {Unset an element in an array, invalid} -setup { #<<<
set json {
{
"foo": ["~S:a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo 0 1
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Attempt to index into atomic type string at path "foo 0 1"}
#>>>
test unset-7.8 {Unset an element in an array, invalid} -setup { #<<<
set json {
{
"foo": ["~S:a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo 1 end/1
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Expected an integer index or end(+/-integer)?, got end/1}
#>>>
test unset-7.9 {Unset an element in an array, invalid} -setup { #<<<
set json {
{
"foo": ["~S:a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo 1 en
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Expected an integer index or end(+/-integer)?, got en}
#>>>
test unset-7.10 {Unset an element in an array, invalid} -setup { #<<<
set json {
{
"foo": ["~S:a", ["1","2","3"], "c"]
}
}
} -body {
json unset json foo 1 end-1x
set json
} -cleanup {
unset -nocomplain json
} -returnCodes error -result {Expected an integer index or end(+/-integer)?, got end-1x}
#>>>

::tcltest::cleanupTests
return
Expand Down

0 comments on commit 8eba01e

Please sign in to comment.