a few basic tests

This commit is contained in:
Ubuntu 2014-08-28 01:37:29 +00:00
parent f7d338ab9c
commit e066bc2148
4 changed files with 422 additions and 0 deletions

73
main/app/test/app.js Normal file
View File

@ -0,0 +1,73 @@
$(function() {
$tests = $("#tests")
runtest = function(name) {
test = $(name)
test.attr('disabled', true)
test.addClass('disabled')
window.urb.send({
appl:"test",
data:{test:name}
}, function(err,res) {
test.attr('disabled', false)
test.removeClass('disabled')
_test = {
name: name,
result: res.data
}
console.log('set it')
console.log(_test)
$tests.prepend(renderTest(_test))
})
}
renderTest = function(test) {
css = "test"
if(test.pending == true)
css += " pending"
$_test = $("<div class='"+css+"' id="+test.name+" onclick='runtest(\""+test.name+"\")'></div>")
$_test.append("<div class='name'>"+test.name+"</div>")
$_test.append("<div class='result'>"+JSON.stringify(test.result)+"</div>")
return $_test
}
renderTests = function(testlist) {
console.log("renderTests: "+testlist)
$tests.html("")
for(i in testlist) {
$tests.append(renderTest(testlist[i]))
}
}
renderError = function(error) {
$tests.html("<div class='error'>Sorry! There was an error fetching from Test: "+error+"</div>")
}
window.urb.subscribe({
appl:"test",
path:"/tests"
}, function(err,res) {
console.log('subscr')
console.log(arguments)
if (res.data.ok)
return
if(err)
renderTests(err)
else
{
if(res.data) {
if(res.data) {
renderTests(res.data)
}
else
{
renderTests("unknown error")
}
}
}
})
})

237
main/app/test/core.hook Normal file
View File

@ -0,0 +1,237 @@
:: Test suite
::
:: runnable from unix with command:
:: curl http://localhost:8080/gog/test/all-tests
::
:::: /hook/core/test/app
::
/? 314 :: need urbit 314
/= front /:/%%/front:/hymn/ :: load front page
::
:::: structures
::
|% :: structures
++ axle ,[%0 tests=(map term test)] :: application state
++ gilt :: subscription frame
$% [%json p=json] :: json data
[%html p=@t] :: html text
[%hymn p=manx] :: html tree
[%mime p=mite q=octs] :: mime data
== ::
++ gift :: output action
$% [%rust gilt] :: total update
[%mean p=ares] :: message failure
[%nice ~] :: succeed
== ::
++ hasp ,[p=ship q=term] :: see %gall
++ move ,[p=bone q=(mold note gift)] :: output operation
++ result :: test result
$% [%mean p=ares] :: failure
[%nice ~] :: success
== ::
++ note :: system request
$% $: %g :: to %ames
$% [%mess p=hasp q=ship r=cage] ::
== == == ::
++ test :: test template
$_ ^? |% ::
++ poke |+([bone ship] [_(list move) +>]) :: start test
++ pour |+([bone path *] [_(list move) +>]) :: system response
-- ::
-- ::
!:
:::: program
::
|_ $: hid=hide :: system state
axle :: custom state
==
++ et :: tests
|%
++ tests-json
%- jobe
%+ turn (~(tap by tests))
|= [nam=@t tes=test]
:- nam
%- jobe
^- (list ,[@t json])
~[[%name %s nam] [%result %s %untested]]
++ succeed
^- test
|%
++ poke
|+ [ost=bone you=ship]
^- [(list move) _+>]
[[ost %give %nice ~]~ +>.$]
++ pour
|+ [ost=bone pax=path sih=*]
^- [(list move) _+>]
!!
--
++ poke-local
^- test
=> |%
++ sign ,[%g result]
--
|%
++ poke
|+ [ost=bone you=ship]
^- [(list move) _+>]
:_ +>.$ :_ ~
:* ost %pass /poke-local %g
%mess [our.hid %test] you %json
!> (joba %test %s %bad-test-name)
==
++ pour
|+ [ost=bone pax=path sih=*]
^- [(list move) _+>]
:_ +>.$
=+ sih=((soft sign) sih)
:_ ~ :+ ost %give
?~ sih [%mean ~ %poke-local-pour-bad-sign ~]
?- +<.u.sih
%nice [%mean ~ %poke-local-pour-unexpected-nice ~]
%mean
?: ?=([~ %bad-test ~] p.u.sih)
[%nice ~]
[%mean ~ %poke-local-pour-unexpected-mean ~]
==
--
++ ze
^- test
|%
++ poke
|+ [ost=bone you=ship]
^- [(list move) _+>]
:_ +>.$ :_ ~
=+ ^= zez
%+ ~(axel ^ze lat.hid *dome *rang)
lat.hid
[%& [0v0 0v0] [/hello %ins 'hello, world']~]
=+ `[l=@da d=dome r=rang]`+<.zez
?: .= lat.r
:_ [~ ~]
[p=1.292.805.149 q=[%direct p=1.292.805.149 q='hello, world' r=%c]]
[ost %give %nice ~]
[ost %give %mean ~ %bad-rang ~[leaf/<d> leaf/<r>]]
++ pour
|+ [ost=bone pax=path sih=*]
^- [(list move) _+>]
!!
--
++ all-tests
^- test
=> |%
++ sign ,[%g result]
++ sult
$? result
[%pending ~]
==
--
=| results=(map ,@t sult)
|%
++ poke
|+ [ost=bone you=ship]
^- [(list move) _+>]
=. results
%- mo
%+ turn (~(tap by tests))
|= [nam=@t tes=test]
[nam %pending ~]
:_ +>.$
%+ turn (~(tap by tests))
|= [nam=@t tes=test]
:* ost %pass /all-tests/[nam] %g
%mess [our.hid %test] you %json
!> (joba %test %s nam)
==
++ pour
|+ [ost=bone pax=path sih=*]
^- [(list move) _+>]
=+ sih=((hard sign) sih)
?. ?=([@ ~] pax) ~& [%all-tests-strange-path pax] [~ +>.$]
=. results (~(put by results) -.pax +.sih)
:_ +>.$
?: (~(any by results) |=([res=sult] ?=(%pending -.res)))
~
:_ ~
?: (~(all by results) |=([res=sult] ?=(%nice -.res)))
[ost %give %nice ~]
:^ ost %give %mean
:+ ~ %failed-tests
%- zing
%+ turn
(skim (~(tap by results)) |=([nam=@t res=sult] ?=(%mean -.res)))
|= [nam=@t res=sult]
?> ?=(%mean -.res)
^- (list tank)
:_ ?~ p.res ~ q.u.p.res
:- %leaf
%+ weld "test %{(trip nam)} failed with "
?~ p.res "no error message"
%+ weld "error code %{(trip p.u.p.res)} and "
?~ q.u.p.res "no error info"
"the following error info:"
--
--
++ spec-pour
|= [ost=bone pax=path sih=*]
^- [(list move) _+>]
=+ sih=((hard ,[%g result]) sih)
:_ +>.$ :_ ~
[ost %give %rust %mime /text/plain (taco (cat 3 (crip <sih>) 10))]
++ prep
|= old=(unit (unit axle))
^- [(list move) _+>]
:- ~
%= +>.$
tests
?~ old
~& %prep-sig tests
?^ u.old
~& %prep-no-sig tests.u.u.old
=. tests
%- mo
^- (list ,[@t test])
=> et
:~ [%succeed succeed]
[%ze ze]
[%poke-local poke-local]
==
(~(put by tests) %all-tests all-tests:et)
==
++ peer :: accept subscriber
|= [ost=bone you=ship pax=path]
^- [(list move) _+>]
?~ pax [[ost %give %rust %hymn front]~ +>.$]
?: ?=(%tests -.pax)
[[ost %give %rust %json tests-json:et]~ +>.$]
:_ +>.$ :_ ~
:* ost %pass /automagic %g
%mess [our.hid %test] you %json
!> (joba %test %s -.pax)
==
++ poke-json :: browser message
|= [ost=bone you=ship jon=json]
^- [(list move) _+>]
=+ tes=((of [%test so] ~):jo jon)
?~ tes [[ost %give %mean ~ %strange-json ~]~ +>.$]
=+ tst=(~(get by tests) +.u.tes)
?~ tst
[[ost %give %mean ~ %bad-test ~]~ +>.$]
~& [%running-test +.u.tes]
=+ res=(poke:u.tst ost you)
:- -.res
+>.$(tests (~(put by tests) +.u.tes +.res))
++ pour :: response
|= [ost=bone pax=path sih=*]
^- [(list move) _+>]
?~ pax ~& %test-strange-path [~ +>.$]
=+ tst=(~(get by tests) -.pax)
?: ?=(%automagic -.pax)
(spec-pour ost pax sih)
?~ tst
~& %test-bad-path [~ +>.$]
=+ res=(pour:u.tst ost +.pax sih)
:- -.res
+>.$(tests (~(put by tests) -.pax +.res))
--

