예제 #1
0
    public void Error_WritesErrorMessage()
    {
        using var mockConsole = new FakeConsole();

        Write.Error("MyError");

        Assert.Equal($"{Red}ERROR: MyError{Reset}{NL}", mockConsole.GetOuput());
    }
예제 #2
0
 public IWrite Error(object val)
 {
     return(Write.Error(val));
 }
예제 #3
0
 public override void Failed(Exception exception)
 {
     Write.Error(exception.Message);
 }
예제 #4
0
        public void AddPlan(string path, Func <byte[]> dataGetter)
        {
            var key = path.ToLowerInvariant();

            var directoryKeys      = new HashSet <string>();
            var pathParts          = key;
            var lastSeparatorIndex = pathParts.LastIndexOf("/");

            while (lastSeparatorIndex > 0)
            {
                pathParts = pathParts.Substring(0, lastSeparatorIndex);
                directoryKeys.Add(pathParts);
                lastSeparatorIndex = pathParts.LastIndexOf("/");
            }

            if (duplicateMap.ContainsKey(key))
            {
                var duplicatePath = duplicateMap[key];
                if (duplicatePath != path)
                {
                    Write.Error(
                        "Case mismatch!",
                        $"A file target was added twice to the build with different casing, which is not allowed!",
                        $"Previously: {White(Dim($"/{duplicatePath}"))}",
                        $"Now: {White(Dim($"/{path}"))}"
                        );
                    HasErrors = true;
                    return;
                }
                Write.Warn(
                    $"{Dim(path)} was added multiple times to the build and will be overwritten",
                    $"Re-Planned for {White(Dim($"/{path}"))}"
                    );
                plan[path]  = dataGetter;
                HasWarnings = true;
            }
            else if (directories.Contains(key))
            {
                Write.Error(
                    "Filepath conflict!",
                    "A directory already exists in the location where a file was to be placed",
                    $"Path in question: {White(Dim($"/{path}"))}"
                    );
                HasErrors = true;
                return;
            }
            else if (directoryKeys.Any(x => files.Contains(x)))
            {
                Write.Error(
                    "Directory path conflict!",
                    "A file already exists in the location where a directory was to be created",
                    $"Path in question: {White(Dim($"/{path}"))}"
                    );
                HasErrors = true;
                return;
            }
            else
            {
                plan[path]        = dataGetter;
                duplicateMap[key] = path;

                files.Add(key);
                foreach (var entry in directoryKeys)
                {
                    directories.Add(entry);
                }
                Write.Light($"Planned for /{path}");
            }
        }