changeset 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 f8ece87df2b1
children b24a35612947
files core/src/luan/cmd_line.luan core/src/luan/modules/IoLuan.java lucene/src/luan/modules/lucene/Ab_testing.luan lucene/src/luan/modules/lucene/Lucene.luan lucene/src/luan/modules/lucene/LuceneWriter.java scripts/test.luan web/src/luan/modules/web/Http.luan web/src/luan/modules/web/Web_server.luan web/src/luan/modules/web/test.luan
diffstat 9 files changed, 82 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/core/src/luan/cmd_line.luan	Sun Feb 08 22:03:27 2015 +0000
+++ b/core/src/luan/cmd_line.luan	Mon Feb 09 04:33:21 2015 +0000
@@ -68,13 +68,13 @@
 if showVersion then print(Luan.VERSION) end
 if i <= #args then
 	local file = args[i]
-	local arg = {}
+	Luan.arg = {}
 	for j,v in ipairs(args) do
-		arg[j-i] = v
+		Luan.arg[j-i] = v
 	end
 	try
 		local main_file = load_file("file:"..file)
-		main_file( Table.unpack(arg) )
+		main_file( Table.unpack(Luan.arg) )
 	catch e do
 		Io.print_to(Io.stderr, e )
 	end
--- a/core/src/luan/modules/IoLuan.java	Sun Feb 08 22:03:27 2015 +0000
+++ b/core/src/luan/modules/IoLuan.java	Mon Feb 09 04:33:21 2015 +0000
@@ -400,6 +400,13 @@
 			return list;
 		}
 
+		public LuanTable parent(LuanState luan) throws LuanException, IOException {
+			File parent = file.getParentFile();
+			if( parent==null )
+				parent = file.getCanonicalFile().getParentFile();
+			return new LuanFile(luan,parent).table();
+		}
+
 		@Override public boolean exists() {
 			return file.exists();
 		}
@@ -442,6 +449,9 @@
 				tbl.put( "children", new LuanJavaFunction(
 					LuanFile.class.getMethod( "children", LuanState.class ), this
 				) );
+				tbl.put( "parent", new LuanJavaFunction(
+					LuanFile.class.getMethod( "parent", LuanState.class ), this
+				) );
 				tbl.put( "rename_to", new LuanJavaFunction(
 					LuanFile.class.getMethod( "rename_to", String.class ), this
 				) );
--- a/lucene/src/luan/modules/lucene/Ab_testing.luan	Sun Feb 08 22:03:27 2015 +0000
+++ b/lucene/src/luan/modules/lucene/Ab_testing.luan	Mon Feb 09 04:33:21 2015 +0000
@@ -1,8 +1,13 @@
-import "luan:Math"
-import "luan:Table"
-import "luan:Io"
-import "luan:web/Http"
-import "luan:logging/Logging"
+local Luan = require "luan:Luan"
+local pairs = Luan.pairs
+local ipairs = Luan.ipairs
+local error = Luan.error
+local range = Luan.range
+local Math = require "luan:Math"
+local Table = require "luan:Table"
+local Io = require "luan:Io"
+local Http = require "luan:web/Http"
+local Logging = require "luan:logging/Logging"
 
 
 local logger = Logging.logger "Ab_testing"
--- a/lucene/src/luan/modules/lucene/Lucene.luan	Sun Feb 08 22:03:27 2015 +0000
+++ b/lucene/src/luan/modules/lucene/Lucene.luan	Mon Feb 09 04:33:21 2015 +0000
@@ -1,6 +1,7 @@
 java()
 local Luan = require "luan:Luan"
 local pairs = Luan.pairs
+local type = Luan.type
 local Table = require "luan:Table"
 local LuceneIndex = require "java:luan.modules.lucene.LuceneIndex"
 local Term = require "java:org.apache.lucene.index.Term"
