Merge: popcorn: use nitunit for blackbox testing
authorJean Privat <jean@pryen.org>
Tue, 7 Jun 2016 19:10:44 +0000 (15:10 -0400)
committerJean Privat <jean@pryen.org>
Tue, 7 Jun 2016 19:10:44 +0000 (15:10 -0400)
Pull-Request: #2153
Reviewed-by: Jean Privat <jean@pryen.org>

41 files changed:
.gitattributes
lib/popcorn/Makefile
lib/popcorn/examples/angular/test_example_angular.nit [moved from lib/popcorn/tests/test_example_angular.nit with 68% similarity]
lib/popcorn/examples/angular/test_example_angular.sav/test_example_angular.res [moved from lib/popcorn/tests/res/test_example_angular.res with 100% similarity]
lib/popcorn/examples/handlers/test_example_post_handler.nit [moved from lib/popcorn/tests/test_example_post.nit with 75% similarity]
lib/popcorn/examples/handlers/test_example_post_handler.sav/test_example_post_handler.res [moved from lib/popcorn/tests/res/test_example_post.res with 100% similarity]
lib/popcorn/examples/handlers/test_example_query_string.nit [moved from lib/popcorn/tests/test_example_query_string.nit with 73% similarity]
lib/popcorn/examples/handlers/test_example_query_string.sav/test_example_query_string.res [moved from lib/popcorn/tests/res/test_example_query_string.res with 100% similarity]
lib/popcorn/examples/hello_world/test_example_hello.nit [moved from lib/popcorn/tests/test_example_hello.nit with 73% similarity]
lib/popcorn/examples/hello_world/test_example_hello.sav/test_example_hello.res [moved from lib/popcorn/tests/res/test_example_hello.res with 98% similarity]
lib/popcorn/examples/middlewares/test_example_advanced_logger.nit [moved from lib/popcorn/tests/test_example_advanced_logger.nit with 65% similarity]
lib/popcorn/examples/middlewares/test_example_advanced_logger.sav/test_example_advanced_logger.res [moved from lib/popcorn/tests/res/test_example_advanced_logger.res with 100% similarity]
lib/popcorn/examples/middlewares/test_example_html_error_handler.nit [moved from lib/popcorn/tests/test_example_html_error_handler.nit with 70% similarity]
lib/popcorn/examples/middlewares/test_example_html_error_handler.sav/test_example_html_error_handler.res [moved from lib/popcorn/tests/res/test_example_html_error_handler.res with 100% similarity]
lib/popcorn/examples/middlewares/test_example_simple_error_handler.nit [moved from lib/popcorn/tests/test_example_simple_error_handler.nit with 68% similarity]
lib/popcorn/examples/middlewares/test_example_simple_error_handler.sav/test_example_simple_error_handler.res [moved from lib/popcorn/tests/res/test_example_simple_error_handler.res with 100% similarity]
lib/popcorn/examples/middlewares/test_example_simple_logger.nit [moved from lib/popcorn/tests/test_example_simple_logger.nit with 68% similarity]
lib/popcorn/examples/middlewares/test_example_simple_logger.sav/test_example_simple_logger.res [moved from lib/popcorn/tests/res/test_example_simple_logger.res with 100% similarity]
lib/popcorn/examples/routing/test_example_glob_route.nit [moved from lib/popcorn/tests/test_example_glob_route.nit with 75% similarity]
lib/popcorn/examples/routing/test_example_glob_route.sav/test_example_glob_route.res [moved from lib/popcorn/tests/res/test_example_glob_route.res with 98% similarity]
lib/popcorn/examples/routing/test_example_param_route.nit [moved from lib/popcorn/tests/test_example_param_route.nit with 73% similarity]
lib/popcorn/examples/routing/test_example_param_route.sav/test_example_param_route.res [moved from lib/popcorn/tests/res/test_example_param_route.res with 98% similarity]
lib/popcorn/examples/routing/test_example_router.nit [moved from lib/popcorn/tests/test_example_router.nit with 67% similarity]
lib/popcorn/examples/routing/test_example_router.sav/test_example_router.res [moved from lib/popcorn/tests/res/test_example_router.res with 98% similarity]
lib/popcorn/examples/sessions/test_example_session.nit [moved from lib/popcorn/tests/test_example_session.nit with 71% similarity]
lib/popcorn/examples/sessions/test_example_session.sav/test_example_session.res [moved from lib/popcorn/tests/res/test_example_session.res with 100% similarity]
lib/popcorn/examples/static_files/test_example_static.nit [moved from lib/popcorn/tests/test_example_static.nit with 73% similarity]
lib/popcorn/examples/static_files/test_example_static.sav/test_example_static.res [moved from lib/popcorn/tests/res/test_example_static.res with 100% similarity]
lib/popcorn/examples/static_files/test_example_static_default.nit [moved from lib/popcorn/tests/test_example_static_default.nit with 72% similarity]
lib/popcorn/examples/static_files/test_example_static_default.sav/test_example_static_default.res [moved from lib/popcorn/tests/res/test_example_static_default.res with 100% similarity]
lib/popcorn/examples/static_files/test_example_static_multiple.nit [moved from lib/popcorn/tests/test_example_static_multiple.nit with 67% similarity]
lib/popcorn/examples/static_files/test_example_static_multiple.sav/test_example_static_multiple.res [moved from lib/popcorn/tests/res/test_example_static_multiple.res with 100% similarity]
lib/popcorn/pop_tests.nit [new file with mode: 0644]
lib/popcorn/test_popcorn.nit [new file with mode: 0644]
lib/popcorn/test_popcorn.sav/test_router.res [moved from lib/popcorn/tests/res/test_router.res with 98% similarity]
lib/popcorn/test_popcorn.sav/test_routes.res [moved from lib/popcorn/tests/res/test_routes.res with 99% similarity]
lib/popcorn/tests/Makefile [deleted file]
lib/popcorn/tests/base_tests.nit [deleted file]
lib/popcorn/tests/test_router.nit [deleted file]
lib/popcorn/tests/test_routes.nit [deleted file]
lib/popcorn/tests/tests.sh [deleted file]

