nitmetrics: do not crash in `to_console` if no values to present
authorJean Privat <jean@pryen.org>
Wed, 12 Mar 2014 13:58:33 +0000 (09:58 -0400)
committerJean Privat <jean@pryen.org>
Wed, 12 Mar 2014 13:58:33 +0000 (09:58 -0400)
The crash occurs since `max` and `min` assert that `not values.is_empty`.

Signed-off-by: Jean Privat <jean@pryen.org>

src/metrics/metrics_base.nit

index 056aba4..64770df 100644 (file)
@@ -170,6 +170,15 @@ interface Metric
 
        # Pretty print the metric results in console
        fun to_console(indent: Int, colors: Bool) do
+               if values.is_empty then
+                       if colors then
+                               print "{"\t" * indent}{name}: {desc} -- nothing".green
+                       else
+                               print "{"\t" * indent}{name}: {desc} -- nothing"
+                       end
+                       return
+               end
+
                var max = self.max
                var min = self.min
                if colors then