From c17f1d5fed096b97b3e757f8aa7841ccb23e4631 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Wed, 23 Jul 2014 12:27:28 -0400 Subject: [PATCH] toolcontext: provide option `set-dummy-tool` used to fix the `toolname` and `version` services so they return respectively "DUMMY_TOOL" and "DUMMY_VERSION". Useful for testing. Signed-off-by: Alexandre Terrasa --- src/toolcontext.nit | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/toolcontext.nit b/src/toolcontext.nit index 5b9d020..49e3cdc 100644 --- a/src/toolcontext.nit +++ b/src/toolcontext.nit @@ -3,6 +3,7 @@ # Copyright 2006-2008 Floréal Morandat # Copyright 2008-2012 Jean Privat # Copyright 2009 Jean-Sebastien Gelinas +# Copyright 2014 Alexandre Terrasa # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -182,6 +183,9 @@ class ToolContext # Option --version var opt_version: OptionBool = new OptionBool("Show version and exit", "--version") + # Option --set-dummy-tool + var opt_set_dummy_tool: OptionBool = new OptionBool("Set toolname and version to DUMMY. Useful for testing", "--set-dummy-tool") + # Option --verbose var opt_verbose: OptionCount = new OptionCount("Verbose", "-v", "--verbose") @@ -196,7 +200,7 @@ class ToolContext init do - option_context.add_option(opt_warn, opt_quiet, opt_stop_on_first_error, opt_no_color, opt_log, opt_log_dir, opt_help, opt_version, opt_verbose) + option_context.add_option(opt_warn, opt_quiet, opt_stop_on_first_error, opt_no_color, opt_log, opt_log_dir, opt_help, opt_version, opt_set_dummy_tool, opt_verbose) end # Name, usage and synopsis of the tool. @@ -237,7 +241,7 @@ class ToolContext end if opt_version.value then - print nit_version + print version exit 0 end @@ -269,6 +273,22 @@ class ToolContext nit_dir = compute_nit_dir end + # Get the current `nit_version` or "DUMMY_VERSION" if `--set-dummy-tool` is set. + fun version: String do + if opt_set_dummy_tool.value then + return "DUMMY_VERSION" + end + return nit_version + end + + # Get the name of the tool or "DUMMY_TOOL" id `--set-dummy-tool` is set. + fun toolname: String do + if opt_set_dummy_tool.value then + return "DUMMY_TOOL" + end + return sys.program_name + end + # The identified root directory of the Nit project var nit_dir: nullable String -- 1.7.9.5