Ejemplo n.º 1
0
 private static void Success(DyaOptions options, string name, string fileName)
 {
     commands.Add($"AddTest {name} -Outcome Passed -Framework DyaUnit -FileName {fileName}");
     if (!options.ShowOnlyFailedTests)
     {
         Printer.Output($"{name}: Success");
     }
 }
Ejemplo n.º 2
0
        private static void Run(IList <FunSet> funs, DyaOptions options)
        {
            var passed = 0;
            var failed = 0;
            var i      = 0;

            foreach (var funSet in funs)
            {
                var padLen    = funSet.Funs.Count.ToString().Length;
                var hasHeader = false;

                void printIt(int i, bool failed)
                {
                    if (!hasHeader && (failed || !options.ShowOnlyFailedTests))
                    {
                        Printer.LineFeed();
                        Printer.Output($"{Path.GetFileName(funSet.FileName)}:");
                        hasHeader = true;
                    }

                    if (failed || !options.ShowOnlyFailedTests)
                    {
                        Console.Write($"[{i.ToString().PadLeft(padLen, '0')}] ");
                    }
                }

                foreach (var fn in funSet.Funs)
                {
                    i++;

                    try
                    {
                        var res = fn.Value.Call(funSet.Context).ToObject();
                        printIt(i, false);
                        Success(options, fn.Key, funSet.FileName);
                        passed++;
                    }
                    catch (Exception ex)
                    {
                        printIt(i, true);
                        Failed(options, fn.Key, ex.Message, funSet.FileName);
                        failed++;
                    }
                }
            }

            Printer.LineFeed();
            Printer.Output("Total:");
            Printer.Output($"{passed} passed, {failed} failed in {funs.Count} file(s)");

            if (options.AppVeyour)
            {
                Submit();
            }
        }
Ejemplo n.º 3
0
        public InteractiveContext(DyaOptions options)
        {
            Options      = options;
            BuildOptions = CreateBuildOptions(options);

            var lookup = FileLookup.Create(
                options.FileNames == null || options.FileNames.Length == 0 || string.IsNullOrWhiteSpace(options.FileNames[0])
                    ? Environment.CurrentDirectory
                    : Path.GetDirectoryName(options.FileNames[0]), options.Paths);

            Linker = new DyIncrementalLinker(lookup, BuildOptions, options.UserArguments);
        }
Ejemplo n.º 4
0
        private static bool RunTests(DyaOptions options)
        {
            if (options.FileNames == null || options.FileNames.Length == 0 ||
                string.IsNullOrEmpty(options.FileNames[0]))
            {
                Printer.Error("File name(s) not specified.");
                return(false);
            }

            return(TestRunner.RunTests(options.GetFileNames(), options,
                                       InteractiveContext.CreateBuildOptions(options)));
        }
Ejemplo n.º 5
0
        private static bool Run(DyaOptions options)
        {
            Printer.Header();

            ctx        = new InteractiveContext(options);
            dispatcher = new CommandDispatcher(ctx);

            if (options.Test)
            {
                Printer.LineFeed();
                return(RunTests(options));
            }
            else if (options.Compile)
            {
                Printer.LineFeed();
                return(Compile(options));
            }
            else if (options.FileNames != null && options.FileNames.Length > 0)
            {
                Printer.LineFeed();
                var i = 0;

                foreach (var f in options.GetFileNames())
                {
                    if (i > 0)
                    {
                        ctx.Reset();
                    }

                    if (!ctx.EvalFile(f, options.MeasureTime))
                    {
                        return(false);
                    }

                    i++;
                }

                if (options.StayInInteractive)
                {
                    RunInteractive();
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                RunInteractive();
            }

            return(true);
        }
Ejemplo n.º 6
0
        private static bool Prepare(string[] args, out DyaOptions options)
        {
            try
            {
                var config = ConfigReader.Read(Path.Combine(FS.GetStartupPath(), "config.json"));
                options = CommandLineReader.Read <DyaOptions>(args, config);
            }
            catch (DyaException ex)
            {
                Printer.Header();
                Printer.LineFeed();
                Printer.Error(ex.Message);
                options = null;
                return(false);
            }

            Printer.NoLogo = options.NoLogo;
            return(true);
        }
Ejemplo n.º 7
0
        private static bool Compile(DyaOptions options)
        {
            var ctx = new InteractiveContext(options);

            foreach (var f in options.GetFileNames())
            {
                var outFile = options.OutputDirectory;

                if (string.IsNullOrWhiteSpace(outFile))
                {
                    outFile = Path.Combine(Path.GetDirectoryName(f), Path.GetFileNameWithoutExtension(f) + ".dyo");
                }
                else if (Directory.Exists(outFile))
                {
                    outFile = Path.Combine(outFile, Path.GetFileNameWithoutExtension(f) + ".dyo");
                }

                if (!File.Exists(f) || !ctx.Compile(f, out var unit))
                {
                    Printer.Error($"Compilation of file \"{f}\" skipped.");
                    continue;
                }

#if !DEBUG
                try
#endif
                {
                    ObjectFileWriter.Write(outFile, unit);
                    Printer.Information($"Compilation completed. File saved: \"{outFile}\"");
                }
#if !DEBUG
                catch (Exception ex)
                {
                    Printer.Error(ex.Message);
                    Printer.Error($"Compilation of file \"{f}\" skipped.");
                    continue;
                }
#endif
            }

            return(true);
        }
Ejemplo n.º 8
0
        public static bool RunTests(IEnumerable <string> fileNames, DyaOptions dyaOptions, BuilderOptions buildOptions)
        {
#if !DEBUG
            try
#endif
            {
                var funs = Compile(fileNames, buildOptions, out var warns);
                Printer.Output($"Running tests from {funs.Count} file(s):");
                Printer.Output(string.Join(' ', funs.Select(f => Path.GetFileName(f.FileName))));

                if (funs == null)
                {
                    return(false);
                }

                Run(funs, dyaOptions);

                if (warns.Count > 0)
                {
                    Printer.LineFeed();
                    Printer.Output($"Warnings:");
                    foreach (var w in warns)
                    {
                        Printer.Output(w.ToString());
                    }
                }

                return(true);
            }
#if !DEBUG
            catch (Exception ex)
            {
                Printer.Error($"Failure! {ex.Message}");
                return(false);
            }
#endif
        }
Ejemplo n.º 9
0
        public static BuilderOptions CreateBuildOptions(DyaOptions options)
        {
            var ret = new BuilderOptions
            {
                Debug            = options.Debug,
                NoOptimizations  = options.NoOptimizations,
                NoLangModule     = options.NoLang,
                NoWarnings       = options.NoWarnings,
                NoWarningsLinker = options.NoWarningsLinker
            };

            if (options.IgnoreWarnings != null)
            {
                foreach (var i in options.IgnoreWarnings)
                {
                    if (!ret.IgnoreWarnings.Contains(i))
                    {
                        ret.IgnoreWarnings.Add(i);
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 10
0
 private static void Failed(DyaOptions options, string name, string reason, string fileName)
 {
     commands.Add($"AddTest {name} -Outcome Failed -Framework DyaUnit -FileName {fileName}");
     Printer.Output($"{name}: Failed: {reason}");
 }