add: $/Dev10/feature/vs_langs01_s/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/command_line/dash_upper_s_spec.rb
File: dash_upper_s_spec.rb
===================================================================
--- [no source file]
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/command_line/dash_upper_s_spec.rb;dash_upper_s
@@ -1,0 +1,60 @@
+require File.dirname(__FILE__) + '/../spec_helper'
+
+describe "The -S command line option" do
+
+  def push_path(dir)
+    ENV['PATH'] = "#{dir};#{ENV['PATH']}"
+  end
+
+  def pop_path
+    ENV['PATH'] = ENV['PATH'].split(';')[1..-1].join(';')
+  end
+
+  def with_path(*dirs)
+    dirs.each{|dir| push_path dir}
+    yield
+    dirs.size.times{ pop_path }
+  end
+
+  it 'finds the file on the path' do
+    this_dir = File.expand_path(File.dirname(__FILE__))
+    fixture_dir = File.expand_path(this_dir + '/../fixtures')
+    
+    dash_s = nil
+    with_path(fixture_dir) do
+      dash_s = ruby_exe(nil, :options => '-S file.rb')
+    end
+    expected = ruby_exe("#{fixture_dir}/file.rb")
+    failed_dash_s = ruby_exe(nil, :args => "-S #{this_dir}/file.rb 2>&1")
+
+    dash_s.should == expected
+    dash_s.should_not == failed_dash_s
+  end
+
+  it 'does not find the file on the path' do
+    dash_s = ruby_exe(nil, :args => '-S does/not/exist.rb 2>&1')
+    normal = ruby_exe(nil, :args => 'does/not/exist.rb 2>&1')
+    dash_s.should == normal
+  end
+
+  it 'finds the first file on the path' do
+    this_dir = File.expand_path(File.dirname(__FILE__))
+    expected = [
+      File.expand_path(this_dir + '/../fixtures'),
+      File.expand_path(this_dir + '/fixtures')
+    ]
+   
+    output = []
+    with_path(*expected.reverse) do
+      output << ruby_exe(nil, :args => "-S file.rb 2>&1")
+    end
+    with_path(*expected) do
+      output << ruby_exe(nil, :args => "-S file.rb 2>&1")
+    end
+
+    output.size.times do |i|
+      actual = output[i].split("\n")[0]
+      actual.should == File.expand_path(expected[i] + '/file.rb')
+    end
+  end
+end
===================================================================
add: $/Dev10/feature/vs_langs01_s/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/command_line/fixtures/file.rb
File: file.rb
===================================================================
--- [no source file]
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/External.LCA_RESTRICTED/Languages/IronRuby/mspec/rubyspec/command_line/fixtures/file.rb;dash_upper_s
@@ -1,0 +1,1 @@
+puts __FILE__
===================================================================
edit: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Hosting/RubyOptionsParser.cs;C1429753
File: RubyOptionsParser.cs
===================================================================
--- $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Hosting/RubyOptionsParser.cs;C1429753  (server)    1/24/2010 6:32 PM
+++ Shelved Change: $/Dev10/feature/vs_langs01_s/Merlin/Main/Languages/Ruby/Ruby/Hosting/RubyOptionsParser.cs;dash_upper_s
@@ -90,6 +90,8 @@
         protected override void ParseArgument(string arg) {
             ContractUtils.RequiresNotNull(arg, "arg");
 
+            string mainFileFromPath = null;
+
             if (arg.StartsWith("-e", StringComparison.Ordinal)) {
                 string command;
                 if (arg == "-e") {
@@ -108,6 +110,10 @@
                 return;
             }
 
+            if (arg.StartsWith("-S", StringComparison.Ordinal)) {
+                mainFileFromPath = arg == "-S" ? PopNextArg() : arg.Substring(2);
+            }
+
             if (arg.StartsWith("-I", StringComparison.Ordinal)) {
                 string includePaths;
                 if (arg == "-I") {
@@ -165,7 +171,6 @@
                 case "-n":
                 case "-p":
                 case "-s":
-                case "-S":
                     throw new InvalidOptionException(String.Format("Option `{0}' not supported", optionName));
 
                 case "-d":
@@ -263,6 +268,9 @@
                     base.ParseArgument(arg);
 
                     if (ConsoleOptions.FileName != null) {
+                        if (mainFileFromPath != null) {
+                            ConsoleOptions.FileName = FindMainFileFromPath(mainFileFromPath);
+                        }
                         LanguageSetup.Options["MainFile"] = RubyUtils.CanonicalizePath(ConsoleOptions.FileName);
                         LanguageSetup.Options["Arguments"] = PopRemainingArgs();
                         LanguageSetup.Options["ArgumentEncoding"] = 
@@ -276,6 +284,17 @@
             }
         }
 
+        private string FindMainFileFromPath(string mainFileFromPath) {
+            string path = Platform.GetEnvironmentVariable("PATH");
+            foreach (string p in path.Split(';')) {
+                string fullPath = RubyUtils.CombinePaths(p, mainFileFromPath);
+                if (Platform.FileExists(fullPath)) {
+                    return fullPath;
+                }
+            }
+            return mainFileFromPath;
+        }
+
         protected override void AfterParse() {
             var existingSearchPaths =
                 LanguageOptions.GetSearchPathsOption(LanguageSetup.Options) ??
@@ -332,7 +351,7 @@
              // { "-p",                          "assume loop like -n but print line also like sed" },
                 { "-rlibrary",                   "require the library, before executing your script" },
              // { "-s",                          "enable some switch parsing for switches after script name" },
-             // { "-S",                          "look for the script using PATH environment variable" },
+                { "-S",                          "look for the script using PATH environment variable" },
              // { "-T[level]",                   "turn on tainting checks" },
                 { "-v",                          "print version number, then turn on verbose mode" },
                 { "-w",                          "turn warnings on for your script" },
===================================================================
