Пример #1
0
        public void ReturnsMinus1IfCompilationFails()
        {
            var originalExe = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "sce.exe");
            var testDir     = TestUtil.GetTestDir(ReturnsMinus1IfCompilationFails);
            var exe         = Path.Combine(testDir, Path.GetFileName(originalExe));

            // ensure that source directory is deleted
            FS.EnsureDirectoryIsEmpty(testDir);

            File.Copy(originalExe, exe);

            var sourceDir = exe + ".src";

            // Start first time to create source dir
            var p = Run(exe);

            Assert.AreEqual(0, p.Result.process.ExitCode);

            // modify source
            File.WriteAllText(Path.Combine(sourceDir, "Program.cs"), @"
using System;

class Program
{
    internal static int Main(string[] args)
    {
        return 0.0;
    }
}
");

            // Start second time to recompile and return different exit code
            p = Run(exe);
            Assert.AreEqual(-1, p.Result.process.ExitCode);
        }
Пример #2
0
        public static string GetTestDir(Action test)
        {
            var a       = Assembly.GetExecutingAssembly();
            var testDir = Path.Combine(Path.GetDirectoryName(a.Location), "test", test.GetMethodInfo().DeclaringType.Name, test.GetMethodInfo().Name);

            FS.EnsureDirectoryIsEmpty(testDir);
            return(testDir);
        }
Пример #3
0
        public void WorksWhenRenamed()
        {
            var originalExe = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "sce.exe");
            var testDir     = TestUtil.GetTestDir(WorksWhenRenamed);
            var exe         = Path.Combine(testDir, "hello.exe");

            // ensure that source directory is deleted
            FS.EnsureDirectoryIsEmpty(testDir);

            File.Copy(originalExe, exe);

            var sourceDir = exe + ".src";

            // Start first time to create source dir
            var p = Run(exe);

            Assert.AreEqual(0, p.Result.process.ExitCode);

            // modify source
            var programCs = Path.Combine(sourceDir, "Program.cs");

            File.WriteAllText(programCs, @"
using System;

class Program
{
    internal static int Main(string[] args)
    {
        return 123;
    }
}
");


            // Start second time to recompile and return different exit code
            p = Run(exe);
            Assert.AreEqual(123, p.Result.process.ExitCode);

            // Start third time to remove old-sce-hello.exe
            p = Run(exe);
            Assert.AreEqual(123, p.Result.process.ExitCode);

            // delete the source dir
            FS.EnsureDirectoryNotExists(sourceDir);

            // Start to show that without code the default behaviour is restored again
            p = Run(exe);
            Assert.AreEqual(0, p.Result.process.ExitCode);
            Assert.IsTrue(File.Exists(programCs));
        }
Пример #4
0
        public void ProcessesShowTheirOutput()
        {
            var originalExe = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "sce.exe");
            var testDir     = TestUtil.GetTestDir(ProcessesShowTheirOutput);
            var exe         = Path.Combine(testDir, Path.GetFileName(originalExe));

            // ensure that source directory is deleted
            FS.EnsureDirectoryIsEmpty(testDir);

            File.Copy(originalExe, exe);

            Console.WriteLine("output from Console.WriteLine");
            Run(exe).Wait();
        }
Пример #5
0
        public void CanLoadEmbeddedNugetReferences()
        {
            var originalExe = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "sce.exe");
            var testDir     = TestUtil.GetTestDir(CanLoadEmbeddedNugetReferences);
            var exe         = Path.Combine(testDir, Path.GetFileName(originalExe));

            // ensure that source directory is deleted
            FS.EnsureDirectoryIsEmpty(testDir);

            File.Copy(originalExe, exe);

            var sourceDir = exe + ".src";

            // Start first time to create source dir
            var p = Run(exe);

            Assert.AreEqual(0, p.Result.process.ExitCode);

            // modify source
            var programCs = Path.Combine(sourceDir, "Program.cs");

            File.WriteAllText(programCs, @"
// nuget-package: log4net
// nuget-package: sidi-util
// nuget-package: Nunit

using System;

class Program
{
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    internal static int Main(string[] args)
    {
        log4net.Config.BasicConfigurator.Configure();
        log.Info(""hello from log4net"");
        log.Info(new Sidi.IO.LPath(@""C:\temp""));
        return 123;
    }
}
");

            // Start second time to recompile and return different exit code
            p = Run(exe);
            Assert.AreEqual(123, p.Result.process.ExitCode);
        }