From 5c747818fe11ab11173073bd6dd4fae25052cf06 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Sun, 7 May 2017 18:34:37 -0400 Subject: [PATCH] app.nit: exit and print an error if not bound to a platform MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/android/platform.nit | 3 +++ lib/app/app_base.nit | 11 +++++++++++ lib/gamnit/gamnit.nit | 8 -------- lib/linux/linux.nit | 3 +++ 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/android/platform.nit b/lib/android/platform.nit index f305144..3a2e105 100644 --- a/lib/android/platform.nit +++ b/lib/android/platform.nit @@ -19,6 +19,9 @@ module platform is platform "android" import java import app +intrude import app::app_base # For test_bound_platform import aware redef fun bound_platform do return "Android" + +redef fun test_bound_platform do end diff --git a/lib/app/app_base.nit b/lib/app/app_base.nit index e3e870a..5c2a902 100644 --- a/lib/app/app_base.nit +++ b/lib/app/app_base.nit @@ -122,5 +122,16 @@ fun app: App do return once new App # However, this value can be used in log files and communications with servers. fun bound_platform: String do return "none" +# Test if the application was bound to a platform, if not crash +private fun test_bound_platform +do + print_error "Apps must be bound to a platform at compilation using `-m linux` or `-m android`" + exit 1 +end + +if "NIT_TESTING".environ == "true" then exit 0 + +test_bound_platform + app.setup app.run diff --git a/lib/gamnit/gamnit.nit b/lib/gamnit/gamnit.nit index 41bfb37..0d39f1e 100644 --- a/lib/gamnit/gamnit.nit +++ b/lib/gamnit/gamnit.nit @@ -78,11 +78,3 @@ redef class App # right after this method returns. They should not be preserved. fun accept_event(event: InputEvent): Bool do return false end - -redef class Sys - redef fun run - do - if "NIT_TESTING".environ == "true" then exit 0 - super - end -end diff --git a/lib/linux/linux.nit b/lib/linux/linux.nit index 32a5ad4..3f08b98 100644 --- a/lib/linux/linux.nit +++ b/lib/linux/linux.nit @@ -18,6 +18,7 @@ module linux import app +intrude import app::app_base # For test_bound_platform redef class App # Path to the expected location of the asset folder of this program @@ -62,3 +63,5 @@ redef class TextAsset end redef fun bound_platform do return "GNU/Linux" + +redef fun test_bound_platform do end -- 1.7.9.5