mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
Added a -d command line argument to XSharp.Test application. Using this argument you can check X# source code files located in another directory than the one where the Cosmos User Kit is installed. Launching the program without argument preserves previous behavior.
This commit is contained in:
parent
4c04c31aeb
commit
f72bc30c0b
2 changed files with 101 additions and 13 deletions
|
|
@ -14,12 +14,13 @@ namespace XSharp.Test {
|
||||||
public partial class MainForm : Form {
|
public partial class MainForm : Form {
|
||||||
// D:\source\Cosmos\source2\Tests\XSharpCompilerTester\bin\Debug
|
// D:\source\Cosmos\source2\Tests\XSharpCompilerTester\bin\Debug
|
||||||
// D:\source\Cosmos\source2\Users\Matthijs\MatthijsPlayground
|
// D:\source\Cosmos\source2\Users\Matthijs\MatthijsPlayground
|
||||||
protected string mPath;
|
|
||||||
|
|
||||||
public MainForm() {
|
public MainForm() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal DirectoryInfo RootDirectory { get; set; }
|
||||||
|
|
||||||
protected void Test(string aFilename) {
|
protected void Test(string aFilename) {
|
||||||
tabsMain.TabPages.Add(Path.GetFileNameWithoutExtension(aFilename));
|
tabsMain.TabPages.Add(Path.GetFileNameWithoutExtension(aFilename));
|
||||||
var xTab = tabsMain.TabPages[tabsMain.TabPages.Count - 1];
|
var xTab = tabsMain.TabPages[tabsMain.TabPages.Count - 1];
|
||||||
|
|
@ -52,11 +53,11 @@ namespace XSharp.Test {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MainForm_Load(object sender, EventArgs e) {
|
private void MainForm_Load(object sender, EventArgs e) {
|
||||||
mPath = CosmosPaths.DebugStubSrc;
|
if (null == RootDirectory) { RootDirectory = new DirectoryInfo(CosmosPaths.DebugStubSrc); }
|
||||||
// For testing
|
// For testing
|
||||||
Test(Path.Combine(mPath, "Serial.xs"));
|
// Test(Path.Combine(RootDirectory.FullName, "Serial.xs"));
|
||||||
|
|
||||||
var xFiles = Directory.GetFiles(mPath, "*.xs");
|
var xFiles = Directory.GetFiles(RootDirectory.FullName, "*.xs");
|
||||||
foreach (var xFile in xFiles) {
|
foreach (var xFile in xFiles) {
|
||||||
Test(xFile);
|
Test(xFile);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,102 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace XSharp.Test {
|
namespace XSharp.Test
|
||||||
static class Program {
|
{
|
||||||
[STAThread]
|
public static class Program
|
||||||
static void Main() {
|
{
|
||||||
Application.EnableVisualStyles();
|
private static void DisplayUsage()
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
{
|
||||||
Application.Run(new MainForm());
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.AppendFormat("{0} [-h] [-d <directory path>]\r\n",
|
||||||
|
Assembly.GetExecutingAssembly().GetName().Name);
|
||||||
|
builder.AppendFormat("-h : display this notice.\r\n");
|
||||||
|
builder.AppendFormat("-d : names a directory that will be searched for .xs file.\r\n");
|
||||||
|
MessageBox.Show(builder.ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
[STAThread]
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
|
if (!ParseArgs(args) || _displayUsage)
|
||||||
|
{
|
||||||
|
DisplayUsage();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Application.EnableVisualStyles();
|
||||||
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
|
MainForm form = new MainForm();
|
||||||
|
form.RootDirectory = _rootDirectory;
|
||||||
|
Application.Run(form);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool ParseArgs(string[] args)
|
||||||
|
{
|
||||||
|
bool result = true;
|
||||||
|
|
||||||
|
for (int index = 0; index < args.Length; index++)
|
||||||
|
{
|
||||||
|
string scannedArgument = args[index];
|
||||||
|
// Defensive programming.
|
||||||
|
if (string.IsNullOrEmpty(scannedArgument)) { scannedArgument = " "; }
|
||||||
|
switch (scannedArgument[0])
|
||||||
|
{
|
||||||
|
case '-':
|
||||||
|
case '/':
|
||||||
|
if (1 == scannedArgument.Length) { goto default; }
|
||||||
|
scannedArgument = scannedArgument.Substring(1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
MessageBox.Show(string.Format("Unrecognized command line argument '{0}'.", scannedArgument));
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch (scannedArgument.ToLower())
|
||||||
|
{
|
||||||
|
case "h":
|
||||||
|
_displayUsage = true;
|
||||||
|
break;
|
||||||
|
case "d":
|
||||||
|
if (++index >= args.Length)
|
||||||
|
{
|
||||||
|
MessageBox.Show("The -d command line argument must be followed by a directory name.");
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string directoryPath = args[index] ?? "";
|
||||||
|
try { _rootDirectory = new DirectoryInfo(args[index]); }
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
MessageBox.Show(string.Format("'{0}' is not a valid directory path for -d command line argument.",
|
||||||
|
directoryPath));
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!_rootDirectory.Exists)
|
||||||
|
{
|
||||||
|
MessageBox.Show(string.Format("The target directory '{0} doesn't exist.", _rootDirectory.FullName));
|
||||||
|
result = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Must reinitialize scannedArgument to its original value.
|
||||||
|
scannedArgument = args[index];
|
||||||
|
MessageBox.Show(string.Format("Unrecognized command line argument '{0}'.", scannedArgument));
|
||||||
|
result = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool _displayUsage = false;
|
||||||
|
private static DirectoryInfo _rootDirectory;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue