Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6ec26e8
Showing
105 changed files
with
10,665 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
_ReSharper.IREmbeddedApp/* | |||
ExampleApps/obj/ | |||
IREmbeddedApp/bin/ | |||
IREmbeddedApp/obj/ | |||
IRTestResources/bin/ | |||
IRTestResources/obj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,3 @@ | |||
10.times { |i| | |||
puts "#{i} green bottles" | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,6 @@ | |||
puts "$0 is #{$0}" | |||
puts "__FILE__ is #{__FILE__}" | |||
puts "There are #{ARGV.length} command-line arguments" | |||
ARGV.each_with_index do |arg, index| | |||
puts "#{index}: #{arg}" | |||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,19 @@ | |||
require 'test/unit' | |||
require 'flexmock/test_unit' | |||
|
|||
# ================================================ | |||
class TestDog < Test::Unit::TestCase | |||
|
|||
def test_dog_wags | |||
tail_mock = flexmock(:wag => :happy) | |||
assert_equal :happy, tail_mock.wag | |||
end | |||
|
|||
def test_dog_wags_not | |||
tail_mock = flexmock(:wag => :sad) | |||
assert_equal :happy, tail_mock.wag | |||
end | |||
|
|||
end | |||
|
|||
# TODO: test failures fail on reporting. location?? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
require 'test/unit' | |||
|
|||
# ================================================ | |||
class TestDemo < Test::Unit::TestCase | |||
|
|||
def test_should_pass | |||
sum = 2 + 2 | |||
assert_equal 4, sum | |||
end | |||
|
|||
def test_should_fail | |||
sum = 2 + 2 | |||
assert_equal 5, sum | |||
end | |||
|
|||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,75 @@ | |||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |||
<PropertyGroup> | |||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | |||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | |||
<ProductVersion>8.0.50727</ProductVersion> | |||
<SchemaVersion>2.0</SchemaVersion> | |||
<ProjectGuid>{F81E1902-C72C-4457-A526-A49AE80FEA1F}</ProjectGuid> | |||
<OutputType>Exe</OutputType> | |||
<AppDesignerFolder>Properties</AppDesignerFolder> | |||
<RootNamespace>ExampleApps</RootNamespace> | |||
<AssemblyName>ExampleApps</AssemblyName> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | |||
<DebugSymbols>true</DebugSymbols> | |||
<DebugType>full</DebugType> | |||
<Optimize>false</Optimize> | |||
<OutputPath>bin\</OutputPath> | |||
<DefineConstants>DEBUG;TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
</PropertyGroup> | |||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | |||
<DebugType>pdbonly</DebugType> | |||
<Optimize>true</Optimize> | |||
<OutputPath>bin\</OutputPath> | |||
<DefineConstants>TRACE</DefineConstants> | |||
<ErrorReport>prompt</ErrorReport> | |||
<WarningLevel>4</WarningLevel> | |||
</PropertyGroup> | |||
<ItemGroup> | |||
<Reference Include="IREmbeddedApp, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL"> | |||
<SpecificVersion>False</SpecificVersion> | |||
<HintPath>..\IREmbeddedApp\bin\IREmbeddedApp.dll</HintPath> | |||
</Reference> | |||
<Reference Include="IronRuby.Libraries, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | |||
<SpecificVersion>False</SpecificVersion> | |||
<HintPath>C:\Program Files\IronRuby 1.0.0.0\bin\IronRuby.Libraries.dll</HintPath> | |||
</Reference> | |||
<Reference Include="IRTestResources, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL"> | |||
<SpecificVersion>False</SpecificVersion> | |||
<HintPath>..\IRTestResources\bin\IRTestResources.dll</HintPath> | |||
</Reference> | |||
<Reference Include="Serfs, Version=0.1.0.0, Culture=neutral, processorArchitecture=MSIL"> | |||
<SpecificVersion>False</SpecificVersion> | |||
<HintPath>..\IREmbeddedApp\Serfs.dll</HintPath> | |||
</Reference> | |||
<Reference Include="System" /> | |||
<Reference Include="System.Data" /> | |||
<Reference Include="System.Xml" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<Compile Include="Program.cs" /> | |||
<Compile Include="Properties\AssemblyInfo.cs" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<EmbeddedResource Include="Applications\test_unit_app.rb" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<EmbeddedResource Include="Applications\test_mocking_app.rb" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<EmbeddedResource Include="Applications\bottles.rb" /> | |||
</ItemGroup> | |||
<ItemGroup> | |||
<EmbeddedResource Include="Applications\list_args.rb" /> | |||
</ItemGroup> | |||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | |||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | |||
Other similar extension points exist, see Microsoft.Common.targets. | |||
<Target Name="BeforeBuild"> | |||
</Target> | |||
<Target Name="AfterBuild"> | |||
</Target> | |||
--> | |||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,65 @@ | |||
using System; | |||
using IREmbeddedApp; | |||
|
|||
namespace IronRubyConsole { | |||
|
|||
class Program { | |||
|
|||
static int Main(string[] args) { | |||
int exitcode = 0; | |||
|
|||
// First application : bottles | |||
Console.WriteLine("bottles.rb"); | |||
Console.WriteLine("----------"); | |||
try { | |||
EmbeddedRuby er1 = new EmbeddedRuby(); | |||
er1.Mount("Applications"); | |||
exitcode = er1.Run("bottles.rb"); | |||
} catch (Exception e) { | |||
Console.WriteLine(e.Message); | |||
} | |||
Console.WriteLine(); | |||
|
|||
// list_args.rb | |||
Console.WriteLine("bottles.rb"); | |||
Console.WriteLine("----------"); | |||
try { | |||
EmbeddedRuby er1 = new EmbeddedRuby(); | |||
er1.Mount("Applications"); | |||
exitcode = er1.Run("list_args.rb", args); | |||
} catch (Exception e) { | |||
Console.WriteLine(e.Message); | |||
} | |||
Console.WriteLine(); | |||
|
|||
// Demo of test::unit | |||
Console.WriteLine("test_unit_app.rb"); | |||
Console.WriteLine("----------------"); | |||
try { | |||
EmbeddedRuby er2 = new EmbeddedRuby(); | |||
er2.AddAssembly("IRTestResources", "Files/Core").Mount("Files/TestUnit"); | |||
er2.Mount("Applications"); | |||
exitcode = er2.Run("test_unit_app.rb"); | |||
} catch (Exception e) { | |||
Console.WriteLine(e.Message); | |||
} | |||
Console.WriteLine(); | |||
|
|||
// Demo of test::unit and flexmock | |||
Console.WriteLine("test_mocking_app.rb"); | |||
Console.WriteLine("-------------------"); | |||
try { | |||
EmbeddedRuby er3 = new EmbeddedRuby(); | |||
er3.AddAssembly("IRTestResources", "Files/Core").Mount("Files/FlexMock").Mount("Files/TestUnit"); | |||
er3.Mount("Applications"); | |||
exitcode = er3.Run("test_mocking_app.rb"); | |||
} catch (Exception e) { | |||
Console.WriteLine(e.Message); | |||
} | |||
Console.WriteLine(); | |||
|
|||
return exitcode; | |||
} | |||
} | |||
} | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,34 @@ | |||
using System.Reflection; | |||
using System.Runtime.InteropServices; | |||
|
|||
// General Information about an assembly is controlled through the following | |||
// set of attributes. Change these attribute values to modify the information | |||
// associated with an assembly. | |||
[assembly: AssemblyTitle("ExampleApps")] | |||
[assembly: AssemblyDescription("Executable demonstrating running Ruby programs embedded into the exe.")] | |||
[assembly: AssemblyConfiguration("")] | |||
[assembly: AssemblyCompany("djlSoft")] | |||
[assembly: AssemblyProduct("ExampleApps")] | |||
[assembly: AssemblyCopyright("Copyright David Lake © 2010")] | |||
[assembly: AssemblyTrademark("")] | |||
[assembly: AssemblyCulture("")] | |||
|
|||
// Setting ComVisible to false makes the types in this assembly not visible | |||
// to COM components. If you need to access a type in this assembly from | |||
// COM, set the ComVisible attribute to true on that type. | |||
[assembly: ComVisible(false)] | |||
|
|||
// The following GUID is for the ID of the typelib if this project is exposed to COM | |||
[assembly: Guid("40e052ee-a6b3-441c-93b2-1768a97fb5a7")] | |||
|
|||
// Version information for an assembly consists of the following four values: | |||
// | |||
// Major Version | |||
// Minor Version | |||
// Build Number | |||
// Revision | |||
// | |||
// You can specify all the values or you can default the Revision and Build Numbers | |||
// by using the '*' as shown below: | |||
[assembly: AssemblyVersion("0.1.0.0")] | |||
[assembly: AssemblyFileVersion("0.1.0.0")] |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,36 @@ | |||
|
|||
Microsoft Visual Studio Solution File, Format Version 9.00 | |||
# Visual Studio 2005 | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IREmbeddedApp", "IREmbeddedApp\IREmbeddedApp.csproj", "{252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IRTestResources", "IRTestResources\IRTestResources.csproj", "{9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}" | |||
EndProject | |||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleApps", "ExampleApps\ExampleApps.csproj", "{F81E1902-C72C-4457-A526-A49AE80FEA1F}" | |||
ProjectSection(ProjectDependencies) = postProject | |||
{9FE6381A-B2E1-4B08-A9CC-F62CD14B719C} = {9FE6381A-B2E1-4B08-A9CC-F62CD14B719C} | |||
{252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E} = {252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E} | |||
EndProjectSection | |||
EndProject | |||
Global | |||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | |||
Debug|Any CPU = Debug|Any CPU | |||
Release|Any CPU = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | |||
{252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{252B7E48-4D69-4AAF-AB8F-BCA432D0BF2E}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{9FE6381A-B2E1-4B08-A9CC-F62CD14B719C}.Release|Any CPU.Build.0 = Release|Any CPU | |||
{F81E1902-C72C-4457-A526-A49AE80FEA1F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | |||
{F81E1902-C72C-4457-A526-A49AE80FEA1F}.Debug|Any CPU.Build.0 = Debug|Any CPU | |||
{F81E1902-C72C-4457-A526-A49AE80FEA1F}.Release|Any CPU.ActiveCfg = Release|Any CPU | |||
{F81E1902-C72C-4457-A526-A49AE80FEA1F}.Release|Any CPU.Build.0 = Release|Any CPU | |||
EndGlobalSection | |||
GlobalSection(SolutionProperties) = preSolution | |||
HideSolutionNode = FALSE | |||
EndGlobalSection | |||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,63 @@ | |||
using System; | |||
using System.Collections.Generic; | |||
using System.Reflection; | |||
using IronRuby; | |||
using IronRuby.Runtime; | |||
using Microsoft.Scripting; | |||
using Microsoft.Scripting.Hosting; | |||
using Microsoft.Scripting.Hosting.Providers; | |||
using SERFS; | |||
|
|||
namespace IREmbeddedApp { | |||
public class EmbeddedRuby { | |||
private readonly Serfs _serfs; | |||
|
|||
public EmbeddedRuby() { | |||
_serfs = new Serfs("EmbeddedRuby"); | |||
} | |||
|
|||
public AssemblyInfo Mount(string topFolder) { | |||
return _serfs.AddAssembly(Assembly.GetCallingAssembly().FullName,topFolder); | |||
} | |||
|
|||
public AssemblyInfo AddAssembly(string name) { | |||
return _serfs.AddAssembly(name); | |||
} | |||
|
|||
public AssemblyInfo AddAssembly(string name, string folder) { | |||
return _serfs.AddAssembly(name, folder); | |||
} | |||
|
|||
public int Run(string app) { | |||
return Run(app, null); | |||
} | |||
|
|||
public int Run(string app, string[] args) { | |||
ScriptRuntime runtime = Ruby.CreateRuntime(); | |||
ScriptEngine engine = runtime.GetEngine("rb"); | |||
RubyContext context = (RubyContext)HostingHelpers.GetLanguageContext(engine); | |||
context.ObjectClass.SetConstant("SerfsInstance", _serfs); | |||
|
|||
// Sort out ARGV | |||
string argv; | |||
if ((args != null) && (args.Length > 0)) { | |||
List<string> quoted_args = new List<string>(); | |||
foreach (string s in args) { | |||
quoted_args.Add("'" + s + "'"); | |||
} | |||
argv = String.Format("ARGV << {0}\r\n", String.Join(" << ", quoted_args.ToArray())); | |||
} else { | |||
argv = ""; | |||
} | |||
// Prefix bootstrap with $0 and ARGV | |||
string boot = String.Format( | |||
"$0='{0}'\r\n{1}{2}", | |||
app, argv, _serfs.Read("bootstrap.rb") | |||
); | |||
ScriptSource source = engine.CreateScriptSourceFromString(boot, "bootstrap.rb", SourceCodeKind.File); | |||
int ex = source.ExecuteProgram(); | |||
context.Shutdown(); | |||
return ex; | |||
} | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,57 @@ | |||
# Bootstrapper patches load and require so that files can be | |||
# read from SERFS (Simple Embedded Resource File System) | |||
# It finishes by loading $0 (which should be set up before entry) | |||
|
|||
def read_embedded_file(path) | |||
$LOAD_PATH.each do |loc| | |||
test = "#{loc}/#{path}".gsub(/\\/,'/') | |||
str = SerfsInstance.read(test) | |||
return str.to_s if str | |||
end | |||
false | |||
end | |||
|
|||
# TODO: If the optional wrap parameter is true, the loaded script will be executed under an anonymous module, | |||
# TODO: protecting the calling program's global namespace. | |||
# TODO: In no circumstance will any local variables in the loaded file be propagated to the loading environment. | |||
def load_embedded_file(path, wrap = false) | |||
str = read_embedded_file(path) | |||
if (str) | |||
eval str, nil, path | |||
return true | |||
end | |||
false | |||
end | |||
|
|||
# Patch 'load' | |||
alias old_load load | |||
def load(filename, wrap = false) | |||
old_load(filename, wrap) | |||
rescue LoadError => load_error | |||
if load_error.message =~ /#{Regexp.escape filename}\z/ and load_embedded_file(filename, wrap) | |||
return true | |||
end | |||
raise load_error | |||
end | |||
|
|||
# Patch 'require' | |||
alias old_require require | |||
def require(path) | |||
return false if $".include?(path) | |||
old_require(path) | |||
rescue LoadError => load_error | |||
if load_error.message =~ /#{Regexp.escape path}\z/ | |||
str = (read_embedded_file(path + ".rb") || read_embedded_file(path)) | |||
if str | |||
$" << path | |||
eval str, nil, path | |||
return true | |||
end | |||
end | |||
raise load_error | |||
end | |||
private :old_require | |||
private :require | |||
|
|||
# Run | |||
load $0 if $0 |
Oops, something went wrong.