<?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>Virtual Clouds &#187; methodology</title>
	<atom:link href="http://www.virtual-clouds.com/category/methodology/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.virtual-clouds.com</link>
	<description>Erlang and Other Animals</description>
	<lastBuildDate>Mon, 19 Jul 2010 17:42:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>perl one liners = magic</title>
		<link>http://www.virtual-clouds.com/2009/10/81/magic-perl-one-liners/</link>
		<comments>http://www.virtual-clouds.com/2009/10/81/magic-perl-one-liners/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 22:41:24 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[methodology]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[perl]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=81</guid>
		<description><![CDATA[a word about the power of unix shell commands: perl one liners, i.e. one line of perl that can save you hours of error-prone hand changes. when i want to do some massive changes in my code this is what i use. say you need replcae a record name from abc_record to xyz_record, first if <a href='http://www.virtual-clouds.com/2009/10/81/magic-perl-one-liners/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.virtual-clouds.com/wp-content/uploads/2009/10/perl-150x150.jpg" alt="perl" title="perl" width="150" height="150" class="alignleft size-thumbnail wp-image-89" />a word about the power of unix shell commands: perl one liners, i.e. one line of <a href="http://www.perl.org/">perl</a> that can save you hours of error-prone hand changes. when i want to do some massive changes in my code this is what i use.</p>
<p>say you need replcae a record name from abc_record to xyz_record, first if you use perl recursivlly it will touch all files and revision control will makr them for commit. you don&#8217;t want that. so use grep to filter the relevant files:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;#abc_record\b&quot;</span> . <span style="color: #660033;">-rl</span></pre></div></div>

<p>next, do the replace:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-pe</span> s<span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">&quot;#abc_record\b&quot;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">&quot;xyz_record&quot;</span><span style="color: #000000; font-weight: bold;">/</span>g <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;#abc_record\b&quot;</span> src -rl<span style="color: #000000; font-weight: bold;">`</span></pre></div></div>

<p>note the use of \b to mark a word boundary.</p>
<p>a more complex replace is if you need to change the code from using a record to use a wrapper function. so for exmaple we have the record:</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #014ea4;">-</span><span style="color: #5400b3;">record</span><span style="color: #109ab8;">&#40;</span><span style="color: #d400ed;">abc_record</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span>fld<span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>and we want to start use a wrapper module:</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #014ea4;">-</span><span style="color: #5400b3;">module</span><span style="color: #109ab8;">&#40;</span>rtools<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
<span style="color: #014ea4;">-</span><span style="color: #5400b3;">export</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span>fld<span style="color: #014ea4;">/</span><span style="color: #ff9600;">1</span><span style="color: #109ab8;">&#93;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">fld</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">R</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">R</span><span style="color: #ff9600;">#</span><span style="color: #d400ed;">abc_record</span><span style="color: #6bb810;">.</span>fld<span style="color: #6bb810;">.</span></pre></div></div>

<p>so we can do it instantly like that:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-pe</span> s<span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">&quot;\b(\w+)#abc_record\.fld&quot;</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #ff0000;">&quot;rtools:fld(\1)&quot;</span><span style="color: #000000; font-weight: bold;">/</span>g <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">&quot;#abc_record\.fld&quot;</span> src -rl<span style="color: #000000; font-weight: bold;">`</span></pre></div></div>

<p>here we have switched from using A#abc_record.fld to record_tools:fld(A)</p>
<p>another trick is to remove complete lines (!), so for exmaple you can get rid of all the -compile(export_all) you have fullishly inserted into your code:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">perl</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-nle</span> <span style="color: #ff0000;">'print if !/-compile\(export_all\)/'</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">grep</span> export_all src -rl<span style="color: #000000; font-weight: bold;">`</span></pre></div></div>

<p>one safty tip, omit the -i first to try before you actuall change files.</p>
<p>this was just a learn-by-example, more info can be found at:<br />
<a href="http://sial.org/howto/perl/one-liner">http://sial.org/howto/perl/one-liner</a><br />
<a href="http://www.unixguide.net/unix/perl_oneliners.shtml">http://www.unixguide.net/unix/perl_oneliners.shtml</a>	</p>
]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2009/10/81/magic-perl-one-liners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>code coverage in erlang</title>
		<link>http://www.virtual-clouds.com/2008/10/24/code-coverage-in-erlang/</link>
		<comments>http://www.virtual-clouds.com/2008/10/24/code-coverage-in-erlang/#comments</comments>
		<pubDate>Thu, 23 Oct 2008 22:15:17 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[methodology]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=24</guid>
		<description><![CDATA[yesterday i found about code coverage under erlang on this nice blog. i wanted to integrate it with my unit testing, so i would be able to see what code of mine is not tested. this can be used to add new tests to cover it, or even remove of unnecessary code. it took me <a href='http://www.virtual-clouds.com/2008/10/24/code-coverage-in-erlang/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>yesterday i found about code coverage under erlang on this nice <a href="http://curious-attempt-bunny.blogspot.com/2007/10/code-coverage-analysis-in-erlang.html">blog</a>. i wanted to integrate it with my unit testing, so i would be able to see what code of mine is not tested. this can be used to add new tests to cover it, or even remove of unnecessary code.</p>
<p>it took me some time to play with it and come up with a good method of doing that. eventually i have replaced the unit testing makefile line with:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">check<span style="color: #004400;">:</span>
	<span style="color: #004400;">@</span>for f in <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> do \
	echo <span style="color: #000088; font-weight: bold;">$$</span>f<span style="color: #004400;">;</span> \
	erl <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">FLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>noshell <span style="color: #004400;">-</span>eval <span style="color: #CC2200;">&quot;
	cover:compile($$f, [{i,<span style="color: #000099; font-weight: bold;">\&quot;</span>$(INCLUDE)<span style="color: #000099; font-weight: bold;">\&quot;</span>}]),<span style="color: #000099; font-weight: bold;">\</span>
	$$f:test(),
	cover:analyse_to_file($$f, <span style="color: #000099; font-weight: bold;">\&quot;</span>$(DOC)/$${f}_coverage.html<span style="color: #000099; font-weight: bold;">\&quot;</span>, [html]).&quot;</span>\
	<span style="color: #004400;">-</span>s init stop<span style="color: #004400;">;</span> \</pre></div></div>

<p>This actually do 3 things in a raw:</p>
<ol>
<li>compile each module using cover:compile.</li>
<li>run the test, using the eunit test() function.</li>
<li>dump analysis into html files on doc directory</li>
</ol>
<p>enjoy!</p>
<p>edit: i found out, that you compile the whole directory for covearge, so the result you get is thecombined  coverage for all the specified modules and tests.</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">OBJECTS <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">patsubst</span> <span style="color: #004400;">%.</span>erl<span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">BIN</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">/%.$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">EMULATOR</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*.</span>erl<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
MODULES <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">patsubst</span> <span style="color: #004400;">%.</span>erl<span style="color: #004400;">,%,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*.</span>erl<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
SKIP_FILES <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">patsubst</span> <span style="color: #004400;">%.</span>erl<span style="color: #004400;">,%,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*</span>_tests<span style="color: #004400;">.</span>erl<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
MODULES <span style="color: #004400;">:=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">filter-out</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">SKIP_FILES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
MODULES <span style="color: #004400;">:=</span> <span style="color: #004400;">&#91;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">subst</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">space</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">comma</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">,$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">&#93;</span>
&nbsp;
check<span style="color: #004400;">:</span>
	<span style="color: #004400;">@</span>echo Testing units<span style="color: #004400;">...</span>
	<span style="color: #004400;">@$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">TIME</span><span style="color: #004400;">&#41;</span> erl <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ERL_LIB_FLAGS</span><span style="color: #004400;">&#41;</span> \
	<span style="color: #004400;">-</span>mnesia dir <span style="color: #CC2200;">'&quot;$(DATA_DIR)&quot;'</span> <span style="color: #004400;">-</span>mnesia debug <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MNESIA</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>noshell \
	<span style="color: #004400;">-</span>eval <span style="color: #CC2200;">&quot;<span style="color: #000099; font-weight: bold;">\</span>
	cover:compile_directory(<span style="color: #000099; font-weight: bold;">\&quot;</span>.<span style="color: #000099; font-weight: bold;">\&quot;</span>, [{i,<span style="color: #000099; font-weight: bold;">\&quot;</span>$(INCLUDE)<span style="color: #000099; font-weight: bold;">\&quot;</span>},{d,'NODEBUG'}]), <span style="color: #000099; font-weight: bold;">\</span>
	T = fun(X) -&gt; io:format(user, <span style="color: #000099; font-weight: bold;">\&quot;</span>~-20.s<span style="color: #000099; font-weight: bold;">\&quot;</span>, [X]), X:test() end, <span style="color: #000099; font-weight: bold;">\</span>
	[T(X) || X &amp;lt;- &quot;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #CC2200;">&quot;], <span style="color: #000099; font-weight: bold;">\</span>
	F = fun(X) -&gt; cover:analyse_to_file(X, <span style="color: #000099; font-weight: bold;">\&quot;</span>$(LOG)/<span style="color: #000099; font-weight: bold;">\&quot;</span> ++ <span style="color: #000099; font-weight: bold;">\</span>
	    atom_to_list(X) ++ <span style="color: #000099; font-weight: bold;">\&quot;</span>_coverage.html<span style="color: #000099; font-weight: bold;">\&quot;</span>, [html]) end, <span style="color: #000099; font-weight: bold;">\</span>
	[F(X) || X &amp;lt;- &quot;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #CC2200;">&quot;]. <span style="color: #000099; font-weight: bold;">\</span>
	&quot;</span> <span style="color: #004400;">-</span>s init stop<span style="color: #004400;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2008/10/24/code-coverage-in-erlang/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>more on eunit</title>
		<link>http://www.virtual-clouds.com/2008/10/6/more-on-eunit/</link>
		<comments>http://www.virtual-clouds.com/2008/10/6/more-on-eunit/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 21:32:10 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[methodology]]></category>
		<category><![CDATA[erlang]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=6</guid>
		<description><![CDATA[the use of eunit is very easy and intuitive. in principle every function which ends with _test of arity 0 (i.e. no input arguments) will be automaticly exported by eunit. eunit will also create a function called test() which will call all tests functions which have been defined. this mechanism leaves the programmer with only <a href='http://www.virtual-clouds.com/2008/10/6/more-on-eunit/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p>the use of eunit is very easy and intuitive. in principle every function which ends with _test of arity 0 (i.e. no input arguments) will be automaticly exported by eunit. eunit will also create a function called test() which will call all tests functions which have been defined. this mechanism leaves the programmer with only the actual test writing, and saves him/her the tedious wrappers and procedures. writing a test on a new module become something which take few seconds.</p>
<p>for example, the next function has its own testing function:</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #ff3c00;">flip_sides</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">Side</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #186895;">case</span> <span style="color: #45b3e6;">Side</span> <span style="color: #186895;">of</span>
		x <span style="color: #6bb810;">-&gt;</span> <span style="color: #006600;">o</span><span style="color: #6bb810;">;</span>
		o <span style="color: #6bb810;">-&gt;</span> <span style="color: #006600;">x</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #ff3c00;">flip_sides_test</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	?<span style="color: #ff3c00;">assert</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">flip_sides</span><span style="color: #109ab8;">&#40;</span>x<span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">==</span> o<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	?<span style="color: #ff3c00;">assert</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">flip_sides</span><span style="color: #109ab8;">&#40;</span>o<span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">==</span> x<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>the testing function is invoked automatically by calling the test function of this module, e.g. mymodule:test(). the test function is supplied by the eunit framework, which takes every function that ends with _test() and add it to the testing list of that module.</p>
<p>a more advanced testing method is needed for testing the always loops that keep the state on the erlang module. few problems need to be solved in order to properly test those kind of loops:</p>
<ul>
<li> initial state loading.</li>
<li> external function calls.</li>
<li> check of the new state, after each event.</li>
<p></lu></p>
<p>the first problem can be solved by adding a new start function for debug use, which takes all the state variables of the always loop as parameters. this allows you to start the always loop in any state you want.</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">% original start of arity/0</span>
<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% new function for debug of arity/2</span>
<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>  <span style="color: #ff3c00;">register</span><span style="color: #109ab8;">&#40;</span>?<span style="color: #6941fd;">MODULE</span><span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">spawn</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">end</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% the state loop</span>
<span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #186895;">receive</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> stop<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">From</span> <span style="color: #014ea4;">!</span> stopped<span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> reset<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span>add<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">N</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span>module2:<span style="color: #ff3c00;">add</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">N</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span> continue<span style="color: #109ab8;">&#41;</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>the next problem is the call for external function, shown here as call for module2:add/2, i solved this by adding another parameter to the loop&#8217;s state in order to keep a reference to the called function. i have also added it to the start function.</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">% original start of arity/0</span>
<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #6bb810;">,</span> <span style="color: #186895;">fun</span> module2:<span style="color: #006600;">add</span><span style="color: #014ea4;">/</span><span style="color: #ff9600;">2</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% new function for debug of arity/2</span>
<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #ff3c00;">register</span><span style="color: #109ab8;">&#40;</span>?<span style="color: #6941fd;">MODULE</span><span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">spawn</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">fun</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span> <span style="color: #186895;">end</span><span style="color: #109ab8;">&#41;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span>
&nbsp;
<span style="color: #666666; font-style: italic;">% the state loop</span>
<span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #186895;">receive</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> stop<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">From</span> <span style="color: #014ea4;">!</span> stopped<span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> reset<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span>add<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">N</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">F</span><span style="color: #ff3c00;">unc</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">N</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span> continue<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>adding a reference to the external function allows me to switch to a mocking function as desired. for the new state checking i have added a dump command to the always loop which return me the current state, so i can test it on my testing functions.</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">% the state loop</span>
<span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Status</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #186895;">receive</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> stop<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">From</span> <span style="color: #014ea4;">!</span> stopped<span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> reset<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #45b3e6;">From</span> <span style="color: #014ea4;">!</span> reset<span style="color: #6bb810;">,</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> <span style="color: #109ab8;">&#123;</span>add<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">N</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #ff3c00;">always</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">F</span><span style="color: #ff3c00;">unc</span><span style="color: #109ab8;">&#40;</span><span style="color: #45b3e6;">N</span><span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">State</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span> continue<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">;</span>
		<span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">From</span><span style="color: #6bb810;">,</span> dump<span style="color: #109ab8;">&#125;</span> <span style="color: #6bb810;">-&gt;</span> <span style="color: #109ab8;">&#123;</span><span style="color: #45b3e6;">State</span><span style="color: #6bb810;">,</span> dump<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Func</span><span style="color: #109ab8;">&#125;</span>
	<span style="color: #186895;">end</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>last i&#8217;ll show the test function:</p>

<div class="wp_syntax"><div class="code"><pre class="erlang" style="font-family:monospace;"><span style="color: #ff3c00;">always_reset_test</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span> <span style="color: #6bb810;">-&gt;</span>
	<span style="color: #45b3e6;">Fun</span> <span style="color: #014ea4;">=</span> <span style="color: #186895;">fun</span> callback_check_reset_mockup<span style="color: #014ea4;">/</span><span style="color: #ff9600;">2</span><span style="color: #6bb810;">,</span>
	<span style="color: #ff3c00;">start</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#91;</span>x<span style="color: #6bb810;">,</span> o<span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> continue<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Fun</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	<span style="color: #ff3c00;">rpc</span><span style="color: #109ab8;">&#40;</span>reset<span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	?<span style="color: #ff3c00;">assert</span><span style="color: #109ab8;">&#40;</span><span style="color: #ff3c00;">rpc</span><span style="color: #109ab8;">&#40;</span>dump<span style="color: #109ab8;">&#41;</span> <span style="color: #014ea4;">==</span> <span style="color: #109ab8;">&#123;</span><span style="color: #109ab8;">&#91;</span><span style="color: #109ab8;">&#93;</span><span style="color: #6bb810;">,</span> start<span style="color: #6bb810;">,</span> <span style="color: #45b3e6;">Fun</span><span style="color: #109ab8;">&#125;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">,</span>
	<span style="color: #ff3c00;">stop</span><span style="color: #109ab8;">&#40;</span><span style="color: #109ab8;">&#41;</span><span style="color: #6bb810;">.</span></pre></div></div>

<p>callback_check_reset_mockup(N, State) ->  void. % you can check match if applicable
</pre>
<p>that's it!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2008/10/6/more-on-eunit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lots of &#8216;e&#8217;s&#8230;</title>
		<link>http://www.virtual-clouds.com/2008/10/3/lots-of-es/</link>
		<comments>http://www.virtual-clouds.com/2008/10/3/lots-of-es/#comments</comments>
		<pubDate>Tue, 21 Oct 2008 21:22:00 +0000</pubDate>
		<dc:creator>ofer affias</dc:creator>
				<category><![CDATA[methodology]]></category>
		<category><![CDATA[erlang]]></category>

		<guid isPermaLink="false">http://www.virtual-clouds.com/?p=3</guid>
		<description><![CDATA[i have started off a new project, mostly based on erlang, and i have decided to post few of my observations and experiences which i pick along the way. i will start with edoc and eunit, both i have added to my project with zero effort, and got remarkable results. edoc produces automatic documentation for <a href='http://www.virtual-clouds.com/2008/10/3/lots-of-es/'>[...]</a>]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.virtual-clouds.com/wp-content/uploads/2008/10/erlang.gif" alt="erlang" title="erlang" width="114" height="96" class="alignleft size-full wp-image-108" />i have started off a new project, mostly based on <a href="http://www.erlang.org/">erlang</a>, and i have decided to post few of my observations and experiences which i pick along the way. i will start with <a href="http://www.erlang.org/doc/apps/edoc/index.html">edoc </a>and <a href="http://svn.process-one.net/contribs/trunk/eunit/doc/overview-summary.html">eunit</a>, both i have added to my project with zero effort, and got remarkable results.</p>
<p>edoc produces automatic documentation for the project. i have just added the right code to my project makefile, and voula &#8211; instance documentation for my functions api. the code itself is:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">docs<span style="color: #004400;">:</span>
erl <span style="color: #004400;">-</span>noshell <span style="color: #004400;">-</span>eval <span style="color: #CC2200;">&quot;edoc:application($(APPNAME), <span style="color: #000099; font-weight: bold;">\&quot;</span>.<span style="color: #000099; font-weight: bold;">\&quot;</span>, [$(DOC_OPTS)])&quot;</span> <span style="color: #004400;">-</span>s init stop</pre></div></div>

<p>where:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">APPNAME <span style="color: #004400;">=</span> myappVSN <span style="color: #004400;">=</span> <span style="color: #CC2200;">0.1</span>
DOC_OPTS <span style="color: #004400;">=</span> <span style="color: #004400;">&#123;</span>def<span style="color: #004400;">,</span> <span style="color: #004400;">&#123;</span>version<span style="color: #004400;">,</span> <span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">VSN</span><span style="color: #004400;">&#41;</span><span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #004400;">&#125;</span><span style="color: #004400;">&#125;</span><span style="color: #004400;">,</span> no_packages</pre></div></div>

<p>eunit gives an easy way to add unit testing to the project, again, i have added few lines to my makefile:</p>

<div class="wp_syntax"><div class="code"><pre class="make" style="font-family:monospace;">MODULES <span style="color: #004400;">=</span> <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">patsubst</span> <span style="color: #004400;">%.</span>erl<span style="color: #004400;">,%,$</span><span style="color: #004400;">&#40;</span><span style="color: #0000CC; font-weight: bold;">wildcard</span> <span style="color: #004400;">*.</span>erl<span style="color: #004400;">&#41;</span><span style="color: #004400;">&#41;</span>
check<span style="color: #004400;">:</span>
<span style="color: #004400;">@</span>for f in <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">MODULES</span><span style="color: #004400;">&#41;</span><span style="color: #004400;">;</span> do \
echo <span style="color: #000088; font-weight: bold;">$$</span>f<span style="color: #004400;">;</span> \
erl <span style="color: #004400;">$</span><span style="color: #004400;">&#40;</span><span style="color: #000088;">ERL_LIB_FLAGS</span><span style="color: #004400;">&#41;</span> <span style="color: #004400;">-</span>noshell <span style="color: #004400;">-</span>s <span style="color: #000088; font-weight: bold;">$$</span>f test <span style="color: #004400;">-</span>s init stop<span style="color: #004400;">;</span> \
done</pre></div></div>

<p>those few lines takes all the erl files on the current directory and run the test function for each module.</p>
<p>that&#8217;s it for the first time.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.virtual-clouds.com/2008/10/3/lots-of-es/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
