<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Channel 9 Forums - Tech Off - How to mimic cmd.exe parsing functionality for unit tests.</title>
	<atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Forums/rss"></atom:link>
	<image>
		<url>http://mschnlnine.vo.llnwd.net/d1/Dev/App_Themes/C9/images/feedimage.png</url>
		<title>Channel 9 Forums - Tech Off - How to mimic cmd.exe parsing functionality for unit tests.</title>
		<link>http://channel9.msdn.com/Forums</link>
	</image>
	<description>Channel 9 keeps you up to date with the latest news and behind the scenes info from Microsoft that developers love to keep up with. From LINQ to SilverLight – Watch videos and hear about all the cool technologies coming and the people behind them.</description>
	<link>http://channel9.msdn.com/Forums</link>
	<language>en</language>
	<pubDate>Tue, 21 May 2013 08:38:56 GMT</pubDate>
	<lastBuildDate>Tue, 21 May 2013 08:38:56 GMT</lastBuildDate>
	<generator>Rev9</generator>
	<c9:totalResults>3</c9:totalResults>
	<c9:pageCount>-3</c9:pageCount>
	<c9:pageSize>-1</c9:pageSize>
	<item>
		<title>Tech Off - How to mimic cmd.exe parsing functionality for unit tests.</title>
		<description><![CDATA[<p>I'm using Ookii.CommandLine (yay!) as well as some internal command line processing of the values after they've passed through Ookii.CommandLine.</p><p>I want to add some unit tests that will allow us to show that we correctly respond to invalid data on the command line, but I am hoping to do this by building the array of args from a single string, NOT by manually populating the args themselves.&nbsp; i.e. I want to create a bunch of unit tests to do this:</p><p>string[] args = &quot;-Arg1 argvalue1 -Arg2 argvalue2&quot;.Split();</p><p>CommandLineParser.Parse(args);</p><p>not this:</p><p>string[] args = {&quot;-Arg1&quot;, &quot;argvalue1&quot;, &quot;-Arg2&quot;, &quot;argvalue2&quot;};</p><p>CommandLineParser.Parse(args);</p><p>&nbsp;</p><p>I want to do this because there is some crafty processing that is handled by cmd.exe when the app is run and I'd like to know that if the user intermixes quotes or other special characters in the argument list, we handle it correctly (or fail gracefully).&nbsp; Further, this will satisfy a security requirement that we attempted to address being 'hacked' by a malicious user into behaving badly through crazy command line arguments.</p><p>Does anyone know how to mimic the same processing done by cmd.exe so that I can get the arguments returned in args?</p><p>&nbsp;</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/How-to-mimic-cmdexe-parsing-functionality-for-unit-tests/68559711383f4552a450a1040102f3d1#68559711383f4552a450a1040102f3d1</link>
		<pubDate>Fri, 09 Nov 2012 15:42:49 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/How-to-mimic-cmdexe-parsing-functionality-for-unit-tests/68559711383f4552a450a1040102f3d1#68559711383f4552a450a1040102f3d1</guid>
		<dc:creator>ScanIAm</dc:creator>
		<slash:comments>3</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ScanIAm/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - How to mimic cmd.exe parsing functionality for unit tests.</title>
		<description><![CDATA[<p>Command line processing is a bit more complex than this. Yes, CMD.EXE does some crafty processing that splits the command line into a string array. Unfortunately, so does PowerShell, but it does things differently. Their similar, but not the same. I think you have 3 options here.</p><ol><li>Use a command line parser that parses the full command line and not just the args the shell gives you. This ensures the syntax is the same regardless of the shell, which is both a good and a bad thing. </li><li>Right unit tests that test the syntax of both shells, and hope we never get a mainstream third (or more) shell. This seems like the most difficult and brittle option. </li><li>Write unit tests that test the args, not the command line. You can create your own helper method to make it easier to write. Simplest would be a function that takes a params string array and returns the array, but that just saves you a few keystrokes. More robust would be to just write a Parse method that parses the string, similar to what you're asking for, but that doesn't care what syntax is used. Pick a simple syntax to parse and ignore what the various shells do. Heck, in most cases a simple Split on the space character would be good enough. More robust, just borrow a CSV parser which would allow you to represent everything in a single string with little effort. </li></ol><p>I'd probably go for a CSV parser. Forget about worrying about the shell syntax, it's not really relevant if your command line parser is parsing an args array.</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/How-to-mimic-cmdexe-parsing-functionality-for-unit-tests/e042f0e5056146a5a6ada10401284dfe#e042f0e5056146a5a6ada10401284dfe</link>
		<pubDate>Fri, 09 Nov 2012 17:58:48 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/How-to-mimic-cmdexe-parsing-functionality-for-unit-tests/e042f0e5056146a5a6ada10401284dfe#e042f0e5056146a5a6ada10401284dfe</guid>
		<dc:creator>William Kempf</dc:creator>
		<slash:comments>3</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/wkempf/Discussions/RSS</wfw:commentRss>
	</item>
	<item>
		<title>Tech Off - How to mimic cmd.exe parsing functionality for unit tests.</title>
		<description><![CDATA[<p>@<a href="/Forums/TechOff/How-to-mimic-cmdexe-parsing-functionality-for-unit-tests#ce042f0e5056146a5a6ada10401284dfe">wkempf</a>:I was hoping not to have to roll my own, but you're probably right.</p><p>Thanks for the ideas!</p>]]></description>
		<link>http://channel9.msdn.com/Forums/TechOff/How-to-mimic-cmdexe-parsing-functionality-for-unit-tests/885ccf9a6c2a47a8a544a10401327715#885ccf9a6c2a47a8a544a10401327715</link>
		<pubDate>Fri, 09 Nov 2012 18:35:48 GMT</pubDate>
		<guid isPermaLink="false">http://channel9.msdn.com/Forums/TechOff/How-to-mimic-cmdexe-parsing-functionality-for-unit-tests/885ccf9a6c2a47a8a544a10401327715#885ccf9a6c2a47a8a544a10401327715</guid>
		<dc:creator>ScanIAm</dc:creator>
		<slash:comments>3</slash:comments>
		<wfw:commentRss>http://channel9.msdn.com/Niners/ScanIAm/Discussions/RSS</wfw:commentRss>
	</item>
</channel>
</rss>