예제 #1
0
        public void IncludedFileReturns()
        {
            var jam1 =
                @"
Echo file1 ;
include file2.jam ;
Echo file1 post ;
";
            var jam2 =
                @"
Echo file2 ;
#return ;
Echo file2 post ;
";

            var jamProgram = new ProgramDescripton()
            {
                new SourceFileDescription()
                {
                    Contents = jam1, File = new NPath("file1.jam")
                },
                new SourceFileDescription()
                {
                    Contents = jam2, File = new NPath("file2.jam")
                },
            };

            AssertConvertedProgramHasIdenticalOutput(jamProgram);
        }
예제 #2
0
        private static void AssertConvertedProgramHasIdenticalOutput(ProgramDescripton program, IEnumerable <string> onlyConvert = null)
        {
            program[0].Contents = "NotFile all ;\n" + program[0].Contents;

            var jamRunInstructions = new JamRunnerInstructions {
                JamfilesToCreate = program
            };

            var jamResult = new JamRunner().Run(jamRunInstructions).Select(s => s.TrimEnd());

            Console.WriteLine("Jam:");
            foreach (var l in jamResult)
            {
                Console.WriteLine(l);
            }

            IEnumerable <string> csharpResult = null;

            Func <NPath, bool> shouldConvert = (NPath name) => onlyConvert == null || onlyConvert.Contains(name.ToString());

            try
            {
                var toBeCSharp = new ProgramDescripton(program.Where(f => shouldConvert(f.File)));
                var toStayJam  = new ProgramDescripton(program.Where(f => !shouldConvert(f.File)));

                var csharp = new JamToCSharpConverter().Convert(toBeCSharp);

                var convertedJamRunInstructions = new JamRunnerInstructions()
                {
                    CSharpFiles              = csharp,
                    JamfilesToCreate         = toStayJam,
                    JamFileToInvokeOnStartup = program[0].File.FileName
                };

                csharpResult = new JamRunner().Run(convertedJamRunInstructions).Select(s => s.TrimEnd());

                Console.WriteLine("C#:");
                foreach (var l in csharpResult)
                {
                    Console.WriteLine(l);
                }
                Console.WriteLine();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed converting/running to c#: " + e);
            }
            CollectionAssert.AreEqual(jamResult, csharpResult);
        }
예제 #3
0
        public void LocalScoping()
        {
            var jam1 =
                @"


myvar = 123 ;

include file2.jam ;

Echo $(myvar) from file 1 ;
MyRule ;

";
            var jam2 =
                @"

local myvar = harry ;

rule MyRule
{
   Echo $(myvar) from MyRule ;
}

MyRule ;

";

            var jamProgram = new ProgramDescripton()
            {
                new SourceFileDescription()
                {
                    Contents = jam1, File = new NPath("file1.jam")
                },
                new SourceFileDescription()
                {
                    Contents = jam2, File = new NPath("file2.jam")
                },
            };

            AssertConvertedProgramHasIdenticalOutput(jamProgram);
        }
예제 #4
0
        public void VariablePersistence()
        {
            var jam1 =
                @"
Echo this file will be csharp ;

myglobal = 123 ;
Echo myglobal from csharp $(myglobal) ;
include file2.jam ;
";
            var jam2 =
                @"
Echo this file will stay jam ;
Echo myglobal from jam $(myglobal) ;
myglobal = 312 ;
include file3.jam ;
";

            var jam3 =
                @"
Echo and this file is csharp again ;
Echo myglobal from file3 $(myglobal) ;
";

            var jamProgram = new ProgramDescripton()
            {
                new SourceFileDescription()
                {
                    Contents = jam1, File = new NPath("file1.jam")
                },
                new SourceFileDescription()
                {
                    Contents = jam2, File = new NPath("file2.jam")
                },
                new SourceFileDescription()
                {
                    Contents = jam3, File = new NPath("file3.jam")
                }
            };

            AssertConvertedProgramHasIdenticalOutput(jamProgram, new[] { "file1.jam", "file3.jam" });
        }
예제 #5
0
        public void Include()
        {
            var jam1 =
                @"
Echo this file will be csharp ;
myvar = file2.jam ;
include $(myvar) ;
Echo file1 post ;
";
            var jam2 =
                @"
Echo this file will stay jam ;
include file3.jam ;
Echo file2 post ;
";

            var jam3 =
                @"
Echo and this file is csharp again ;
";

            var jamProgram = new ProgramDescripton()
            {
                new SourceFileDescription()
                {
                    Contents = jam1, File = new NPath("file1.jam")
                },
                new SourceFileDescription()
                {
                    Contents = jam2, File = new NPath("file2.jam")
                },
                new SourceFileDescription()
                {
                    Contents = jam3, File = new NPath("file3.jam")
                }
            };

            AssertConvertedProgramHasIdenticalOutput(jamProgram, new[] { "file1.jam", "file3.jam" });
        }