コード例 #1
0
 /// <summary>
 /// Writes a detailed error message to the buffer
 /// </summary>
 /// <param name="buffer">Instance of <see cref="StringBuilder"/></param>
 /// <param name="sassСompilationException">Sass compilation exception</param>
 private static void WriteCompilationErrorDetails(StringBuilder buffer,
                                                  SassCompilationException sassСompilationException)
 {
     if (sassСompilationException.Status > 0)
     {
         buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Status, sassСompilationException.Status);
     }
     buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_Description, sassСompilationException.Description);
     if (!string.IsNullOrWhiteSpace(sassСompilationException.File))
     {
         buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_File, sassСompilationException.File);
     }
     if (sassСompilationException.LineNumber > 0)
     {
         buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_LineNumber,
                                 sassСompilationException.LineNumber.ToString(CultureInfo.InvariantCulture));
     }
     if (sassСompilationException.ColumnNumber > 0)
     {
         buffer.AppendFormatLine("{0}: {1}", Strings.ErrorDetails_ColumnNumber,
                                 sassСompilationException.ColumnNumber.ToString(CultureInfo.InvariantCulture));
     }
     if (!string.IsNullOrWhiteSpace(sassСompilationException.SourceFragment))
     {
         buffer.AppendFormatLine("{1}:{0}{0}{2}", Environment.NewLine,
                                 Strings.ErrorDetails_SourceFragment,
                                 sassСompilationException.SourceFragment);
     }
 }
