shrub/lib/ph.hoon

284 lines
6.4 KiB
Plaintext
Raw Normal View History

2019-02-06 05:21:41 +03:00
::
:::: /hoon/ph/lib
::
/- aquarium
=, aquarium
|%
:: Defines a complete integration test.
::
++ test-core
$_ ^?
|%
2019-02-12 22:26:48 +03:00
::
:: Unique name, used as a cache label.
::
2019-02-12 05:46:36 +03:00
++ label *term
2019-02-12 22:26:48 +03:00
::
:: List of ships that are part of the test.
::
:: We'll only hear effects from these ships, and only these will
:: be in the cache points.
::
2019-02-12 02:25:25 +03:00
++ ships *(list ship)
2019-02-12 22:26:48 +03:00
::
:: Called first to kick off the test.
::
++ start |~(now=@da *(quip ph-event _^?(..start)))
::
:: Called on every effect from a ship.
::
++ route |~([now=@da ship unix-effect] *(quip ph-event _^?(..start)))
2019-02-06 05:21:41 +03:00
--
::
++ ph-event
$% [%test-done p=?]
aqua-event
==
::
++ send-events-to
|= [who=ship what=(list unix-event)]
^- (list ph-event)
%+ turn what
|= ovo=unix-event
[%event who ovo]
::
++ init
|= who=ship
^- (list ph-event)
[%init-ship who]~
::
:: factor out send-events-to
::
++ dojo
|= [who=ship what=tape]
^- (list ph-event)
%+ send-events-to who
^- (list unix-event)
:~
[//term/1 %belt %ctl `@c`%e]
[//term/1 %belt %ctl `@c`%u]
[//term/1 %belt %txt ((list @c) what)]
[//term/1 %belt %ret ~]
==
::
2019-02-09 02:21:40 +03:00
++ insert-file
2019-02-15 04:18:04 +03:00
|= [who=ship pax=path txt=@t]
2019-02-09 02:21:40 +03:00
^- (list ph-event)
?> ?=([@ @ @ *] pax)
2019-02-15 04:18:04 +03:00
=/ file [/text/plain (as-octs:mimes:html txt)]
2019-02-09 02:21:40 +03:00
%+ send-events-to who
:~
[//sync/0v1n.2m9vh %into i.t.pax | [t.t.t.pax `file]~]
==
::
2019-02-09 06:18:38 +03:00
++ on-dojo-output
|= [who=ship her=ship ovo=unix-effect what=tape fun=$-($~ (list ph-event))]
2019-02-06 05:21:41 +03:00
^- (list ph-event)
2019-02-08 05:03:46 +03:00
?. =(who her)
2019-02-06 05:21:41 +03:00
~
2019-02-08 05:03:46 +03:00
?. ?=(%blit -.q.ovo)
~
?. %+ lien p.q.ovo
2019-02-06 05:21:41 +03:00
|= =blit:dill
?. ?=(%lin -.blit)
|
!=(~ (find what p.blit))
~
2019-02-09 06:18:38 +03:00
(fun)
::
++ expect-dojo-output
|= [who=ship her=ship ovo=unix-effect what=tape]
^- (list ph-event)
%- on-dojo-output
:^ who her ovo
:- what
|= ~
2019-02-06 05:21:41 +03:00
[%test-done &]~
2019-02-12 02:25:25 +03:00
::
2019-02-15 04:18:04 +03:00
++ on-ergo
|= [who=ship her=ship ovo=unix-effect fun=$-($~ (list ph-event))]
?. =(who her)
~
?. ?=(%ergo -.q.ovo)
~
(fun)
::
2019-02-12 05:46:36 +03:00
++ test-lib
|_ our=ship
++ compose-tests
|= [a=test-core b=test-core]
^- test-core
=/ done-with-a |
|%
::
:: Cache lookup label
::
2019-02-12 22:26:48 +03:00
++ label :((cury cat 3) label:a '--' label:b)
2019-02-12 05:46:36 +03:00
::
:: Union of ships in a and b
::
++ ships ~(tap in (~(uni in (silt ships.a)) (silt ships.b)))
::
:: Start with start of a
::
++ start
|= now=@da
^- (quip ph-event _..start)
=/ have-cache
2019-02-15 04:18:04 +03:00
(scry-aqua ? now /fleet-snap/[label:a]/noun)
2019-02-12 05:46:36 +03:00
~& [%have-cache label:a have-cache]
?: have-cache
=. done-with-a &
=/ restore-event [%restore-snap label:a]
=^ events-start b (start:b now)
[[restore-event events-start] ..start]
=^ events a (start:a now)
2019-02-12 02:25:25 +03:00
[events ..start]
2019-02-12 05:46:36 +03:00
::
:: Keep going on a until it's done. If success, go to b.
::
:: In theory, we should be able to just swap out the whole core
:: for b, but in practice the types are hard, and we generally
:: try to avoid changing the structure of a core in the middle
:: like that.
::
++ route
|= [now=@da who=ship ovo=unix-effect]
^- (quip ph-event _..start)
?: done-with-a
=^ events b (route:b now who ovo)
[events ..start]
=^ events a (route:a now who ovo)
=+ ^- [done=(list ph-event) other-events=(list ph-event)]
%+ skid events
|= e=ph-event
=(%test-done -.e)
?~ done
[other-events ..start]
?> ?=(%test-done -.i.done)
?. p.i.done
[[%test-done |]~ ..start]
=. done-with-a &
=/ snap-event [%snap-ships label:a ships:a]
=^ events-start b (start:b now)
[(welp other-events [snap-event events-start]) ..start]
--
::
2019-02-12 02:53:23 +03:00
:: Don't use directly, or else you might not have a parent.
::
:: Consider ++galaxy, ++star, ++planet, and ++ship-with-ancestors.
::
++ raw-ship
|= her=ship
2019-02-12 02:25:25 +03:00
^- test-core
|%
2019-02-12 22:26:48 +03:00
++ label (cat 3 'init-' (scot %p her))
2019-02-12 02:53:23 +03:00
++ ships ~[her]
2019-02-12 02:25:25 +03:00
++ start
2019-02-12 05:46:36 +03:00
|= now=@da
2019-02-12 02:25:25 +03:00
^- (quip ph-event _..start)
2019-02-12 02:53:23 +03:00
[(init her) ..start]
2019-02-12 02:25:25 +03:00
::
++ route
2019-02-12 05:46:36 +03:00
|= [now=@da who=ship ovo=unix-effect]
2019-02-12 02:25:25 +03:00
^- (quip ph-event _..start)
:_ ..start
%- zing
2019-02-12 02:53:23 +03:00
:: This is a pretty bad heuristic, but in general galaxies will
:: hit the first of these cases, and other ships will hit the
:: second.
::
2019-02-12 02:25:25 +03:00
:~
%- on-dojo-output
2019-02-12 02:53:23 +03:00
:^ her who ovo
:- "+ /{(scow %p her)}/base/2/web/testing/udon"
2019-02-12 02:25:25 +03:00
|= ~
2019-02-12 02:53:23 +03:00
[%test-done &]~
2019-02-12 02:25:25 +03:00
::
%- on-dojo-output
2019-02-12 02:53:23 +03:00
:^ her who ovo
:- "is your neighbor"
2019-02-12 02:25:25 +03:00
|= ~
[%test-done &]~
==
--
2019-02-12 22:26:48 +03:00
::
2019-02-12 02:53:23 +03:00
++ galaxy
|= her=ship
?> =(%czar (clan:title her))
(raw-ship her)
::
++ star
|= her=ship
?> =(%king (clan:title her))
%+ compose-tests (galaxy (^sein:title her))
(raw-ship her)
::
++ planet
|= her=ship
?> =(%duke (clan:title her))
%+ compose-tests (star (^sein:title her))
(raw-ship her)
::
++ ship-with-ancestors
|= her=ship
%. her
?- (clan:title her)
%czar galaxy
%king star
%duke planet
%earl ~|(%moon-not-implemented !!)
%pawn ~|(%comet-not-implemented !!)
==
2019-02-15 04:18:04 +03:00
::
2019-02-15 04:36:30 +03:00
:: Touches /sur/aquarium/hoon on the given ship.
::
:: You must have started the ship or this will fail.
::
++ touch-file
|= her=ship
^- test-core
=| warped=@t
|%
++ label %touch-file
++ ships ~
++ start
|= now=@da
^- (pair (list ph-event) _..start)
=/ pax
/(scot %p our)/home/(scot %da now)/sur/aquarium/hoon
=. warped (cat 3 '=> . ' .^(@t %cx pax))
:_ ..start
%- zing
:~ (dojo her "|mount %")
(insert-file her pax warped)
==
::
++ route
|= [now=@da who=ship ovo=unix-effect]
^- (quip ph-event _..start)
:_ ..start
%- zing
:~ %- on-ergo
:^ her who ovo
|= $~
=/ pax /i/[(scot %p her)]/home/(scot %da now)/sur/aquarium/hoon/noun
?: =(warped (need (scry-aqua (unit @) now pax)))
[%test-done &]~
~& %not-done-yet
~
==
--
::
2019-02-15 04:18:04 +03:00
++ scry-aqua
|* [a=mold now=@da pax=path]
.^ a
%gx
(scot %p our)
%aqua
(scot %da now)
pax
==
2019-02-12 05:46:36 +03:00
--
2019-02-06 05:21:41 +03:00
--