Merge: Popcorn: clean tests
authorJean Privat <jean@pryen.org>
Thu, 18 May 2017 15:02:05 +0000 (11:02 -0400)
committerJean Privat <jean@pryen.org>
Thu, 18 May 2017 15:02:05 +0000 (11:02 -0400)
This PR does two things:
* clean the lib by moving all the tests to `tests/` directories, easier to see what is important, great visual improvement for the examples.
* use a lot of imagination to avoid the `class name X already used`. It mostly replaces Short&Cool names by LooooonnggggandAndBooooringNameForSoSimpleHandler. No more warnings when make checking.

Pull-Request: #2434
Reviewed-by: Jean Privat <jean@pryen.org>

40 files changed:
lib/popcorn/Makefile
lib/popcorn/examples/angular/tests/test_example_angular.nit [moved from lib/popcorn/examples/angular/test_example_angular.nit with 91% similarity]
lib/popcorn/examples/angular/tests/test_example_angular.res [moved from lib/popcorn/examples/angular/test_example_angular.sav/test_example_angular.res with 99% similarity]
lib/popcorn/examples/handlers/tests/test_example_post_handler.nit [moved from lib/popcorn/examples/handlers/test_example_post_handler.nit with 95% similarity]
lib/popcorn/examples/handlers/tests/test_example_post_handler.res [moved from lib/popcorn/examples/handlers/test_example_post_handler.sav/test_example_post_handler.res with 93% similarity]
lib/popcorn/examples/handlers/tests/test_example_query_string.nit [moved from lib/popcorn/examples/handlers/test_example_query_string.nit with 97% similarity]
lib/popcorn/examples/handlers/tests/test_example_query_string.res [moved from lib/popcorn/examples/handlers/test_example_query_string.sav/test_example_query_string.res with 99% similarity]
lib/popcorn/examples/hello_world/tests/test_example_hello.nit [moved from lib/popcorn/examples/hello_world/test_example_hello.nit with 100% similarity]
lib/popcorn/examples/hello_world/tests/test_example_hello.res [moved from lib/popcorn/examples/hello_world/test_example_hello.sav/test_example_hello.res with 100% similarity]
lib/popcorn/examples/middlewares/example_advanced_logger.nit
lib/popcorn/examples/middlewares/example_simple_error_handler.nit
lib/popcorn/examples/middlewares/example_simple_logger.nit
lib/popcorn/examples/middlewares/tests/test_example_advanced_logger.nit [moved from lib/popcorn/examples/middlewares/test_example_advanced_logger.nit with 89% similarity]
lib/popcorn/examples/middlewares/tests/test_example_advanced_logger.res [moved from lib/popcorn/examples/middlewares/test_example_advanced_logger.sav/test_example_advanced_logger.res with 96% similarity]
lib/popcorn/examples/middlewares/tests/test_example_html_error_handler.nit [moved from lib/popcorn/examples/middlewares/test_example_html_error_handler.nit with 96% similarity]
lib/popcorn/examples/middlewares/tests/test_example_html_error_handler.res [moved from lib/popcorn/examples/middlewares/test_example_html_error_handler.sav/test_example_html_error_handler.res with 97% similarity]
lib/popcorn/examples/middlewares/tests/test_example_simple_error_handler.nit [moved from lib/popcorn/examples/middlewares/test_example_simple_error_handler.nit with 93% similarity]
lib/popcorn/examples/middlewares/tests/test_example_simple_error_handler.res [moved from lib/popcorn/examples/middlewares/test_example_simple_error_handler.sav/test_example_simple_error_handler.res with 82% similarity]
lib/popcorn/examples/middlewares/tests/test_example_simple_logger.nit [moved from lib/popcorn/examples/middlewares/test_example_simple_logger.nit with 89% similarity]
lib/popcorn/examples/middlewares/tests/test_example_simple_logger.res [moved from lib/popcorn/examples/middlewares/test_example_simple_logger.sav/test_example_simple_logger.res with 96% similarity]
lib/popcorn/examples/routing/example_router.nit
lib/popcorn/examples/routing/tests/test_example_glob_route.nit [moved from lib/popcorn/examples/routing/test_example_glob_route.nit with 100% similarity]
lib/popcorn/examples/routing/tests/test_example_glob_route.res [moved from lib/popcorn/examples/routing/test_example_glob_route.sav/test_example_glob_route.res with 100% similarity]
lib/popcorn/examples/routing/tests/test_example_param_route.nit [moved from lib/popcorn/examples/routing/test_example_param_route.nit with 100% similarity]
lib/popcorn/examples/routing/tests/test_example_param_route.res [moved from lib/popcorn/examples/routing/test_example_param_route.sav/test_example_param_route.res with 100% similarity]
lib/popcorn/examples/routing/tests/test_example_router.nit [moved from lib/popcorn/examples/routing/test_example_router.nit with 97% similarity]
lib/popcorn/examples/routing/tests/test_example_router.res [moved from lib/popcorn/examples/routing/test_example_router.sav/test_example_router.res with 100% similarity]
lib/popcorn/examples/sessions/tests/test_example_session.nit [moved from lib/popcorn/examples/sessions/test_example_session.nit with 97% similarity]
lib/popcorn/examples/sessions/tests/test_example_session.res [moved from lib/popcorn/examples/sessions/test_example_session.sav/test_example_session.res with 98% similarity]
lib/popcorn/examples/static_files/tests/test_example_static.nit [moved from lib/popcorn/examples/static_files/test_example_static.nit with 92% similarity]
lib/popcorn/examples/static_files/tests/test_example_static.res [moved from lib/popcorn/examples/static_files/test_example_static.sav/test_example_static.res with 99% similarity]
lib/popcorn/examples/static_files/tests/test_example_static_default.nit [moved from lib/popcorn/examples/static_files/test_example_static_default.nit with 91% similarity]
lib/popcorn/examples/static_files/tests/test_example_static_default.res [moved from lib/popcorn/examples/static_files/test_example_static_default.sav/test_example_static_default.res with 99% similarity]
lib/popcorn/examples/static_files/tests/test_example_static_multiple.nit [moved from lib/popcorn/examples/static_files/test_example_static_multiple.nit with 81% similarity]
lib/popcorn/examples/static_files/tests/test_example_static_multiple.res [moved from lib/popcorn/examples/static_files/test_example_static_multiple.sav/test_example_static_multiple.res with 99% similarity]
lib/popcorn/pop_tests.nit
lib/popcorn/tests/test_pop_routes.nit [moved from lib/popcorn/test_pop_routes.nit with 100% similarity]
lib/popcorn/tests/test_popcorn.nit [moved from lib/popcorn/test_popcorn.nit with 100% similarity]
lib/popcorn/tests/test_popcorn.sav/test_router.res [moved from lib/popcorn/test_popcorn.sav/test_router.res with 100% similarity]
lib/popcorn/tests/test_popcorn.sav/test_routes.res [moved from lib/popcorn/test_popcorn.sav/test_routes.res with 100% similarity]