コード例 #2
0
        public virtual void MappingSyntaxErrorDuringCompilationOfFileIsCorrect()
        {
            // Arrange
            string inputFilePath = Path.Combine(_filesDirectoryPath,
                                                string.Format("invalid-syntax/{0}/style{1}", _subfolderName, _fileExtension));

            SassCompilationException exception = null;

            // Act
            try
            {
                CompilationResult result = SassCompiler.CompileFile(inputFilePath);
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.NotEmpty(exception.Message);
            Assert.Equal(GetCanonicalPath(inputFilePath), exception.File);
            Assert.Equal(3, exception.LineNumber);
            Assert.Equal(13, exception.ColumnNumber);
        }
コード例 #3
0
        public virtual void MappingFileNotFoundErrorDuringCompilationOfFileIsCorrect()
        {
            // Arrange
            string inputFilePath = Path.Combine(_filesDirectoryPath,
                                                string.Format("non-existing-files/{0}/style{1}", _subfolderName, _fileExtension));

            SassCompilationException exception = null;

            // Act
            try
            {
                CompilationResult result = SassCompiler.CompileFile(inputFilePath);
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.NotEmpty(exception.Message);
            Assert.Null(exception.File);
            Assert.Equal(-1, exception.LineNumber);
            Assert.Equal(-1, exception.ColumnNumber);
        }
コード例 #4
0
        public virtual void MappingFileNotFoundErrorDuringCompilationOfCodeIsCorrect()
        {
            // Arrange
            string inputFilePath = Path.Combine(_filesDirectoryPath,
                                                string.Format("non-existing-files/{0}/base{1}", _subfolderName, _fileExtension));
            string inputCode = File.ReadAllText(inputFilePath);
            var    options   = new CompilationOptions
            {
                SourceMap = true
            };

            SassCompilationException exception = null;

            // Act
            try
            {
                CompilationResult result = SassCompiler.Compile(inputCode, inputFilePath, options: options);
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.NotEmpty(exception.Message);
            Assert.Equal(GetCanonicalPath(inputFilePath), exception.File);
            Assert.Equal(_syntaxType == SyntaxType.Sass ? 5 : 6, exception.LineNumber);
            Assert.Equal(1, exception.ColumnNumber);
        }
コード例 #5
0
        public void MappingSassSyntaxErrorDuringCompilationOfCode()
        {
            // Arrange
            string inputPath        = GenerateSassFilePath("invalid-syntax", "base");
            string input            = GetFileContent(inputPath);
            string importedFilePath = GenerateSassFilePath("invalid-syntax", "_reset");

            // Act
            string output;
            SassCompilationException exception = null;

            try
            {
                using (var sassCompiler = CreateSassCompiler())
                {
                    output = sassCompiler.Compile(input, inputPath).CompiledContent;
                }
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual(
                "Error: Expected newline." + Environment.NewLine +
                "   at @import (Files/imports/errors/invalid-syntax/sass/_reset.sass:5:9) -> " +
                "  margin; 0" + Environment.NewLine +
                "   at root stylesheet (Files/imports/errors/invalid-syntax/sass/base.sass:5:9)",
                exception.Message
                );
            Assert.AreEqual("Expected newline.", exception.Description);
            Assert.AreEqual(1, exception.Status);
            Assert.AreEqual(importedFilePath, exception.File);
            Assert.AreEqual(5, exception.LineNumber);
            Assert.AreEqual(9, exception.ColumnNumber);
            Assert.AreEqual(
                "Line 4: ol" + Environment.NewLine +
                "Line 5:   margin; 0" + Environment.NewLine +
                "----------------^" + Environment.NewLine +
                "Line 6:   padding: 0",
                exception.SourceFragment
                );
            Assert.AreEqual(
                "   at @import (Files/imports/errors/invalid-syntax/sass/_reset.sass:5:9)" + Environment.NewLine +
                "   at root stylesheet (Files/imports/errors/invalid-syntax/sass/base.sass:5:9)",
                exception.CallStack
                );
        }
コード例 #6
0
        public void MappingSassSyntaxDuringCompilationOfFile()
        {
            // Arrange
            string inputPath        = GenerateSassFilePath("invalid-syntax", "base");
            string importedFilePath = GenerateSassFilePath("invalid-syntax", "_reset");

            // Act
            string output;
            SassCompilationException exception = null;

            try
            {
                using (var sassCompiler = CreateSassCompiler())
                {
                    output = sassCompiler.CompileFile(inputPath).CompiledContent;
                }
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual(
                "Error: expected \"{\"." + Environment.NewLine +
                "   at @use (Files/modules/errors/invalid-syntax/scss/_reset.scss:6:10) -> " +
                "  padding; 0;" + Environment.NewLine +
                "   at root stylesheet (Files/modules/errors/invalid-syntax/scss/base.scss:1:1)",
                exception.Message
                );
            Assert.AreEqual("expected \"{\".", exception.Description);
            Assert.AreEqual(1, exception.Status);
            Assert.AreEqual(importedFilePath, exception.File);
            Assert.AreEqual(6, exception.LineNumber);
            Assert.AreEqual(10, exception.ColumnNumber);
            Assert.AreEqual(
                "Line 5:   margin: 0;" + Environment.NewLine +
                "Line 6:   padding; 0;" + Environment.NewLine +
                "-----------------^" + Environment.NewLine +
                "Line 7: }",
                exception.SourceFragment
                );
            Assert.AreEqual(
                "   at @use (Files/modules/errors/invalid-syntax/scss/_reset.scss:6:10)" + Environment.NewLine +
                "   at root stylesheet (Files/modules/errors/invalid-syntax/scss/base.scss:1:1)",
                exception.CallStack
                );
        }
コード例 #7
0
        public void MappingSassCustomErrorDuringCompilationOfCode()
        {
            // Arrange
            string inputPath = GenerateSassFilePath("custom-error", "base");
            string input     = GetFileContent(inputPath);

            // Act
            string output;
            SassCompilationException exception = null;

            try
            {
                using (var sassCompiler = CreateSassCompiler())
                {
                    output = sassCompiler.Compile(input, inputPath).CompiledContent;
                }
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual(
                "Error: \"Property top must be either left or right.\"" + Environment.NewLine +
                "   at root stylesheet (Files/modules/errors/custom-error/scss/base.scss:4:3) -> " +
                "  @include m.reflexive-position(top, 12px);",
                exception.Message
                );
            Assert.AreEqual("\"Property top must be either left or right.\"", exception.Description);
            Assert.AreEqual(1, exception.Status);
            Assert.AreEqual(inputPath, exception.File);
            Assert.AreEqual(4, exception.LineNumber);
            Assert.AreEqual(3, exception.ColumnNumber);
            Assert.AreEqual(
                "Line 3: .sidebar {" + Environment.NewLine +
                "Line 4:   @include m.reflexive-position(top, 12px);" + Environment.NewLine +
                "----------^" + Environment.NewLine +
                "Line 5: }",
                exception.SourceFragment
                );
            Assert.AreEqual(
                "   at root stylesheet (Files/modules/errors/custom-error/scss/base.scss:4:3)",
                exception.CallStack
                );
        }
コード例 #8
0
        public void MappingSassImportErrorDuringCompilationOfCode()
        {
            // Arrange
            string inputPath = GenerateSassFilePath("non-existing-files", "base");
            string input     = GetFileContent(inputPath);

            // Act
            string output;
            SassCompilationException exception = null;

            try
            {
                using (var sassCompiler = CreateSassCompiler())
                {
                    output = sassCompiler.Compile(input, inputPath).CompiledContent;
                }
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual(
                "Error: Can't find stylesheet to import." + Environment.NewLine +
                "   at root stylesheet (Files/imports/errors/non-existing-files/sass/base.sass:5:9) -> " +
                "@import normalize",
                exception.Message
                );
            Assert.AreEqual("Can't find stylesheet to import.", exception.Description);
            Assert.AreEqual(1, exception.Status);
            Assert.AreEqual(inputPath, exception.File);
            Assert.AreEqual(5, exception.LineNumber);
            Assert.AreEqual(9, exception.ColumnNumber);
            Assert.AreEqual(
                "Line 5: @import normalize" + Environment.NewLine +
                "----------------^" + Environment.NewLine +
                "Line 6: @import url(http://fonts.googleapis.com/css?family=Limelight&subset=latin,latin-ext)",
                exception.SourceFragment
                );
            Assert.AreEqual(
                "   at root stylesheet (Files/imports/errors/non-existing-files/sass/base.sass:5:9)",
                exception.CallStack
                );
        }
コード例 #9
0
        public void MappingSassImportErrorDuringCompilationOfCode()
        {
            // Arrange
            string inputPath = GenerateSassFilePath("non-existing-files", "base");
            string input     = GetFileContent(inputPath);

            // Act
            string output;
            SassCompilationException exception = null;

            try
            {
                using (var sassCompiler = CreateSassCompiler())
                {
                    output = sassCompiler.Compile(input, inputPath).CompiledContent;
                }
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual(
                "Error: Can't find stylesheet to import." + Environment.NewLine +
                "   at root stylesheet (Files/modules/errors/non-existing-files/scss/base.scss:1:1) -> " +
                "@use 'normalize';",
                exception.Message
                );
            Assert.AreEqual("Can't find stylesheet to import.", exception.Description);
            Assert.AreEqual(1, exception.Status);
            Assert.AreEqual(inputPath, exception.File);
            Assert.AreEqual(1, exception.LineNumber);
            Assert.AreEqual(1, exception.ColumnNumber);
            Assert.AreEqual(
                "Line 1: @use 'normalize';" + Environment.NewLine +
                "--------^",
                exception.SourceFragment
                );
            Assert.AreEqual(
                "   at root stylesheet (Files/modules/errors/non-existing-files/scss/base.scss:1:1)",
                exception.CallStack
                );
        }
コード例 #10
0
        public void MappingSassSyntaxErrorDuringCompilationOfCode()
        {
            // Arrange
            string inputPath = GenerateSassFilePath("invalid-syntax", "style");
            string input     = GetFileContent(inputPath);

            // Act
            string output;
            SassCompilationException exception = null;

            try
            {
                using (var sassCompiler = CreateSassCompiler())
                {
                    output = sassCompiler.Compile(input, inputPath).CompiledContent;
                }
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual(
                "Error: Expected \"." + Environment.NewLine +
                "   at Files/simple/errors/invalid-syntax/scss/style.scss:3:36 -> " +
                "    family: \"Open Sans, sans-serif;",
                exception.Message
                );
            Assert.AreEqual("Expected \".", exception.Description);
            Assert.AreEqual(1, exception.Status);
            Assert.AreEqual(inputPath, exception.File);
            Assert.AreEqual(3, exception.LineNumber);
            Assert.AreEqual(36, exception.ColumnNumber);
            Assert.AreEqual(
                "Line 2:   font: italic 20px/24px {" + Environment.NewLine +
                "Line 3:     family: \"Open Sans, sans-serif;" + Environment.NewLine +
                "-------------------------------------------^" + Environment.NewLine +
                "Line 4:   }",
                exception.SourceFragment
                );
            Assert.IsEmpty(exception.CallStack);
        }
コード例 #11
0
        public void UsageOfIncludePathsPropertyDuringCompilationOfCode()
        {
            // Arrange
            var withoutIncludedPathOptions = new CompilationOptions
            {
                IncludePaths = new List <string>()
            };
            var withIncludedPathOptions = new CompilationOptions
            {
                IncludePaths = new List <string> {
                    GenerateSassDirectoryPath("additional-path", "vendor")
                }
            };

            string inputPath = GenerateSassFilePath("additional-path", "base");
            string input     = GetFileContent(inputPath);

            string targetOutputPath2 = GenerateCssFilePath("additional-path", "base");
            string targetOutput2     = GetFileContent(targetOutputPath2);

            // Act
            SassCompilationException exception1 = null;
            string output2;

            using (var compiler = CreateSassCompiler())
            {
                try
                {
                    compiler.Compile(input, inputPath, options: withoutIncludedPathOptions);
                }
                catch (SassCompilationException e)
                {
                    exception1 = e;
                }

                output2 = compiler.Compile(input, inputPath, options: withIncludedPathOptions).CompiledContent;
            }

            // Assert
            Assert.IsNotNull(exception1);
            Assert.AreEqual(targetOutput2, output2);
        }
コード例 #12
0
        /// <summary>
        /// Generates a detailed error message
        /// </summary>
        /// <param name="sassСompilationException">Sass compilation exception</param>
        /// <param name="omitMessage">Flag for whether to omit message</param>
        /// <returns>Detailed error message</returns>
        public static string GenerateErrorDetails(SassCompilationException sassСompilationException,
                                                  bool omitMessage = false)
        {
            if (sassСompilationException == null)
            {
                throw new ArgumentNullException(nameof(sassСompilationException));
            }

            var           stringBuilderPool = StringBuilderPool.Shared;
            StringBuilder detailsBuilder    = stringBuilderPool.Rent();

            WriteCommonErrorDetails(detailsBuilder, sassСompilationException, omitMessage);
            WriteCompilationErrorDetails(detailsBuilder, sassСompilationException);

            detailsBuilder.TrimEnd();

            string errorDetails = detailsBuilder.ToString();

            stringBuilderPool.Return(detailsBuilder);

            return(errorDetails);
        }
コード例 #13
0
        public void MappingFileNotFoundErrorDuringCompilationOfFile()
        {
            // Arrange
            string inputPath = GenerateSassFilePath("non-existing-files", "style");

            // Act
            string output;
            SassCompilationException exception = null;

            try
            {
                using (var sassCompiler = CreateSassCompiler())
                {
                    output = sassCompiler.CompileFile(inputPath).CompiledContent;
                }
            }
            catch (SassCompilationException e)
            {
                exception = e;
            }

            // Assert
            Assert.NotNull(exception);
            Assert.AreEqual(
                string.Format("Error: No such file or directory: {0}", inputPath),
                exception.Message
                );
            Assert.AreEqual(
                string.Format("No such file or directory: {0}", inputPath),
                exception.Description
                );
            Assert.AreEqual(3, exception.Status);
            Assert.IsEmpty(exception.File);
            Assert.AreEqual(0, exception.LineNumber);
            Assert.AreEqual(0, exception.ColumnNumber);
            Assert.IsEmpty(exception.SourceFragment);
            Assert.IsEmpty(exception.CallStack);
        }
コード例 #14
0
        public void LatestMsieChakraIsSupported()
        {
            // Arrange
            IJsEngineFactory jsEngineFactory = new MsieJsEngineFactory(new MsieSettings
            {
                EngineMode = JsEngineMode.ChakraIeJsRt
            });
            const string input = @".icon-bug {
  background-image: url('http://www.codeplex.com/Download?ProjectName=bundletransformer&DownloadId=358407');
}";

            // Act
            string output;
            SassCompilationException exception = null;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                try
                {
                    using (var sassCompiler = new SassCompiler(jsEngineFactory))
                    {
                        output = sassCompiler.Compile(input, false).CompiledContent;
                    }
                }
                catch (SassCompilerLoadException)
                {
                    // Ignore this error
                }
                catch (SassCompilationException e)
                {
                    exception = e;
                }
            }

            // Assert
            Assert.Null(exception);
        }
コード例 #15
0
 public static string Format(SassCompilationException sassСompilationException)
 {
     return(GenerateErrorDetails(sassСompilationException));
 }