├── rakefile.rb ├── tests ├── Caching Example │ ├── bin │ │ └── foo.exe │ ├── bar.cs │ └── foo.cs ├── Simple Example │ ├── bar.cs │ └── foo.cs └── tests.rb └── lib └── loveme.rb /rakefile.rb: -------------------------------------------------------------------------------- 1 | 2 | task :default do 3 | puts pwd 4 | ruby 'tests/tests.rb' 5 | end -------------------------------------------------------------------------------- /tests/Caching Example/bin/foo.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jcbozonier/IronLove/master/tests/Caching Example/bin/foo.exe -------------------------------------------------------------------------------- /tests/Caching Example/bar.cs: -------------------------------------------------------------------------------- 1 | public class Bar 2 | { 3 | public string GetValue() 4 | { 5 | return "test execution of exe successful!!"; 6 | } 7 | } -------------------------------------------------------------------------------- /tests/Simple Example/bar.cs: -------------------------------------------------------------------------------- 1 | public class Bar 2 | { 3 | public string GetValue() 4 | { 5 | return "test execution of exe successful!!"; 6 | } 7 | } -------------------------------------------------------------------------------- /tests/Simple Example/foo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class Foo 4 | { 5 | public static void Main(params string[] args) 6 | { 7 | var bar = new Bar(); 8 | Console.WriteLine(bar.GetValue()); 9 | } 10 | } -------------------------------------------------------------------------------- /tests/Caching Example/foo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class Foo 4 | { 5 | public static void Main(params string[] args) 6 | { 7 | var bar = new Bar(); 8 | Console.WriteLine(bar.GetValue() + "."); 9 | } 10 | } -------------------------------------------------------------------------------- /lib/loveme.rb: -------------------------------------------------------------------------------- 1 | files = Dir.glob("*.cs") 2 | compiler_args = "" 3 | 4 | if(File.exist? "bin/foo.exe") 5 | last_time_i_compiled = File.mtime("bin/foo.exe") 6 | i_prefer_to_compile = false 7 | 8 | files.each do |file| 9 | i_prefer_to_compile |= last_time_i_compiled < File.mtime(file) 10 | end 11 | else 12 | i_prefer_to_compile = true 13 | end 14 | 15 | files.each do |file| 16 | compiler_args += file + ' ' 17 | end 18 | 19 | Dir.mkdir "bin" unless File.directory? "bin" 20 | 21 | system "csc /out:\"bin/foo.exe\" #{compiler_args}" if i_prefer_to_compile 22 | 23 | system "bin/foo.exe" -------------------------------------------------------------------------------- /tests/tests.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'fileutils' 3 | 4 | 5 | 6 | class LoveMe_Tests < Test::Unit::TestCase 7 | # def setup 8 | # end 9 | 10 | # def teardown 11 | # end 12 | 13 | def test_when_interpreting_a_simple_do_nothing_class 14 | example_directory = "tests/Simple Example" 15 | 16 | compiled_executable_output = "" 17 | 18 | Dir.chdir(example_directory) do 19 | compiled_executable_output = `ruby "../../lib/loveme.rb"` 20 | puts "Simple output: " + compiled_executable_output 21 | end 22 | 23 | assert compiled_executable_output.include?("test execution of exe successful!!"), "the compiled executable should be executed." 24 | assert File.exist?(File.join(example_directory, 'bin/foo.exe')), "an executable should have been generated." 25 | 26 | # clean up 27 | FileUtils.rm_rf File.join(example_directory, 'bin') 28 | end 29 | 30 | def test_when_running_a_script_that_has_already_been_compiled_and_hasnt_changed_since_the_last_compilation 31 | example_directory = "tests/Caching Example" 32 | last_time_script_was_compiled = File.mtime(File.join(example_directory, "bin/foo.exe")) 33 | 34 | compiled_executable_output = "" 35 | 36 | Dir.chdir(example_directory) do 37 | compiled_executable_output = `ruby "../../lib/loveme.rb"` 38 | puts "Cached compilation: " + compiled_executable_output 39 | end 40 | 41 | new_script_compilation_time = File.new(File.join(example_directory, "bin/foo.exe")).mtime 42 | 43 | assert_equal new_script_compilation_time, last_time_script_was_compiled, "script should not have been recompiled." 44 | assert compiled_executable_output.include?("test execution of exe successful!!"), "the compiled executable should be executed." 45 | end 46 | end 47 | --------------------------------------------------------------------------------