index ad89fec..ed29191 100644 (file)
@@ -19,4 +19,4 @@ NITUNIT=nitunit
 all:
 
 check:
-       $(NITUNIT) .
+       $(NITUNIT) . tests/ examples/
@@ -29,10 +29,10 @@ class TestExampleAngular
                system "curl -s {host}:{port}/not_found" # handled by angular controller
        end
 
-       fun test_example_param_route do
+       fun test_example_angular do
                var app = new App
                app.use("/counter", new CounterAPI)
-               app.use("/*", new StaticHandler("../examples/angular/www/", "index.html"))
+               app.use("/*", new StaticHandler(test_path / "../www/", "index.html"))
                run_test(app)
        end
 end
@@ -19,7 +19,7 @@ module test_example_post_handler is test_suite
 import pop_tests
 import example_post_handler
 
-class TestExampleQueryString
+class TestExamplePostHandler
        super TestPopcorn
 
        redef fun client_test do
@@ -31,7 +31,7 @@ class TestExampleQueryString
                system "curl -s {host}:{port}/"
        end
 
-       fun test_example_glob_route do
+       fun test_example_post_handler do
                var app = new App
                app.use("/", new PostHandler)
                run_test(app)
@@ -4,7 +4,6 @@ URI: /
 Body: 
 
 [Client] curl -s localhost:*****/ --data 'user'