--- a/lucene/src/luan/modules/lucene/LuceneWriter.java	Sun Feb 08 22:03:27 2015 +0000
+++ b/lucene/src/luan/modules/lucene/LuceneWriter.java	Mon Feb 09 04:33:21 2015 +0000
@@ -59,7 +59,7 @@
 
 	public void save_document(LuanState luan,LuanTable doc) throws LuanException, IOException {
 		if( doc.get("type")==null )
-			throw luan.exception("missing 'type'");
+			throw luan.exception("missing 'type' field");
 		String id = (String)doc.get("id");
 		if( id == null ) {
 			id = nextId(luan);
--- a/scripts/test.luan	Sun Feb 08 22:03:27 2015 +0000
+++ b/scripts/test.luan	Mon Feb 09 04:33:21 2015 +0000
@@ -1,3 +1,57 @@
-local do_file = require("luan:Luan").do_file
+local Luan = require "luan:Luan"
+local assert = Luan.assert
+local range = Luan.range
+local Io = require "luan:Io"
+local Http = require "luan:web/Http"
+local Lucene = require "luan:lucene/Lucene"
+local Ab_testing = require "luan:lucene/Ab_testing"
+
+
+local function print(...)
+	Io.print_to(Io.stderr,...)
+end
+
+function Io.schemes.site(path)
+	return Io.Uri( "luan:web"..path )
+end
+
+
+Http.init_for_test()
+Http.request.parameters.code = "require('luan:Io').print 'hi'"
+page = Http.get_page "/web_run"
+assert( page.trim() == "hi" )
+
+Http.init_for_test()
+Http.request.parameters.cmd = "'ab'..'cd'"
+page = Http.get_page "/web_shell"
+assert( page.find "abcd" )
+
 
-do_file "luan:web/test.luan"
+-- lucene
+
+this_file = Io.schemes.file(Luan.arg[0])
+this_dir = this_file.parent()
+lucene_dir = this_dir.parent().child("build").child("lucene_test")
+--print(lucene_dir.to_string())
+db = Lucene.Index(lucene_dir.to_string())
+db.delete_all()
+
+ab_testing = Ab_testing.of(db)
+test_events = {"all"}
+aggregator_factories = {
+	all = Ab_testing.count_all;
+}
+ab_testing.test{ name="All", values={"all"}, events=test_events, aggregator_factories=aggregator_factories }
+ab_testing.test{ name="null", values={"A","B"}, events=test_events, aggregator_factories=aggregator_factories }
+
+for record in range(1,10) do
+	local doc = {type="test"}
+	ab_testing.to_doc(doc)
+	db.save_document(doc)
+end
+
+Http.init_for_test()
+ab_testing.web_page{"All","null"}.service()
+
+
+print "done"
--- a/web/src/luan/modules/web/Http.luan	Sun Feb 08 22:03:27 2015 +0000
+++ b/web/src/luan/modules/web/Http.luan	Mon Feb 09 04:33:21 2015 +0000
@@ -3,6 +3,7 @@
 local ipairs = Luan.ipairs
 local to_string = Luan.to_string
 local Table = require "luan:Table"
+require "luan:logging/Logging"  -- initialize logging
 local LuanHandler = require "java:luan.modules.web.LuanHandler"
 
 
--- a/web/src/luan/modules/web/Web_server.luan	Sun Feb 08 22:03:27 2015 +0000
+++ b/web/src/luan/modules/web/Web_server.luan	Mon Feb 09 04:33:21 2015 +0000
@@ -1,7 +1,6 @@
 require "luan:String"
 local Io = require "luan:Io"
 local Package = require "luan:Package"
-require "luan:logging/Logging"  -- initialize logging
 local Http = require "luan:web/Http"
 
 java()
--- a/web/src/luan/modules/web/test.luan	Sun Feb 08 22:03:27 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,24 +0,0 @@
-local Luan = require "luan:Luan"
-local assert = Luan.assert
-local Io = require "luan:Io"
-local Http = require "luan:web/Http"
-
-
-local function print(...)
-	Io.print_to(Io.stderr,...)
-end
-
-function Io.schemes.site(path,loading)
-	return Io.Uri( "luan:web"..path, loading )
-end
-
-
-Http.init_for_test()
-Http.request.parameters.code = "require('luan:Io').print 'hi'"
-page = Http.get_page "/web_run"
-assert( page.trim() == "hi" )
-
-Http.init_for_test()
-Http.request.parameters.cmd = "'ab'..'cd'"
-page = Http.get_page "/web_shell"
-assert( page.find "abcd" )