View File

@ -0,0 +1,30 @@
:: Front page of the twitter app.
::
:::: /hook/hymn/front/twit/app
::
/? 314 :: need urbit 314
/= urbit /:/===/lib/urb:/hymn/ :: urbit library (js)
/= style /:/%%%/style:/hymn/ :: stylesheet (css)
/= application /:/%%%/app:/hymn/ :: application (js)
!:
:::: content
::
^- manx
;html
;head
;title: Tests
;+ style
;script
=type "text/javascript"
=src "//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"
;
==
==
;body
;div#tests
;p: Fetching tests...
==
;+ urbit
;+ application
==
==

82
main/app/test/style.css Normal file
View File

@ -0,0 +1,82 @@
body,
textarea,
input {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 400;
}
body {
margin-top: 4rem;
font-size: 18px;
}
.test,
.name,
.result {
width: 32rem;
}
textarea {
border: 0;
height: 8rem;
line-height: 1.5rem;
margin-bottom: .3rem;
resize: none;
padding: 1rem 1px;
background-color: #f7f7f7;
}
.name {
border: 0;
color: #333;
letter-spacing: 0.01rem;
}
.name {
background-color: transparent;
border: 2px solid #5DE668;
color: #5DE668;
padding: .3rem 1rem;
font-weight: 500;
cursor: pointer;
}
.name {
background-color: #5DE668;
color: #fff;
}
.disabled {
opacity: .6;
}
.text {
word-wrap:break-word;
margin-bottom: .3rem;
line-height: 1.6rem;
}
#twet {
margin-bottom: 3rem;
border-bottom: 2px solid #464646;
padding-bottom: 2rem;
}
#twet,
.tweet {
border-bottom: 1px solid #eee;
}
.tweet {
margin-bottom: 2rem;
padding-bottom: 1rem;
}
.pending {
opacity: .3;
}
.error {
color: #FF5F5F;
letter-spacing: .06rem;
}