comparison scripts/test.luan @ 503:92c3d22745b8

make _ENV optional
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 20 May 2015 23:24:46 -0600
parents 55f9f74f1e55
children 7bc63886d4f2
comparison
equal deleted inserted replaced
502:d3183a330ff5 503:92c3d22745b8
1 local Binary = require "luan:Binary"
2 local Debug = require "luan:Debug"
3 local Html = require "luan:Html"
4 local Io = require "luan:Io"
1 local Luan = require "luan:Luan" 5 local Luan = require "luan:Luan"
6 local Math = require "luan:Math"
7 local Package = require "luan:Package"
8 local String = require "luan:String"
9 local Table = require "luan:Table"
10 local Thread = require "luan:Thread"
11 local Time = require "luan:Time"
12 local Hosting = require "luan:host/Hosting"
13 local Http = require "luan:http/Http"
14 local HttpTest = require "luan:http/HttpTest"
15 local Server = require "luan:http/Server"
16 local Lucene = require "luan:lucene/Lucene"
17 local Mail = require "luan:mail/Mail"
18 local Stripe = require "luan:stripe/Stripe"
19
2 local error = Luan.error 20 local error = Luan.error
3 local range = Luan.range 21 local range = Luan.range
4 local Io = require "luan:Io" 22 local init = HttpTest.init
5 local Http = require "luan:http/Http" 23 local get_page = HttpTest.get_page
6 local init_for_test = Http.init_for_test
7 local Lucene = require "luan:lucene/Lucene"
8 local Ab_testing = require "luan:lucene/Ab_testing" 24 local Ab_testing = require "luan:lucene/Ab_testing"
9 25
10 26
11 local function print(...) 27 local function print(...)
12 Io.print_to(Io.stderr,...) 28 Io.print_to(Io.stderr,...)
14 30
15 function Io.schemes.site(path,add_extension) 31 function Io.schemes.site(path,add_extension)
16 return Io.uri( "luan:http"..path, add_extension ) 32 return Io.uri( "luan:http"..path, add_extension )
17 end 33 end
18 34
35 local page
19 36
20 init_for_test() 37 init()
21 Http.request.parameter.code = "require('luan:Io').print 'hi'" 38 Http.request.parameter.code = "require('luan:Io').print 'hi'"
22 page = Http.get_page "/run" 39 page = get_page "/run"
23 page.trim() == "hi" or error "failed" 40 page.trim() == "hi" or error "failed"
24 41
25 init_for_test() 42 init()
26 Http.request.parameter.cmd = "'ab'..'cd'" 43 Http.request.parameter.cmd = "'ab'..'cd'"
27 page = Http.get_page "/shell" 44 page = get_page "/shell"
28 page.find "abcd" or error "failed" 45 page.find "abcd" or error "failed"
29 46
30 47
31 -- lucene 48 -- lucene
32 49
33 this_file = Io.schemes.file(Luan.arg[0]) 50 local this_file = Io.schemes.file(Luan.arg[0])
34 this_dir = this_file.parent() 51 local this_dir = this_file.parent()
35 lucene_dir = this_dir.parent().child("build").child("lucene_test") 52 local lucene_dir = this_dir.parent().child("build").child("lucene_test")
36 --print(lucene_dir.to_string()) 53 --print(lucene_dir.to_string())
37 db = Lucene.index(lucene_dir.to_string()) 54 local db = Lucene.index(lucene_dir.to_string())
38 db.delete_all() 55 db.delete_all()
39 56
40 ab_testing = Ab_testing.of(db) 57 local ab_testing = Ab_testing.of(db)
41 test_events = {"all"} 58 local test_events = {"all"}
42 aggregator_factories = { 59 local aggregator_factories = {
43 all = Ab_testing.count_all; 60 all = Ab_testing.count_all;
44 } 61 }
45 ab_testing.test{ name="All", values={"all"}, events=test_events, aggregator_factories=aggregator_factories } 62 ab_testing.test{ name="All", values={"all"}, events=test_events, aggregator_factories=aggregator_factories }
46 ab_testing.test{ name="null", values={"A","B"}, events=test_events, aggregator_factories=aggregator_factories } 63 ab_testing.test{ name="null", values={"A","B"}, events=test_events, aggregator_factories=aggregator_factories }
47 64
49 local doc = {type="test"} 66 local doc = {type="test"}
50 ab_testing.to_doc(doc) 67 ab_testing.to_doc(doc)
51 db.save_document(doc) 68 db.save_document(doc)
52 end 69 end
53 70
54 init_for_test() 71 init()
55 ab_testing.web_page{"All","null"}.respond() 72 ab_testing.web_page{"All","null"}.respond()
56 73
57 local Web_search = require "luan:lucene/Web_search" 74 local Web_search = require "luan:lucene/Web_search"
58 local web_search = Web_search.of(db) 75 local web_search = Web_search.of(db)
59 76
60 init_for_test() 77 init()
61 web_search.respond() 78 web_search.respond()
62 79
63 init_for_test() 80 init()
64 Http.request.parameter.query = "Query.all_docs" 81 Http.request.parameter.query = "Query.all_docs"
65 Http.request.parameter.rows = "100" 82 Http.request.parameter.rows = "100"
66 Http.request.parameter.sort = "" 83 Http.request.parameter.sort = ""
67 web_search.respond() 84 web_search.respond()
68 85
71 88
72 function Io.schemes.site(path,add_extension) 89 function Io.schemes.site(path,add_extension)
73 return Io.uri( "file:../website/src"..path, add_extension ) 90 return Io.uri( "file:../website/src"..path, add_extension )
74 end 91 end
75 92
76 init_for_test(); Http.get_page "/" 93 init(); get_page "/"
77 init_for_test(); Http.get_page "/docs.html" 94 init(); get_page "/docs.html"
78 init_for_test(); Http.get_page "/tutorial.html" 95 init(); get_page "/tutorial.html"
79 init_for_test(); Http.get_page "/pil.html" 96 init(); get_page "/pil.html"
80 init_for_test(); Http.get_page "/manual.html" 97 init(); get_page "/manual.html"
81 init_for_test(); Http.get_page "/diff.html" 98 init(); get_page "/diff.html"
82 init_for_test(); Http.get_page "/examples/hi" 99 init(); get_page "/examples/hi"
83 init_for_test(); Http.get_page "/examples/hi2" 100 init(); get_page "/examples/hi2"
84 init_for_test(); Http.get_page "/examples/hi2_simply_html" 101 init(); get_page "/examples/hi2_simply_html"
85 init_for_test(); Http.get_page "/examples/shell" 102 init(); get_page "/examples/shell"
86 103
87 init_for_test() 104 init()
88 Http.request.parameter.name = "bob" 105 Http.request.parameter.name = "bob"
89 page = Http.get_page "/examples/hi2" 106 page = get_page "/examples/hi2"
90 page.find "bob" or error "failed" 107 page.find "bob" or error "failed"
91 108
92 init_for_test() 109 init()
93 Http.request.parameter.name = "bob" 110 Http.request.parameter.name = "bob"
94 page = Http.get_page "/examples/hi2_simply_html" 111 page = get_page "/examples/hi2_simply_html"
95 page.find "bob" or error "failed" 112 page.find "bob" or error "failed"
96 113
97 114
98 print "done" 115 print "done"