<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>michaelgalloy.com &#187; Search Results  &#187;  mgunit+1.0</title>
	<atom:link href="http://michaelgalloy.com/search/mgunit+1.0/feed/rss2/" rel="self" type="application/rss+xml" />
	<link>http://michaelgalloy.com</link>
	<description>Resources for IDL developers</description>
	<lastBuildDate>Mon, 06 Feb 2012 20:16:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Command line options for your IDL program</title>
		<link>http://michaelgalloy.com/2009/05/11/command-line-options-for-your-idl-program.html</link>
		<comments>http://michaelgalloy.com/2009/05/11/command-line-options-for-your-idl-program.html#comments</comments>
		<pubDate>Tue, 12 May 2009 03:52:21 +0000</pubDate>
		<dc:creator>Michael Galloy</dc:creator>
				<category><![CDATA[IDL]]></category>
		<category><![CDATA[original]]></category>

		<guid isPermaLink="false">http://michaelgalloy.com/?p=605</guid>
		<description><![CDATA[The COMMAND_LINE_ARGS routine was introduced in IDL 6.2, allowing IDL programs to access command line args passed to IDL when starting it. For example, to pass command line arguments into the MYPROGRAM routine, call IDL like below: $ idl -e "myprogram" -args a b c Then, in MYPROGRAM, the command line arguments could be retrieved [...]]]></description>
			<content:encoded><![CDATA[<p>The <code>COMMAND_LINE_ARGS</code> routine was introduced in IDL 6.2, allowing IDL programs to access command line args passed to IDL when starting it. For example, to pass command line arguments into the <code>MYPROGRAM</code> routine, call IDL like below:</p>

<pre><code>$ idl -e "myprogram" -args a b c
</code></pre>

<p>Then, in <code>MYPROGRAM</code>, the command line arguments could be retrieved with:</p>

<pre><code>args = command_line_args()
</code></pre>

<p>The <code>args</code> string array would contain &#8220;a&#8221;, &#8220;b&#8221;, and &#8220;c&#8221;. To make it more convenient to launch IDL this way, you can create a script that calls IDL in the proper way, passing arguments of the script to arguments listed after the <code>-args</code> in the IDL call. If you name the wrapper script <code>myprogram</code> also, your calls would look like:</p>

<pre><code>$ myprogram a b c
</code></pre>

<p>But, suppose you wanted your routine to have command line switches like:</p>

<pre><code>$ myprogram --verbose --header=test.hdr test.dat
</code></pre>

<p>Then you had to parse the args received from <code>COMMAND_LINE_ARGS</code> yourself. The <code>mg_options</code> class simplifies this parsing and adds several other conveniences.</p>

<p><span id="more-605"></span></p>

<p>The <code>mg_options</code> class can be instantiated with the optional <code>APP_NAME</code> and <code>VERSION</code> properties:</p>

<pre><code>opts = obj_new('mg_options', app_name='mgunit', version='1.0.0beta')
</code></pre>

<p>Next, add options using the <code>addOption</code> method:</p>

<pre><code>opts-&gt;addOption, 'color', 'c', /boolean, $
                 help='produce color output on STDOUT'
opts-&gt;addOption, 'filename', $
                 help='specify a log filename'
opts-&gt;addOption, 'gui', 'g', /boolean, $
                 help='start a GUI to run the tests'
opts-&gt;addOption, 'html', 'm', /boolean, $
                 help='produce HTML output'
</code></pre>

<p>The two positional parameters of <code>addOption</code> are the full name of the option (used with &#8220;&#8211;&#8221;) and an optional short name (used with just a single &#8220;-&#8221;). The help keyword gives a description of the option displayed when the help option is given (the help option is automatically created for you). The boolean keyword indicates that the option does not take a value, it&#8217;s presence indicates it is &#8220;on&#8221;.</p>

<p>Next, add the positional parameters:</p>

<pre><code>opts-&gt;addParams, [0, -1]
</code></pre>

<p>This indicates the minimum and maximum number of positional parameters, with <code>-1</code> indicating there is no maximum number.</p>

<p>After defining all the options and parameters, the arguments to the program can be parsed:</p>

<pre><code>opts-&gt;parseArgs, error_message=errorMsg
</code></pre>

<p>The <code>ERROR_MESSAGE</code> keyword will contain parse error message if they occur, otherwise it will be an empty string.</p>

<p>After the parsing, use the <code class="method">get</code> method to retrieve the value of the parameters:</p>

<pre><code>if (errorMsg eq '') then begin
  params = opts-&gt;get(/params, n_params=nparams)

  if (nparams gt 0L &amp;&amp; ~opts-&gt;get('help')) then begin
    filename = opts-&gt;get('filename', present=filenamePresent)
    if (filenamePresent) then begin
      mgunit, params, $
              color=opts-&gt;get('color'), $
              filename=opts-&gt;get('filename'), $
              gui=opts-&gt;get('gui'), $
              html=opts-&gt;get('html')
    endif else begin
      mgunit, params, $
              color=opts-&gt;get('color'), $
              gui=opts-&gt;get('gui'), $
              html=opts-&gt;get('html')
    endelse
  endif
endif else begin
  message, errorMsg, /informational, /noname
endelse
</code></pre>

<p>Don&#8217;t forget to free the options object when finished:</p>

<pre><code>obj_destroy, opts
</code></pre>

<p>A help option is automatically created to display information about the options:</p>

<pre><code>$ mgunit --help
usage: mgunit [options] ...

options:
  --color, -c          produce color output on STDOUT
  --filename=FILENAME  specify a log filename
  --gui, -g            start a GUI to run the tests
  --help, -h           display this help
  --html, -m           produce HTML output
  --version            display version information
</code></pre>

<p>Because we set the <code>APP_NAME</code> and <code>VERSION</code> properties when instantiating the options object, the <code>version</code> option gives useful information:</p>

<pre><code>$ mgunit --version
mgunit 1.0.0beta
</code></pre>

<p></p></p>

<p>So the command line options can be used as follows:</p>

<pre><code>$ mgunit --color --filename=unittests.txt gpu_alltests_uts
</code></pre>

<p>This is translated in the wrapper to:</p>

<pre><code>IDL&gt; mgunit, 'gpu_alltests_uts', /color, filename='unittests.txt'
</code></pre>

<p>Here&#8217;s the <a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mg_options__define.pro">source code</a> (<a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mg_options__define.html">docs</a>). You will need the <a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mgcohashtable__define.pro">hash table</a>, <a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mgcoarraylist__define.pro">array list</a>, and <a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mgcoabstractlist__define.pro">abstract list</a> classes also.</p></p>
]]></content:encoded>
			<wfw:commentRss>http://michaelgalloy.com/2009/05/11/command-line-options-for-your-idl-program.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>mgunit 1.0 released</title>
		<link>http://michaelgalloy.com/2009/04/27/mgunit-10-released.html</link>
		<comments>http://michaelgalloy.com/2009/04/27/mgunit-10-released.html#comments</comments>
		<pubDate>Mon, 27 Apr 2009 16:29:31 +0000</pubDate>
		<dc:creator>Michael Galloy</dc:creator>
				<category><![CDATA[IDL]]></category>

		<guid isPermaLink="false">http://michaelgalloy.com/?p=625</guid>
		<description><![CDATA[I&#8217;ve released mgunit 1.0: get the source distribution or save file distribution. Also check out the project website to join the mgunit mailing list, read a short tutorial, check out development code from Subversion, etc. Some features of the 1.0 release: Several test runners for outputting test results to various formats are available; output can [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released mgunit 1.0: get the <a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mgunit-src-1.0.0-r70.zip">source distribution</a> or <a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mgunit-1.0.0-r70.zip">save file distribution</a>. Also check out the project website to join the mgunit mailing list, read a short tutorial, check out development code from Subversion, etc.</p>

<p>Some features of the 1.0 release:</p>

<ol>
<li><p>Several test runners for outputting test results to various formats are available; output can be sent to stdout, log files, or html files. In addition, there is a GUI test runner that will show results and re-run tests with the push of a button (also recompiling tests before running them).</p></li>
<li><p>Contains IDL Workbench templates for making it even faster to create new test cases/suites.</p></li>
<li><p>Keywords to <code>MGUNIT</code> to retrieve the number of passing and failing tests.</p></li>
</ol>

<p>Color output to the terminal window when possible.</p>

<p>Command line wrapper so that mgunit can be run from the UNIX command line (get the source distribution to use this ability).</p>

<p>This release also contains several bug fixes.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelgalloy.com/2009/04/27/mgunit-10-released.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>mgunit 1.0 beta</title>
		<link>http://michaelgalloy.com/2009/04/17/mgunit-10-beta.html</link>
		<comments>http://michaelgalloy.com/2009/04/17/mgunit-10-beta.html#comments</comments>
		<pubDate>Fri, 17 Apr 2009 20:41:52 +0000</pubDate>
		<dc:creator>Michael Galloy</dc:creator>
				<category><![CDATA[IDL]]></category>

		<guid isPermaLink="false">http://michaelgalloy.com/?p=548</guid>
		<description><![CDATA[Before I release mgunit 1.0, I would like to get a some feedback. I am using this for all the testing of my projects, but I would like to make sure it is working for others&#8217; use cases. Several test runners for outputting test results to various formats are available; output can be sent to [...]]]></description>
			<content:encoded><![CDATA[<p>Before I release mgunit 1.0, I would like to get a some feedback. I am using this for all the testing of my projects, but I would like to make sure it is working for others&#8217; use cases.</p>

<ol>
<li><p>Several test runners for outputting test results to various formats are available; output can be sent to stdout, log files, or html files. In addition, there is a GUI test runner that will show results and re-run tests with the push of a button (also recompiling tests before running them).</p></li>
<li><p>Contains IDL Workbench templates for making it even faster to create new test cases/suites.</p></li>
<li><p>Keywords to <code>mgunit</code> to retrieve the number of passing and failing tests.</p></li>
<li><p>Color output to the terminal window when possible.</p></li>
</ol>

<p>This release also contains several bug fixes.</p>

<p>I recommend getting the source distribution so that you don&#8217;t have to do a manual restore: <a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mgunit-src-1.0.0beta-r54.zip">source distribution</a> and <a href="http://michaelgalloy.com/wp-content/uploads/2009/04/mgunit-1.0.0beta-r54.zip">save file distribution</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelgalloy.com/2009/04/17/mgunit-10-beta.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit testing framework</title>
		<link>http://michaelgalloy.com/2007/01/04/unit-testing-framework.html</link>
		<comments>http://michaelgalloy.com/2007/01/04/unit-testing-framework.html#comments</comments>
		<pubDate>Fri, 05 Jan 2007 04:48:23 +0000</pubDate>
		<dc:creator>Michael Galloy</dc:creator>
				<category><![CDATA[IDL]]></category>
		<category><![CDATA[original]]></category>

		<guid isPermaLink="false">http://michaelgalloy.com/2007/01/04/unit-testing-framework.html</guid>
		<description><![CDATA[MGunit is a unit testing framework modeled on other unit testing frameworks such as JUnit. The goal is to allow easy creation and reporting of results of tests, but still allow for all needed flexibility. More details and examples after the jump. The structure of tests created for this framework is straightforward. Individual tests are [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://michaelgalloy.com/wp-content/uploads/2007/01/mgunit.zip">MGunit</a> is a unit testing framework modeled on other unit testing frameworks such as JUnit. The goal is to allow easy creation and reporting of results of tests, but still allow for all needed flexibility. More details and examples after the jump.</p>

<p><span id="more-83"></span></p>

<p>The structure of tests created for this framework is straightforward. Individual tests are methods of an class that subclasses <code>MGtestCase</code>. Each method returns 1 for success or 0 for failure (or throws an error). Each test method&#8217;s name must start with &#8220;test&#8221;. Test cases may be (but are not required to be) grouped into test suites.</p>

<p>The examples (<a href="http://michaelgalloy.com/demos/tests/findgentest__define.pro"><code>FINDGENTEST</code></a>, <a href="http://michaelgalloy.com/demos/tests/indgentest__define.pro"><code>INDGENTEST</code></a>, and <a href="http://michaelgalloy.com/demos/tests/indgensuite__define.pro"><code>INDGENSUITE</code></a>) of MGunit discussed are available for download.</p>

<p>To create a test, subclass <code>MGtestCase</code> like:</p>

<pre><code>pro findgentest__define
  define = { findgentest, inherits MGtestCase }
end
</code></pre>

<p>A test is just a method whose name starts with &#8220;test&#8221;. MGunit will find the tests automatically (make sure they are either already compiled or above <code>FINDGENTEST__DEFINE</code> in the same file). A test case may have as many tests as necessary. For example, a simple test:</p>

<pre><code>function findgentest::test2
  a = findgen(5)
  assert, array_equal(a, [0.0, 1.0, 2.0, 3.0, 4.0]), 'Correct elements'

  return, 1
end
</code></pre>

<p>Return 1 for success. For failure, either return 0 or throw an error. Here the helper routine <code>ASSERT</code> will throw an error using the given message if its condition is not met. This will be reported as a failure along with the message. To run this test, use:</p>

<pre><code>IDL&gt; mgunit, 'findgentest'
</code></pre>

<p>Results can be sent to a log file with the <code>LOG_FILE</code>:</p>

<pre><code>IDL&gt; mgunit, 'findgentest', log_file='results.log'
</code></pre>

<p>This should produce the output:</p>

<pre><code>Starting test suite MGTESTSUITE (1 test case, 4 tests)
   Starting FINDGENTEST (4 tests)
      TEST1: failed "Wrong number of elements"
      TEST2: passed
      TEST3: passed
      TEST4: failed "Type conversion error: Unable to convert..."
      Results: 2 / 4 tests passed
   Results: 2 / 4 tests passed
</code></pre>

<p>One tricky situation is that sometimes invalid input must be tested to make sure the routine fails. In this case, throwing an error should indicate a success of the test, not a failure. In this case use the provided batch file <code>error_is_pass</code> at the beginning of the routine, like:</p>

<pre><code>function findgentest::test3
  @error_is_pass

  a = findgen('string')

  return, 1
end
</code></pre>

<p>Multiple test cases can be specified as an array</p>

<pre><code>IDL&gt; mgunit, ['findgentest', 'indgentest']
</code></pre>

<p>or by creating a test suite. Test suites are very simple; they are just collections of test cases. To make a suite, subclass <code>MGtestSuite</code> and use the <code>add</code> method to add test classes. For example,</p>

<pre><code>function indgensuite::init, _extra=e
  compile_opt strictarr

  if (~self-&gt;mgtestsuite::init(_extra=e)) then return, 0

  self-&gt;add, ['indgentest', 'findgentest']

  return, 1
end

pro indgensuite__define
  define = { indgensuite, inherits MGtestSuite }
end
</code></pre>

<p>This test suite is available for download (<a href="http://michaelgalloy.com/demos/tests/indgensuite__define.pro">source</a> / <a href="http://michaelgalloy.com/demos/tests/indgensuite__define.html">docs</a>). <code>MGUNIT</code> can run test suites also,</p>

<pre><code>IDL&gt; mgunit, 'indgensuite'
</code></pre>

<p><code>MGUNIT</code> will also accept a mixed array of test suites and test cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://michaelgalloy.com/2007/01/04/unit-testing-framework.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