-POST Error: user format error on user
 URI: /
 Body: user
 
@@ -35,4 +34,4 @@ order: desc
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
@@ -30,7 +30,7 @@ class TestExampleQueryString
                system "curl -s {host}:{port}/?items=10\\&order=asc"
        end
 
-       fun test_example_glob_route do
+       fun test_example_query_string do
                var app = new App
                app.use("/", new QueryStringHandler)
                run_test(app)
index 4ca9120..a8ad514 100644 (file)
@@ -28,7 +28,7 @@ class RequestTimeHandler
        redef fun all(req, res) do req.timer = new Clock
 end
 
-class LogHandler
+class AdvancedLoggerHandler
        super Handler
 
        redef fun all(req, res) do
@@ -41,7 +41,7 @@ class LogHandler
        end
 end
 
-class HelloHandler
+class AnotherHandler
        super Handler
 
        redef fun get(req, res) do res.send "Hello World!"
@@ -49,6 +49,6 @@ end
 
 var app = new App
 app.use_before("/*", new RequestTimeHandler)
-app.use("/", new HelloHandler)
-app.use_after("/*", new LogHandler)
+app.use("/", new AnotherHandler)
+app.use_after("/*", new AdvancedLoggerHandler)
 app.listen("localhost", 3000)
index 16a5977..7d1b73c 100644 (file)
@@ -26,7 +26,7 @@ class SimpleErrorHandler
        end
 end
 
-class HelloHandler
+class SomeHandler
        super Handler
 
        redef fun get(req, res) do res.send "Hello World!"
@@ -34,6 +34,6 @@ end
 
 
 var app = new App
-app.use("/", new HelloHandler)
+app.use("/", new SomeHandler)
 app.use("/*", new SimpleErrorHandler)
 app.listen("localhost", 3000)
index 4052169..73aff4f 100644 (file)
 
 import popcorn
 
-class LogHandler
+class SimpleLoggerHandler
        super Handler
 
        redef fun all(req, res) do print "Request Logged"
 end
 
-class HelloHandler
+class MyOtherHandler
        super Handler
 
        redef fun get(req, res) do res.send "Hello World!"
@@ -30,6 +30,6 @@ end
 
 
 var app = new App
-app.use_before("/*", new LogHandler)
-app.use("/", new HelloHandler)
+app.use_before("/*", new SimpleLoggerHandler)
+app.use("/", new MyOtherHandler)
 app.listen("localhost", 3000)
@@ -27,11 +27,11 @@ class TestExampleAdvancedLogger
                system "curl -s {host}:{port}/about"
        end
 
-       fun test_example_param_route do
+       fun test_example_advanced_logger do
                var app = new App
                app.use_before("/*", new RequestTimeHandler)
-               app.use("/", new HelloHandler)
-               app.use_after("/*", new LogHandler)
+               app.use("/", new AnotherHandler)
+               app.use_after("/*", new AdvancedLoggerHandler)
                run_test(app)
        end
 end