index 02c0677..e326f39 100644 (file)
@@ -6,5 +6,5 @@ tables_nit.c            -diff
 c_src/**               -diff
 
 tests/sav/**/*.res     -whitespace
-lib/popcorn/tests/res/*.res -whitespace
+*.res                  -whitespace
 *.patch                        -whitespace
index 12db3df..bc59692 100644 (file)
@@ -17,8 +17,4 @@
 NITUNIT=../../bin/nitunit
 
 check:
-       $(NITUNIT) README.md
-       $(NITUNIT) pop_routes.nit
-       $(NITUNIT) pop_handlers.nit
-       $(NITUNIT) popcorn.nit
-       cd tests; make check
+       $(NITUNIT) .
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_angular is test_suite
+
+import pop_tests
 import example_angular
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleAngular
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/counter"
                system "curl -s {host}:{port}/counter -X POST"
                system "curl -s {host}:{port}/counter"
                system "curl -s {host}:{port}/not_found" # handled by angular controller
-               return null
        end
-end
-
-var app = new App
-app.use("/counter", new CounterAPI)
-app.use("/*", new StaticHandler("../examples/angular/www/", "index.html"))
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_param_route do
+               var app = new App
+               app.use("/counter", new CounterAPI)
+               app.use("/*", new StaticHandler("../examples/angular/www/", "index.html"))
+               run_test(app)
+       end
+end
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_post_handler is test_suite
+
+import pop_tests
 import example_post_handler
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleQueryString
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/ -X POST"
                system "curl -s {host}:{port}/ --data 'user'"
                system "curl -s {host}:{port}/ --data 'user=Morriar'"
                system "curl -s {host}:{port}/ --data 'user=\&order=desc'"
                system "curl -s {host}:{port}/ --data 'user=Morriar\&order=desc'"
-
                system "curl -s {host}:{port}/"
-               return null
        end
-end
-
-var app = new App
-app.use("/", new PostHandler)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_glob_route do
+               var app = new App
+               app.use("/", new PostHandler)
+               run_test(app)
+       end
+end
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_query_string is test_suite
+
+import pop_tests
 import example_query_string
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleQueryString
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/?user=Morriar"
                system "curl -s {host}:{port}/?reload"
                system "curl -s {host}:{port}/?foo\\&bar=baz"
                system "curl -s {host}:{port}/?items=10\\&order=asc"
-               return null
        end
-end
-
-var app = new App
-app.use("/", new QueryStringHandler)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_glob_route do
+               var app = new App
+               app.use("/", new QueryStringHandler)
+               run_test(app)
+       end
+end
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_hello is test_suite
+
+import pop_tests
 import example_hello
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleHello
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}"
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}///////////"
                system "curl -s {host}:{port}/not_found"
                system "curl -s {host}:{port}/not_found/not_found"
-               return null
        end
-end
-
-var app = new App
-app.use("/", new HelloHandler)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_hello do
+               var app = new App
+               app.use("/", new HelloHandler)
+               run_test(app)
+       end
+end
@@ -26,4 +26,4 @@
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_advanced_logger is test_suite
+
+import pop_tests
 import example_advanced_logger
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleAdvancedLogger
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/about"
-               return null
        end
-end
-
-var app = new App
-app.use_before("/*", new RequestTimeHandler)
-app.use("/", new HelloHandler)
-app.use_after("/*", new LogHandler)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_param_route do
+               var app = new App
+               app.use_before("/*", new RequestTimeHandler)
+               app.use("/", new HelloHandler)
+               app.use_after("/*", new LogHandler)
+               run_test(app)
+       end
+end
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_html_error_handler is test_suite
+
+import pop_tests
 import example_html_error_handler
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleHtmlErrorHandler
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/about"
-               return null
        end
-end
-
-var app = new App
-app.use("/*", new HtmlErrorHandler)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_param_route do
+               var app = new App
+               app.use("/*", new HtmlErrorHandler)
+               run_test(app)
+       end
+end
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_simple_error_handler is test_suite
+
+import pop_tests
 import example_simple_error_handler
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleSimpleErrorHandler
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/about"
-               return null
        end
-end
-
-var app = new App
-app.use("/", new HelloHandler)
-app.use("/*", new SimpleErrorHandler)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_param_route do
+               var app = new App
+               app.use("/", new HelloHandler)
+               app.use("/*", new SimpleErrorHandler)
+               run_test(app)
+       end
+end
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_simple_logger is test_suite
+
+import pop_tests
 import example_simple_logger
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleSimpleLogger
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/about"
-               return null
        end
-end
-
-var app = new App
-app.use_before("/*", new LogHandler)
-app.use("/", new HelloHandler)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_param_route do
+               var app = new App
+               app.use_before("/*", new LogHandler)
+               app.use("/", new HelloHandler)
+               run_test(app)
+       end
+end
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_glob_route is test_suite
+
+import pop_tests
 import example_glob_route
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleGlobRoute
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/user/Morriar/item/10"
                system "curl -s {host}:{port}/user/Morriar/item/10/"
                system "curl -s {host}:{port}/user/Morriar/item/10/profile"
                system "curl -s {host}:{port}/user/Morriar/item/10/profile/settings"
-
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/not_found"
                system "curl -s {host}:{port}/not_found/not_found"
-               return null
        end
-end
-
-var app = new App
-app.use("/user/:user/item/:item/*", new UserItem)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_glob_route do
+               var app = new App
+               app.use("/user/:user/item/:item/*", new UserItem)
+               run_test(app)
+       end
+end
@@ -39,4 +39,4 @@ Here the item 10 of the use Morriar.
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_param_route is test_suite
+
+import pop_tests
 import example_param_route
-import base_tests
 
-class TestClient
-       super ClientThread
+class TestExampleParamRoute
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/Morriar"
                system "curl -s {host}:{port}//"
-
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/not_found"
                system "curl -s {host}:{port}/not_found/not_found"
-               return null
        end
-end
-
-var app = new App
-app.use("/:user", new UserHome)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_param_route do
+               var app = new App
+               app.use("/:user", new UserHome)
+               run_test(app)
+       end
+end
@@ -35,4 +35,4 @@ Hello not_found
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_router is test_suite
+
+import pop_tests
 import example_router
-import base_tests
 
-class HelloClient
-       super ClientThread
+class TestExampleRouter
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}"
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/user"
                system "curl -s {host}:{port}/user/"
                system "curl -s {host}:{port}/user/profile"
-
                system "curl -s {host}:{port}/not_found"
                system "curl -s {host}:{port}/user/not_found"
                system "curl -s {host}:{port}/products/not_found"
-               return null
        end
-end
-
-var user_router = new Router
-user_router.use("/*", new UserLogger)
-user_router.use("/", new UserHome)
-user_router.use("/profile", new UserProfile)
-
-var app = new App
-app.use("/", new AppHome)
-app.use("/user", user_router)
 
-var host = test_host
-var port = test_port
-
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new HelloClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_router do
+               var user_router = new Router
+               user_router.use("/*", new UserLogger)
+               user_router.use("/", new UserHome)
+               user_router.use("/profile", new UserProfile)
+               var app = new App
+               app.use("/", new AppHome)
+               app.use("/user", user_router)
+               run_test(app)
+       end
+end
@@ -45,4 +45,4 @@ User logged
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+module test_example_session is test_suite
+
+import pop_tests
 import example_session
-import base_tests
 
-class HelloClient
-       super ClientThread
+class TestExampleSession
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/"
                system "curl -s {host}:{port}/ -X POST"
-
                system "curl -s {host}:{port}/not_found"
                system "curl -s {host}:{port}/user/not_found"
                system "curl -s {host}:{port}/products/not_found"
-               return null
        end
-end
-
-var app = new App
-app.use("/*", new SessionInit)
-app.use("/", new AppLogin)
-
-var host = test_host
-var port = test_port
 
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new HelloClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
+       fun test_example_param_route do
+               var app = new App
+               app.use("/*", new SessionInit)
+               app.use("/", new AppLogin)
+               run_test(app)
+       end
+end
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import base_tests
+module test_example_static is test_suite
+
+import pop_tests
 import example_static
 
-class TestClient
-       super ClientThread
+class TestExampleStatic
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/css/style.css"
                system "curl -s {host}:{port}/js/app.js"
                system "curl -s {host}:{port}/hello.html"
                system "curl -s {host}:{port}/"
-
                system "curl -s {host}:{port}/css/not_found.nit"
                system "curl -s {host}:{port}/static/css/not_found.nit"
                system "curl -s {host}:{port}/not_found.nit"
+       end
 
-               return null
+       fun test_example_param_route do
+               var app = new App
+               app.use("/", new StaticHandler("../examples/static_files/public/"))
+               run_test(app)
        end
 end
-
-var app = new App
-app.use("/", new StaticHandler("../examples/static_files/public/"))
-
-var host = test_host
-var port = test_port
-
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import base_tests
+module test_example_static_default is test_suite
+
+import pop_tests
 import example_static_default
 
-class TestClient
-       super ClientThread
+class TestExampleStaticDefault
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/css/style.css"
                system "curl -s {host}:{port}/js/app.js"
                system "curl -s {host}:{port}/hello.html"
                system "curl -s {host}:{port}/"
-
                system "curl -s {host}:{port}/css/not_found.nit"
                system "curl -s {host}:{port}/static/css/not_found.nit"
                system "curl -s {host}:{port}/not_found.nit"
+       end
 
-               return null
+       fun test_example_param_route do
+               var app = new App
+               app.use("/", new StaticHandler("../examples/static_files/public/", "default.html"))
+               run_test(app)
        end
 end
-
-var app = new App
-app.use("/", new StaticHandler("../examples/static_files/public/", "default.html"))
-
-var host = test_host
-var port = test_port
-
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import base_tests
+module test_example_static_multiple is test_suite
+
+import pop_tests
 import example_static_multiple
 
-class TestClient
-       super ClientThread
+class TestExampleStaticMultiple
+       super TestPopcorn
 
-       redef fun main do
+       redef fun client_test do
                system "curl -s {host}:{port}/css/style.css"
                system "curl -s {host}:{port}/js/app.js"
                system "curl -s {host}:{port}/hello.html"
                system "curl -s {host}:{port}/"
-
                system "curl -s {host}:{port}/static/css/style.css"
                system "curl -s {host}:{port}/static/js/app.js"
                system "curl -s {host}:{port}/static/hello.html"
                system "curl -s {host}:{port}/static/"
-
                system "curl -s {host}:{port}/css/not_found.nit"
                system "curl -s {host}:{port}/static/css/not_found.nit"
                system "curl -s {host}:{port}/not_found.nit"
+       end
 
-               return null
+       fun test_example_param_route do
+               var app = new App
+               app.use("/", new StaticHandler("../examples/static_files/public/"))
+               app.use("/", new StaticHandler("../examples/static_files/files/"))
+               app.use("/static", new StaticHandler("../examples/static_files/public/"))
+               app.use("/static", new StaticHandler("../examples/static_files/files/"))
+               run_test(app)
        end
 end
-
-var app = new App
-app.use("/", new StaticHandler("../examples/static_files/public/"))
-app.use("/", new StaticHandler("../examples/static_files/files/"))
-app.use("/static", new StaticHandler("../examples/static_files/public/"))
-app.use("/static", new StaticHandler("../examples/static_files/files/"))
-
-var host = test_host
-var port = test_port
-
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new TestClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
diff --git a/lib/popcorn/pop_tests.nit b/lib/popcorn/pop_tests.nit
new file mode 100644 (file)
index 0000000..1deaeab
--- /dev/null
@@ -0,0 +1,162 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# 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.
+
+# Popcorn testing services
+#
+# ## Blackbox testing
+#
+# Popcorn allows you to test your apps using nitunit blackbox testing.
+#
+# With blackbox testing you compare the output of your program with a result file.
+#
+# To get started with blackbox testing, create a nitunit test suite and imports
+# the `pop_tests` module.
+#
+# You then need to build the app that will be tested by nitunit as shown in the
+# `test_example_hello` method.
+# Calling `run_test` will automatically set the `host` and `port` used for testing.
+#
+# Redefine the `client_test` method to write your scenario.
+# Here we use `curl` to access some URI on the app.
+#
+# ~~~nitish
+# module test_example_hello is test_suite
+#
+# import pop_tests
+# import example_hello
+#
+# class TestExampleHello
+#      super TestPopcorn
+#
+#      fun test_example_hello do
+#              var app = new App
+#              app.use("/", new HelloHandler)
+#              run_test(app)
+#      end
+#
+#      redef fun client_test do
+#              system "curl -s {host}:{port}"
+#              system "curl -s {host}:{port}/"
+#              system "curl -s {host}:{port}///////////"
+#              system "curl -s {host}:{port}/not_found"
+#              system "curl -s {host}:{port}/not_found/not_found"
+#      end
+# end
+# ~~~
+#
+# The blackbox testing needs a reference result file against wich the test output
+# will be compared.
+# Create your expected result file in `test_example_hello.sav/test_example_hello.res`.
+#
+# Test your app by running nitunit:
+#
+# ~~~bash
+# nitunit ./example_hello.nit
+# ~~~
+#
+# See `examples/hello_world` for the complete example.
+module pop_tests
+
+import test_suite
+import popcorn
+import pthreads
+
+redef class Sys
+
+       # Use localhost for testing
+       var test_host = "localhost"
+
+       # Return a new port for each instance
+       fun test_port: Int do
+               srand
+               return 10000+20000.rand
+       end
+end
+
+# Thread running the App to test.
+class AppThread
+       super Thread
+
+       # Host used by tested App.
+       var host: String
+
+       # Port used by tested App.
+       var port: Int
+
+       # App to test.
+       var app: App
+
+       redef fun main
+       do
+               # Hide testing concept to force nitcorn to actually run
+               "NIT_TESTING".setenv("false")
+               app.quiet = true
+               app.listen(host, port)
+               return null
+       end
+end
+
+# Thread running the test client.
+class ClientThread
+       super Thread
+
+       # Test suite to execute.
+       var test_suite: TestPopcorn
+
+       redef fun main do
+               test_suite.client_test
+               print ""
+               return null
+       end
+end
+
+# TestSuite for Popcorn blackbox testing.
+class TestPopcorn
+       super TestSuite
+
+       # Host used to run App.
+       var host: String = test_host
+
+       # Port used to run App.
+       var port: Int = test_port
+
+       # Run the test suite on the App.
+       fun run_test(app: App) do
+               var server = new AppThread(host, port, app)
+               server.start
+               0.1.sleep
+
+               var client = new ClientThread(self)
+               client.start
+               client.join
+               0.1.sleep
+
+               exit 0
+       end
+
+       # Redefine this method to implement your test scenario.
+       fun client_test do end
+
+       # Regex to catch and hide the port from the output to get consistent results
+       var host_re: Regex = "localhost:\[0-9\]+".to_re
+
+       # Execute a System function.
+       fun system(cmd: String, title: nullable String)
+       do
+               title = title or else cmd
+               title = title.replace(host_re, "localhost:*****")
+               print "\n[Client] {title}"
+               sys.system cmd
+       end
+end
diff --git a/lib/popcorn/test_popcorn.nit b/lib/popcorn/test_popcorn.nit
new file mode 100644 (file)
index 0000000..108eb7a
--- /dev/null
@@ -0,0 +1,97 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>
+#
+# 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.
+
+module test_popcorn is test_suite
+
+import pop_tests
+import popcorn
+
+class TestHandler
+       super Handler
+
+       var marker: String
+
+       redef fun get(req, res) do res.send marker
+end
+
+class TestPopcornRouter
+       super TestPopcorn
+
+       redef fun client_test do
+               system "curl -s {host}:{port}"
+               system "curl -s {host}:{port}/"
+               system "curl -s {host}:{port}/user"
+               system "curl -s {host}:{port}/user/"
+               system "curl -s {host}:{port}/user/settings"
+               system "curl -s {host}:{port}/products"
+               system "curl -s {host}:{port}/products/"
+               system "curl -s {host}:{port}/products/list"
+               system "curl -s {host}:{port}/not_found"
+               system "curl -s {host}:{port}/user/not_found"
+               system "curl -s {host}:{port}/products/not_found"
+       end
+
+       fun test_router do
+               var app = new App
+               app.use("/", new TestHandler("/"))
+               app.use("/about", new TestHandler("/about"))
+
+               var router1 = new App
+               router1.use("/", new TestHandler("/user"))
+               router1.use("/settings", new TestHandler("/user/settings"))
+               app.use("/user", router1)
+
+               var router2 = new App
+               router2.use("/", new TestHandler("/products"))
+               router2.use("/list", new TestHandler("/products/list"))
+               app.use("/products", router2)
+
+               run_test(app)
+       end
+end
+
+class TestPopcornRoutes
+       super TestPopcorn
+
+       redef fun client_test do
+               system "curl -s {host}:{port}"
+               system "curl -s {host}:{port}/"
+               system "curl -s {host}:{port}/misc"
+               system "curl -s {host}:{port}/misc/foo"
+               system "curl -s {host}:{port}/misc/foo/bar"
+               system "curl -s {host}:{port}/misc/foo/baz"
+               system "curl -s {host}:{port}/user"
+               system "curl -s {host}:{port}/user/"
+               system "curl -s {host}:{port}/user/id"
+               system "curl -s {host}:{port}/user/id/profile"
+               system "curl -s {host}:{port}/user/id/misc/foo"
+               system "curl -s {host}:{port}/user/id/misc/foo/bar"
+               system "curl -s {host}:{port}/user/id/misc/foo/bar/baz"
+               system "curl -s {host}:{port}/not_found"
+               system "curl -s {host}:{port}/user/id/not_found"
+       end
+
+       fun test_routes do
+               var app = new App
+               app.use("/", new TestHandler("/"))
+               app.use("/user", new TestHandler("/user"))
+               app.use("/misc/*", new TestHandler("/misc/everything"))
+               app.use("/user/:id", new TestHandler("/user/id"))
+               app.use("/user/:id/profile", new TestHandler("/user/id/profile"))
+               app.use("/user/:id/misc/*", new TestHandler("/user/id/misc/everything"))
+               run_test(app)
+       end
+end
similarity index 98%
rename from lib/popcorn/tests/res/test_router.res
rename to lib/popcorn/test_popcorn.sav/test_router.res
index 37be3a6..1022411 100644 (file)
@@ -47,4 +47,4 @@
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
similarity index 99%
rename from lib/popcorn/tests/res/test_routes.res
rename to lib/popcorn/test_popcorn.sav/test_routes.res
index 0c1abfa..58e47d0 100644 (file)
@@ -46,4 +46,4 @@
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
diff --git a/lib/popcorn/tests/Makefile b/lib/popcorn/tests/Makefile
deleted file mode 100644 (file)
index 7e78098..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright 2013 Alexandre Terrasa <alexandre@moz-code.org>.
-#
-# 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.
-
-all: tests
-
-check: clean
-       ./tests.sh
-
-clean:
-       rm -rf out/
diff --git a/lib/popcorn/tests/base_tests.nit b/lib/popcorn/tests/base_tests.nit
deleted file mode 100644 (file)
index a56a33d..0000000
+++ /dev/null
@@ -1,63 +0,0 @@
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# 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.
-
-import popcorn
-import pthreads
-
-redef class Sys
-       var test_host = "localhost"
-
-       # Return a new port for each instance
-       fun test_port: Int do
-               srand
-               return 10000+20000.rand
-       end
-end
-
-class AppThread
-       super Thread
-
-       var host: String
-       var port: Int
-       var app: App
-
-       redef fun main
-       do
-               # Hide testing concept to force nitcorn to actually run
-               "NIT_TESTING".setenv("false")
-               app.quiet = true
-               app.listen(host, port)
-               return null
-       end
-end
-
-class ClientThread
-       super Thread
-
-       var host: String
-       var port: Int
-
-       redef fun main do return null
-
-       # Regex to catch and hide the port from the output to get consistent results
-       var host_re: Regex = "localhost:\[0-9\]+".to_re
-
-       fun system(cmd: String, title: nullable String)
-       do
-               title = title or else cmd
-               title = title.replace(host_re, "localhost:*****")
-               print "\n[Client] {title}"
-               sys.system cmd
-       end
-end
diff --git a/lib/popcorn/tests/test_router.nit b/lib/popcorn/tests/test_router.nit
deleted file mode 100644 (file)
index 915ce4a..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>
-#
-# 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.
-
-import base_tests
-
-class TestHandler
-       super Handler
-
-       var marker: String
-
-       redef fun get(req, res) do res.send marker
-end
-
-class HelloClient
-       super ClientThread
-
-       redef fun main do
-               system "curl -s {host}:{port}"
-               system "curl -s {host}:{port}/"
-               system "curl -s {host}:{port}/user"
-               system "curl -s {host}:{port}/user/"
-               system "curl -s {host}:{port}/user/settings"
-               system "curl -s {host}:{port}/products"
-               system "curl -s {host}:{port}/products/"
-               system "curl -s {host}:{port}/products/list"
-
-               system "curl -s {host}:{port}/not_found"
-               system "curl -s {host}:{port}/user/not_found"
-               system "curl -s {host}:{port}/products/not_found"
-               return null
-       end
-end
-
-var app = new App
-app.use("/", new TestHandler("/"))
-app.use("/about", new TestHandler("/about"))
-
-var router1 = new App
-router1.use("/", new TestHandler("/user"))
-router1.use("/settings", new TestHandler("/user/settings"))
-app.use("/user", router1)
-
-var router2 = new App
-router2.use("/", new TestHandler("/products"))
-router2.use("/list", new TestHandler("/products/list"))
-app.use("/products", router2)
-
-var host = test_host
-var port = test_port
-
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-var client = new HelloClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-exit 0
diff --git a/lib/popcorn/tests/test_routes.nit b/lib/popcorn/tests/test_routes.nit
deleted file mode 100644 (file)
index 2db660a..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>
-#
-# 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.
-
-import base_tests
-
-class TestHandler
-       super Handler
-
-       var marker: String
-
-       redef fun get(req, res) do res.send marker
-end
-
-class HelloClient
-       super ClientThread
-
-       redef fun main do
-               system "curl -s {host}:{port}"
-               system "curl -s {host}:{port}/"
-
-               system "curl -s {host}:{port}/misc"
-               system "curl -s {host}:{port}/misc/foo"
-               system "curl -s {host}:{port}/misc/foo/bar"
-               system "curl -s {host}:{port}/misc/foo/baz"
-
-               system "curl -s {host}:{port}/user"
-               system "curl -s {host}:{port}/user/"
-               system "curl -s {host}:{port}/user/id"
-               system "curl -s {host}:{port}/user/id/profile"
-               system "curl -s {host}:{port}/user/id/misc/foo"
-               system "curl -s {host}:{port}/user/id/misc/foo/bar"
-               system "curl -s {host}:{port}/user/id/misc/foo/bar/baz"
-
-               system "curl -s {host}:{port}/not_found"
-               system "curl -s {host}:{port}/user/id/not_found"
-               return null
-       end
-end
-
-var app = new App
-app.use("/", new TestHandler("/"))
-app.use("/user", new TestHandler("/user"))
-app.use("/misc/*", new TestHandler("/misc/everything"))
-app.use("/user/:id", new TestHandler("/user/id"))
-app.use("/user/:id/profile", new TestHandler("/user/id/profile"))
-app.use("/user/:id/misc/*", new TestHandler("/user/id/misc/everything"))
-
-var host = test_host
-var port = test_port
-
-# First, launch a server in the background
-var server = new AppThread(host, port, app)
-server.start
-0.1.sleep
-
-# Then, launch a client running test requests
-var client = new HelloClient(host, port)
-client.start
-client.join
-0.1.sleep
-
-# Force quit the server
-exit 0
diff --git a/lib/popcorn/tests/tests.sh b/lib/popcorn/tests/tests.sh
deleted file mode 100755 (executable)
index 4406058..0000000
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/bash
-
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2016 Alexandre Terrasa <alexandre@moz-code.org>.
-#
-# 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.
-
-BIN=../bin
-OUT=./out
-RES=./res
-
-NITC=../../../bin/nitc
-
-compile() {
-       local test="$1"
-       $NITC $test.nit -o $OUT/$test.bin 1>&2 2> $OUT/$test.cmp_err
-}
-
-test_prog()
-{
-       local test="$1"
-
-       chmod +x $OUT/$test.bin 2> $OUT/$test.err
-       $OUT/$test.bin > $OUT/$test.res 2> $OUT/$test.err
-
-       diff $OUT/$test.res $RES/$test.res > $OUT/$test.diff 2> /dev/null
-}
-
-# return
-#  0 if the sav not exists
-#  1 if the file does match
-#  2 if the file does not match
-check_result() {
-       local test="$1"
-
-       if [ -s "$OUT/$test.cmp_err" ]; then
-               return 0
-       elif [ -s "$OUT/$test.err" ]; then
-               return 1
-       elif [ ! -r "$RES/$test.res" ]; then
-               return 2
-       elif [ -s "$OUT/$test.diff" ]; then
-               return 3
-       else
-               return 4
-       fi
-}
-
-echo "Testing..."
-echo ""
-
-rm -rf $OUT 2>/dev/null
-mkdir $OUT 2>/dev/null
-
-all=0
-ok=0
-ko=0
-sk=0
-
-for file in `ls test_*.nit`; do
-       ((all++))
-       test="${file%.*}"
-       echo -n "* $test: "
-
-       compile $test
-       test_prog $test
-       check_result $test
-
-       case "$?" in
-               0)
-                       echo "compile error (cat $OUT/$test.cmp_err)"
-                       ((ko++))
-                       ;;
-               1)
-                       echo "error (cat $OUT/$test.cmp_err)"
-                       ((ko++))
-                       ;;
-               2)
-                       echo "skip ($test.res not found)"
-                       ((sk++))
-                       continue;;
-               3)
-                       echo "error (diff $OUT/$test.res $RES/$test.res)"
-                       ((ko++))
-                       ;;
-               4)
-                       echo "success"
-                       ((ok++))
-                       ;;
-
-       esac
-done
-echo ""
-echo "==> success $ok/$all ($ko tests failed, $sk skipped)"
-
-# return result
-test "$ok" == "$all"