comparison scripts/test.luan @ 323:cd2924a1052c

improve testing git-svn-id: https://luan-java.googlecode.com/svn/trunk@324 21e917c8-12df-6dd8-5cb6-c86387c605b9
author fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9>
date Mon, 09 Feb 2015 04:33:21 +0000
parents 7f7708e8fdd4
children 5b36f663a1b8
comparison
equal deleted inserted replaced
322:f8ece87df2b1 323:cd2924a1052c
1 local do_file = require("luan:Luan").do_file 1 local Luan = require "luan:Luan"
2 local assert = Luan.assert
3 local range = Luan.range
4 local Io = require "luan:Io"
5 local Http = require "luan:web/Http"
6 local Lucene = require "luan:lucene/Lucene"
7 local Ab_testing = require "luan:lucene/Ab_testing"
2 8
3 do_file "luan:web/test.luan" 9
10 local function print(...)
11 Io.print_to(Io.stderr,...)
12 end
13
14 function Io.schemes.site(path)
15 return Io.Uri( "luan:web"..path )
16 end
17
18
19 Http.init_for_test()
20 Http.request.parameters.code = "require('luan:Io').print 'hi'"
21 page = Http.get_page "/web_run"
22 assert( page.trim() == "hi" )
23
24 Http.init_for_test()
25 Http.request.parameters.cmd = "'ab'..'cd'"
26 page = Http.get_page "/web_shell"
27 assert( page.find "abcd" )
28
29
30 -- lucene
31
32 this_file = Io.schemes.file(Luan.arg[0])
33 this_dir = this_file.parent()
34 lucene_dir = this_dir.parent().child("build").child("lucene_test")
35 --print(lucene_dir.to_string())
36 db = Lucene.Index(lucene_dir.to_string())
37 db.delete_all()
38
39 ab_testing = Ab_testing.of(db)
40 test_events = {"all"}
41 aggregator_factories = {
42 all = Ab_testing.count_all;
43 }
44 ab_testing.test{ name="All", values={"all"}, events=test_events, aggregator_factories=aggregator_factories }
45 ab_testing.test{ name="null", values={"A","B"}, events=test_events, aggregator_factories=aggregator_factories }
46
47 for record in range(1,10) do
48 local doc = {type="test"}
49 ab_testing.to_doc(doc)
50 db.save_document(doc)
51 end
52
53 Http.init_for_test()
54 ab_testing.web_page{"All","null"}.service()
55
56
57 print "done"