Merge pull request #794 from urbit/remove-eny-from-tests

Rebuild the test support library so its easier and doesn't use entropy.
This commit is contained in:
Elliot Glaysher 2018-08-29 16:05:53 -07:00 committed by GitHub
commit eac6da579e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 141 additions and 151 deletions

View File

@ -1,5 +1,5 @@
/- asn1
/+ base64, der, primitive-rsa, *pkcs, *jose, tester
/+ base64, der, primitive-rsa, *pkcs, *jose
=, eyre
=* rsa primitive-rsa
::

View File

@ -1,20 +1,20 @@
/+ tester
/+ test-runner
/= all-tests
/^ (map path (list test-arm:tester))
/^ (map path (list test-arm:test-runner))
/: /===/tests
/* /test-gen/
::
|%
++ test-runner
|= [defer=? eny=@uvJ tests=(list test:tester)]
++ main
|= [defer=? tests=(list test:test-runner)]
^- tang
::
%- zing
%+ turn tests
|= [=path test-func=test-func:tester]
|= [=path test-func=test-func:test-runner]
^- tang
::
=/ test-results=tang (run-test path eny test-func)
=/ test-results=tang (run-test path test-func)
:: if :defer is set, produce errors; otherwise print them and produce ~
::
?: defer
@ -23,10 +23,10 @@
::
++ run-test
:: executes an individual test.
|= [pax=path eny=@uvJ test=test-func:tester]
|= [pax=path test=test-func:test-runner]
^- tang
=+ name=(spud pax)
=+ run=(mule |.((test eny)))
=+ run=(mule test)
?- -.run
%| :: the stack is already flopped for output?
;: weld
@ -50,7 +50,7 @@
:: +filter-tests-by-prefix
::
++ filter-tests-by-prefix
|= [prefix=path tests=(list test:tester)]
|= [prefix=path tests=(list test:test-runner)]
^+ tests
::
=/ prefix-length=@ud (lent prefix)
@ -73,11 +73,10 @@
:: use empty path prefix if unspecified
::
=/ prefix=path ?~(filter ~ pax.filter)
=/ entropy ?~(seed eny seed)
::
=/ filtered-tests=(list test:tester)
=/ filtered-tests=(list test:test-runner)
%+ filter-tests-by-prefix
prefix
(resolve-test-paths:tester all-tests)
(resolve-test-paths:test-runner all-tests)
::
(test-runner defer entropy filtered-tests)
(main defer filtered-tests)

35
lib/test.hoon Normal file
View File

@ -0,0 +1,35 @@
:: testing utilities meant to be directly used from files in %/tests
::
|%
:: +expect-eq: compares :expected and :actual and pretty-prints the result
::
++ expect-eq
|= [expected=vase actual=vase]
^- tang
::
=| result=tang
::
=? result !=(q.expected q.actual)
%+ weld result
^- tang
:~ [%palm [": " ~ ~ ~] [leaf+"expected" (sell expected) ~]]
[%palm [": " ~ ~ ~] [leaf+"actual" (sell actual) ~]]
==
::
=? result !(~(nest ut p.actual) | p.expected)
%+ weld result
^- tang
:~ :+ %palm [": " ~ ~ ~]
:~ [%leaf "failed to nest"]
(~(dunk ut p.actual) %actual)
(~(dunk ut p.expected) %expected)
== ==
result
:: +category: prepends a name to an error result; passes successes unchanged
::
++ category
|= [a=tape b=tang] ^- tang
?: =(~ b) ~ :: test OK
:- leaf+"in: '{a}'"
(turn b |=(c=tank rose+[~ " " ~]^~[c]))
--

View File

@ -1,6 +1,5 @@
/+ tester
/+ *test
=, ford
=, tester:tester
|%
:: +expect-schematic: assert a +schematic:ford is what we expect
::

63
lib/test/runner.hoon Normal file
View File

@ -0,0 +1,63 @@
|%
:: $test: a test with a fully resolved path
::
+$ test [=path func=test-func]
:: $test-arm: a test with a name (derived from its arm name in a test core)
::
+$ test-arm [name=term func=test-func]
:: $test-func: a single test, as a gate; sample is entropy, produces failures
::
+$ test-func (trap tang)
--
|%
:: +resolve-test-paths: add test names to file paths to form full identifiers
::
++ resolve-test-paths
|= paths-to-tests=(map path (list test-arm))
^- (list test)
::
%- zing
%+ turn ~(tap by paths-to-tests)
|= [=path test-arms=(list test-arm)]
^- (list test)
:: strip off leading 'tests' from :path
::
=. path
?> ?=(^ path)
?> ?=(%tests i.path)
t.path
:: for each test, add the test's name to :path
::
%+ turn test-arms
|= =test-arm
^- test
[(weld path /[name.test-arm]) func.test-arm]
:: +get-test-arms: convert test arms to functions and produce them
::
++ get-test-arms
|= [test-core-type=type test-core=*]
^- (list test-arm)
::
=/ arms=(list @tas) (sloe test-core-type)
::
%+ turn (skim arms has-test-prefix)
|= name=term
^- test-arm
::
=/ run-arm=[=type =nock]
~| [%failed-to-compile-test-arm name]
(~(mint ut test-core-type) p:!>(*tang) [%limb name])
::
:- name
^- test-func
::
|.
^- tang
((hard tang) .*(test-core nock.run-arm))
:: +has-test-prefix: does the arm define a test we should run?
::
++ has-test-prefix
|= a=term ^- ?
=((end 3 5 a) 'test-')
--

View File

@ -1,105 +0,0 @@
|%
:: $test: a test with a fully resolved path
::
+$ test [=path func=test-func]
:: $test-arm: a test with a name (derived from its arm name in a test core)
::
+$ test-arm [name=term func=test-func]
:: $test-func: a single test, as a gate; sample is entropy, produces failures
::
+$ test-func $-(@uvJ tang)
--
|%
:: +resolve-test-paths: add test names to file paths to form full identifiers
::
++ resolve-test-paths
|= paths-to-tests=(map path (list test-arm))
^- (list test)
::
%- zing
%+ turn ~(tap by paths-to-tests)
|= [=path test-arms=(list test-arm)]
^- (list test)
:: strip off leading 'tests' from :path
::
=. path
?> ?=(^ path)
?> ?=(%tests i.path)
t.path
:: for each test, add the test's name to :path
::
%+ turn test-arms
|= =test-arm
^- test
[(weld path /[name.test-arm]) func.test-arm]
:: +get-test-arms: convert test arms to functions and produce them
::
++ get-test-arms
|= [test-core-type=type test-core=*]
^- (list test-arm)
::
=/ arms=(list @tas) (sort (sloe test-core-type) aor)
::
%+ turn (skim arms has-test-prefix)
|= name=term
^- test-arm
::
?> (~(nest ut (~(peek ut test-core-type) %free 6)) & p:!>((init-test)))
::
~| [%failed-to-compile-test-arm name]
=/ run-arm=[=type =nock]
(~(mint ut test-core-type) p:!>(*tang) [%limb name])
::
:- name
^- test-func
::
|= eny=@uvJ
^- tang
((hard tang) .*(test-core(+6 (init-test eny)) nock.run-arm))
:: +has-test-prefix: does the arm define a test we should run?
::
++ has-test-prefix
|= a=term ^- ?
=((end 3 5 a) 'test-')
:: +init-test: data initialized on a per-test basis
::
++ init-test |=(eny=@uvJ ~(. tester eny))
:: +tester: main testing core with helper arms to be used in tests
::
:: TODO provide a lot more helper functions.
::
++ tester
|_ eny=@uvJ
:: +expect-eq: compares :expected and :actual and pretty-prints the result
::
++ expect-eq
|= [expected=vase actual=vase]
^- tang
::
=| result=tang
::
=? result !=(q.expected q.actual)
%+ weld result
^- tang
:~ [%palm [": " ~ ~ ~] [leaf+"expected" (sell expected) ~]]
[%palm [": " ~ ~ ~] [leaf+"actual" (sell actual) ~]]
==
::
=? result !(~(nest ut p.actual) | p.expected)
%+ weld result
^- tang
:~ :+ %palm [": " ~ ~ ~]
:~ [%leaf "failed to nest"]
(~(dunk ut p.actual) %actual)
(~(dunk ut p.expected) %expected)
== ==
result
:: +category: prepends a name to an error result; passes successes unchanged
::
++ category
|= [a=tape b=tang] ^- tang
?: =(~ b) ~ :: test OK
:- leaf+"in: '{a}'"
(turn b |=(c=tank rose+[~ " " ~]^~[c]))
--
--

View File

@ -1,5 +1,4 @@
/+ tester
/+ test-runner
/= test-core /!noun/
::
~& [%loading-test-arms %]
(get-test-arms:tester !>(test-core))
(get-test-arms:test-runner !>(test-core))

View File

@ -1,4 +1,4 @@
/+ base64, tester
/+ base64, *test
:: XX move to zuse
::
|%
@ -13,7 +13,7 @@
~(de base64 | &)
--
::
|_ _tester:tester
|%
++ test-base64
;: weld
%+ expect-eq

View File

@ -1,6 +1,6 @@
/- asn1
/+ der, tester
|_ _tester:tester
/+ der, *test
|%
++ test-asn1-der
=/ nul=spec:asn1 [%nul ~]
=/ int=spec:asn1 [%int 187]

View File

@ -1,8 +1,8 @@
/- asn1
/+ primitive-rsa, *pkcs, *jose, tester
/+ primitive-rsa, *pkcs, *jose, *test
=, eyre
=* rsa primitive-rsa
|_ _tester:tester
|%
++ test-jwk
:: rfc7638 section 3.1
=/ n

View File

@ -1,7 +1,7 @@
/- asn1
/+ primitive-rsa, *pkcs, tester
/+ primitive-rsa, *pkcs, *test
=* rsa primitive-rsa
|_ _tester:tester
|%
++ test-rsapem
:: ex from https://stackoverflow.com/a/19855935
=/ k1=key:rsa

View File

@ -1,6 +1,6 @@
/+ primitive-rsa, tester
/+ primitive-rsa, *test
=* rsa primitive-rsa
|_ _tester:tester
|%
++ test-rsakey
=/ primes=(list @)
:~ 2 3 5 7 11 13 17 19 23 29 31 37 41 43
@ -14,7 +14,7 @@
617 619 631 641 643 647 653 659 661 673 677 683 691 701
709 719 727 733 739 743 751
==
=/ k1 (new-key:rsa 2.048 eny)
=/ k1 (new-key:rsa 2.048 0xdead.beef)
::
=/ k2=key:rsa
=/ p 0x1837.be57.1286.bf6a.3cf8.4716.634f.ef85.f947.c654.da6e.e222.

View File

@ -1,4 +1,4 @@
/+ tester, test-ford
/+ *test, test-ford
::
/= clay-raw /: /===/sys/vane/clay /!noun/
::
@ -8,7 +8,7 @@
=/ test-pit=vase !>(..zuse)
=/ clay-gate (clay-raw test-pit)
::
|_ _tester:tester
|%
++ test-info ^- tang
::
=^ results1 clay-gate

View File

@ -1,4 +1,4 @@
/+ tester
/+ *test
::
/= ford-vane /: /===/sys/vane/ford /!noun/
::
@ -15,7 +15,7 @@
=/ test-pit=vase !>(..zuse)
=/ ford-gate (ford-vane test-pit)
::
|_ _tester:tester
|%
++ test-tear ^- tang
::
;: welp

View File

@ -1,4 +1,4 @@
/+ tester
/+ *test
::
/= jael-raw /: /===/sys/vane/jael
/!noun/
@ -7,7 +7,7 @@
=/ test-pit=vase !>(.)
=/ jael-gate (jael-raw test-pit)
::
|_ _tester:tester
|%
:: tests that galaxies try to listen to an ethereum node
::
++ test-init-as-galaxy ^- tang

View File

@ -1,8 +1,8 @@
/+ tester
/+ *test
::
=, contain
::
|_ _tester:tester
|%
++ test-basic-capped-queue
::
=| q=(capped-queue @u)

View File

@ -1,8 +1,8 @@
/+ tester
/+ *test
::
=, contain
::
|_ _tester:tester
|%
++ test-basic-clock
::
=| c=(clock @u tape)

View File

@ -16,7 +16,7 @@
:: these tests were written.
::
::
/+ tester
/+ *test
=, keccak:crypto
::
:: per bytelength, an example input.
@ -72,7 +72,7 @@
d79d.c266.f6a5.be6b.b0e4.a92e.ceeb.aeb1
==
::
|_ _tester:tester
|%
::
:: check a list of bytelength-answer pairs to see if
:: they match the output given by {hash} for the

View File

@ -1,5 +1,5 @@
/+ tester
|_ _tester:tester
/+ *test
|%
::TODO copy this:
:: https://github.com/ethereum/web3.js/blob/master/test/coder.encodeParam.js
::

View File

@ -31,8 +31,8 @@ You can then just run that individual test suite (and not the ones that are besi
So what is the structure of these test files? They contain a door, with arms starting with `++test-` or `++check-`. At minimum:
```
/+ tester
|_ tester-type:tester
/+ *test
|%
++ test-some-test
(expect-eq !>(4) !>(4))
--