@@ -13,4 +13,4 @@ GET /about \e[33m404\e[m (0.0s)
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
@@ -27,7 +27,7 @@ class TestExampleHtmlErrorHandler
                system "curl -s {host}:{port}/about"
        end
 
-       fun test_example_param_route do
+       fun test_example_html_error_handler do
                var app = new App
                app.use("/*", new HtmlErrorHandler)
                run_test(app)
@@ -27,9 +27,9 @@ class TestExampleSimpleErrorHandler
                system "curl -s {host}:{port}/about"
        end
 
-       fun test_example_param_route do
+       fun test_example_simple_error_handler do
                var app = new App
-               app.use("/", new HelloHandler)
+               app.use("/", new SomeHandler)
                app.use("/*", new SimpleErrorHandler)
                run_test(app)
        end
@@ -27,10 +27,10 @@ class TestExampleSimpleLogger
                system "curl -s {host}:{port}/about"
        end
 
-       fun test_example_param_route do
+       fun test_example_simple_logger do
                var app = new App
-               app.use_before("/*", new LogHandler)
-               app.use("/", new HelloHandler)
+               app.use_before("/*", new SimpleLoggerHandler)
+               app.use("/", new MyOtherHandler)
                run_test(app)
        end
 end
@@ -13,4 +13,4 @@ Request Logged
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
index 91aa3ab..facce99 100644 (file)
@@ -28,7 +28,7 @@ class UserLogger
        redef fun all(req, res) do print "User logged"
 end
 
-class UserHome
+class UserHomepage
        super Handler
 
        redef fun get(req, res) do res.send "User Home"
@@ -42,7 +42,7 @@ end
 
 var user_router = new Router
 user_router.use("/*", new UserLogger)
-user_router.use("/", new UserHome)
+user_router.use("/", new UserHomepage)
 user_router.use("/profile", new UserProfile)
 
 var app = new App
@@ -36,7 +36,7 @@ class TestExampleRouter
        fun test_example_router do
                var user_router = new Router
                user_router.use("/*", new UserLogger)
-               user_router.use("/", new UserHome)
+               user_router.use("/", new UserHomepage)
                user_router.use("/profile", new UserProfile)
                var app = new App
                app.use("/", new AppHome)
@@ -30,7 +30,7 @@ class TestExampleSession
                system "curl -s {host}:{port}/products/not_found"
        end
 
-       fun test_example_param_route do
+       fun test_example_session do
                var app = new App
                app.use("/*", new SessionInit)
                app.use("/", new AppLogin)
@@ -38,4 +38,4 @@
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
@@ -32,9 +32,9 @@ class TestExampleStatic
                system "curl -s {host}:{port}/not_found.nit"
        end
 
-       fun test_example_param_route do
+       fun test_example_static do
                var app = new App
-               app.use("/", new StaticHandler("../examples/static_files/public/"))
+               app.use("/", new StaticHandler(test_path / "../public/"))
                run_test(app)
        end
 end
@@ -70,4 +70,4 @@ alert("Hello World!");
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
@@ -32,9 +32,9 @@ class TestExampleStaticDefault
                system "curl -s {host}:{port}/not_found.nit"
        end
 
-       fun test_example_param_route do
+       fun test_example_static_default do
                var app = new App
-               app.use("/", new StaticHandler("../examples/static_files/public/", "default.html"))
+               app.use("/", new StaticHandler(test_path / "../public/", "default.html"))
                run_test(app)
        end
 end
@@ -36,12 +36,12 @@ class TestExampleStaticMultiple
                system "curl -s {host}:{port}/not_found.nit"
        end
 
-       fun test_example_param_route do
+       fun test_example_static_multiple 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/"))
+               app.use("/", new StaticHandler(test_path / "../public/"))
+               app.use("/", new StaticHandler(test_path / "../files/"))
+               app.use("/static", new StaticHandler(test_path / "../public/"))
+               app.use("/static", new StaticHandler(test_path / "../files/"))
                run_test(app)
        end
 end
@@ -103,4 +103,4 @@ alert("Hello World!");
                <body>
                <h1>404 Not Found</h1>
                </body>
-               </html>
\ No newline at end of file
+               </html>
index 1deaeab..6c5985d 100644 (file)
@@ -131,6 +131,11 @@ class TestPopcorn
        # Port used to run App.
        var port: Int = test_port
 
+       # Directory of the current test suite
+       #
+       # Useful when your tested app need to load some external files.
+       var test_path: String = "NIT_TESTING_PATH".environ.dirname
+
        # Run the test suite on the App.
        fun run_test(app: App) do
                var server = new AppThread(host, port, app)