Merge: Harden tests script
authorJean Privat <jean@pryen.org>
Thu, 28 Jan 2016 21:56:55 +0000 (16:56 -0500)
committerJean Privat <jean@pryen.org>
Thu, 28 Jan 2016 21:56:55 +0000 (16:56 -0500)
Improve the resilience of the tests.sh script if java is not found or if ulimit is limited

Pull-Request: #1930
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/tinks/Makefile
lib/nitcorn/examples/src/htcpcp_server.nit [new file with mode: 0644]
tests/sav/htcpcp_server.res [new file with mode: 0644]

index fbe8155..e637d0c 100644 (file)
 
 all: bin/server bin/tinks bin/tinks3d
 
-pre-build: assets/images/drawing.png src/client/client_serialize.nit src/server/server_serialize.nit
+pre-build: assets/images/drawing.png src/server/server_serialize.nit
 
 # Client
 bin/tinks: assets/images/drawing.png src/client/client.nit $(shell ../../bin/nitls -M src/client/linux_client.nit)
-               ../../bin/nitserial -o src/client/client_serialize.nit src/client/client.nit
+       ../../bin/nitserial -o src/client/client_serialize.nit src/client/client.nit
        ../../bin/nitc -o bin/tinks src/client/linux_client.nit -m src/client/client_serialize.nit
 
 bin/tinks3d: $(shell ../../bin/nitls -M src/client/client3d.nit -m linux)
@@ -38,19 +38,15 @@ src/server/server_serialize.nit: $(shell ../../bin/nitls -M src/server/dedicated
 
 # Android
 android: bin/tinks.apk
-bin/tinks.apk: assets/images/drawing.png src/client/client_serialize.nit res/drawable-ldpi/icon.png $(shell ../../bin/nitls -M src/client/android_client.nit)
+bin/tinks.apk: assets/images/drawing.png res/drawable-ldpi/icon.png $(shell ../../bin/nitls -M src/client/android_client.nit)
+       ../../bin/nitserial -o src/client/client_serialize.nit src/client/client.nit
        ../../bin/nitc -o bin/tinks.apk src/client/android_client.nit -m src/client/client_serialize.nit
 
-android-release: assets/images/drawing.png src/client/client_serialize.nit res/drawable-ldpi/icon.png $(shell ../../bin/nitls -M src/client/android_client.nit)
+android-release: assets/images/drawing.png res/drawable-ldpi/icon.png $(shell ../../bin/nitls -M src/client/android_client.nit)
+       ../../bin/nitserial -o src/client/client_serialize.nit src/client/client.nit
        ../../bin/nitc -o bin/tinks.apk src/client/android_client.nit -m src/client/client_serialize.nit --release
 
 res/drawable-ldpi/icon.png: art/icon.svg
        ../inkscape_tools/bin/svg_to_icons art/icon.svg --android --out res/
 
-# Archive
-pub: assets/images/drawing.png src/client/client_serialize.nit bin/tinks.apk
-       ../../bin/nitc --no-stacktrace -o bin/tinks src/client/linux_client.nit -m src/client/client_serialize.nit
-       tar -czvf bin/tinks.tar.gz bin/tinks assets/
-       scp bin/tinks.tar.gz bin/tinks.apk xymus.net:/var/www/pub/
-
 .PHONY: pub
diff --git a/lib/nitcorn/examples/src/htcpcp_server.nit b/lib/nitcorn/examples/src/htcpcp_server.nit
new file mode 100644 (file)
index 0000000..37fa87e
--- /dev/null
@@ -0,0 +1,96 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2015 Guilherme Mansur<guilhermerpmansur@gmail.com>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# Hyper Text Coffee Pot Control Protocol
+
+# A server that implements HTCPCP. At the moment there are no additions.
+module htcpcp_server
+
+import nitcorn
+
+class HTCPCPAction
+       super Action
+       var brewing = false
+  var is_teapot = false
+
+       redef fun answer(http_request, turi) do
+               var message: String
+               var method = http_request.method
+               var headers = http_request.header
+               var response: HttpResponse
+
+               if is_teapot == true then
+                       response = new HttpResponse(418)
+                       response.body = "I'm a teapot!\n"
+                       response.header["Content-Type"] = "text"
+                       return response
+               end
+
+               if method == "POST" or method == "BREW" then
+                       if brewing then
+                               message = "Pot Busy"
+                               response = new HttpResponse(400)
+                       else
+                               message = "Brewing a new pot of coffee\n"
+                               brewing = true
+                               response = new HttpResponse(200)
+                       end
+               else if method == "WHEN" then
+                       if brewing then
+                               message = "Stopped adding milk, your coffee is ready!\n"
+                               brewing = false
+                               response = new HttpResponse(200)
+                       else
+                               message = "There is no coffee brewing!\n"
+                               response = new HttpResponse(405)
+                       end
+               else if method == "PROPFIND" or method == "GET" then
+                       if brewing then
+                               message = "The pot is busy\n"
+                       else
+                               message = "The pot is ready to brew more coffee\n"
+                       end
+                       response = new HttpResponse(200)
+               else
+                       message = "Unknown method: {method}"
+                       brewing = false
+                       response = new HttpResponse(405)
+               end
+
+               response.header["Content-Type"] = "text"
+               response.body = message
+
+               return response
+       end
+end
+
+
+class HTCPCServer
+       var port: Int
+
+       fun run do
+               var vh = new VirtualHost("localhost:{port}")
+               vh.routes.add new Route("/", new HTCPCPAction)
+               var factory = new HttpFactory.and_libevent
+               factory.config.virtual_hosts.add vh
+               print "Nit4Coffee is now running at port: {port}"
+               factory.run
+       end
+end
+
+var server = new HTCPCServer(1227)
+
+server.run
diff --git a/tests/sav/htcpcp_server.res b/tests/sav/htcpcp_server.res
new file mode 100644 (file)
index 0000000..cfb727c
--- /dev/null
@@ -0,0 +1 @@
+Nit4Coffee is now running at port: 1227