예제 #1
0
        public void GetSkippedBlocks_IfDefinedBlockWithDefinedMacro_SkippedBlockIncludesIfDefinedBlock()
        {
            File.WriteAllText(sourceFilePath,
                              @"#if defined(__GNUC__)
#  include <avr/io.h>
#elif defined(__ICCAVR__)
#  include <ioavr.h>
#  include <intrinsics.h>
#else
#  error Unsupported compiler.
#endif");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var preprocessor = adapter.GetPreprocessor();
            {
                var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
                var skippedBlock  = skippedBlocks.First();
                Assert.AreEqual(4, skippedBlock.Item1);
                Assert.AreEqual(5, skippedBlock.Item2);

                skippedBlock = skippedBlocks.ElementAt(1);
                Assert.AreEqual(7, skippedBlock.Item1);
                Assert.AreEqual(7, skippedBlock.Item2);
            }
        }
예제 #2
0
        public void GetSkippedBlocks_IfMultipleElifDirectiveWithIfDirectiveFalseAndSecondElifDirectiveTrue_SkippedBlockIncludesSecondElifBlock()
        {
            File.WriteAllText(sourceFilePath,
                              @"#define X 0
#define Y 0
#define Z 2
#if X 
#define foo x*y
#elif Y
#define foo x/y
#elif Z
#define foo x-y
#endif
");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var preprocessor = adapter.GetPreprocessor();
            {
                var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
                var skippedBlock  = skippedBlocks.First();
                Assert.AreEqual(4, skippedBlock.Item1);
                Assert.AreEqual(8, skippedBlock.Item2);
            }
        }
예제 #3
0
        public void GetDiagnostics_CFileInDiskHasPreprocessorCodeAndNoWarningsTextHasOneWarning_OneDiagnosticsReturned()
        {
            var sourceInFile =
                @"#if defined(__GNUC__)
    int x = 20;
#elif defined (__ICCAVR__)
    int x = 30;
    int y = 20;
#else
#error Unsupported compiler
#endif
";
            var sourceInEditor = sourceInFile +
                                 @"int func(){ }

int main(){}
";

            File.WriteAllText(sourceFilePath, sourceInFile);
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(sourceInFile);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);

            adapter.Process(sourceInEditor);
            diags = adapter.GetDiagnostics();

            Assert.AreEqual(1, diags.Count);
            Assert.AreEqual(9, diags.First().StartLine);
        }
예제 #4
0
        public void GetSkippedBlocks_IfSingleElifDirectiveWithElifDirectiveFalse_SkippedBlockIncludesElifBlock()
        {
            File.WriteAllText(sourceFilePath,
                              @"#define X 1
#define Y 0
#define Z 0
#if X 
#define foo x*y
#elif Z + 0
#define foo x+y
#elif Y
#define foo x/y
#elif Z
#define foo x-y
#endif
");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var preprocessor = adapter.GetPreprocessor();
            {
                var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();

                var skippedBlock = skippedBlocks.First();
                Assert.AreEqual(6, skippedBlock.Item1);
                Assert.AreEqual(12, skippedBlock.Item2);
            }
        }
예제 #5
0
        public void GetSkippedBlocks_TwoIfBlocksBothFalse_SkippedBlockIncludesBothBlocks()
        {
            File.WriteAllText(sourceFilePath,
                              @"#if 0
#define foo x+y
#endif
#if 0
#define foo x-y
#endif
");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var preprocessor = adapter.GetPreprocessor();
            {
                var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
                var skippedBlock  = skippedBlocks.First();
                Assert.AreEqual(1, skippedBlock.Item1);
                Assert.AreEqual(3, skippedBlock.Item2);

                skippedBlock = skippedBlocks.ElementAt(1);
                Assert.AreEqual(4, skippedBlock.Item1);
                Assert.AreEqual(6, skippedBlock.Item2);
            }
        }
예제 #6
0
 public void GetSkippedBlocks_EmptyFile_NoSkippedBlocksReported()
 {
     File.WriteAllText(sourceFilePath,
     @"");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     AssertSkippedBlocksMatch(adapter, new Tuple<int, int>[] { });
 }
예제 #7
0
        public void GetDiagnostics_EmptyCFile_NoDiagnosticsReturned()
        {
            File.WriteAllText(sourceFilePath, "");
            var adapter = new ClangAdapter(sourceFilePath);
            var diags   = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #8
0
        public void GetDiagnostics_C99StyleSyntaxUsedWithC99TurnedOn_NoDiagnosticsReturned()
        {
            File.WriteAllText(sourceFilePath, @"int main() { for (int i = 0; i < 10; i++){} for (int i = 0; i < 10; i++){} return 0;}");
            var adapter = new ClangAdapter(sourceFilePath, new List<string>(), new List<string>(), Language.C99);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #9
0
        public void GetSkippedBlocks_EmptyFile_NoSkippedBlocksReported()
        {
            File.WriteAllText(sourceFilePath,
                              @"");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            AssertSkippedBlocksMatch(adapter, new Tuple <int, int>[] { });
        }
예제 #10
0
        public void GetDiagnostics_boolKeyword_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @" bool test = true;");

            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #11
0
        private static ClangAdapter GetClangAdapterForBuffer(ITextBuffer buffer)
        {
            ClangAdapter clangAdapter = null;

            ThreadHelper.Generic.Invoke(new Action(() =>
            {
                clangAdapter = buffer.Properties.GetOrCreateSingletonProperty <ClangAdapter>(() => CreateClangAdapter(buffer));
            }));
            return(clangAdapter);
        }
예제 #12
0
        public void GetDiagnostics_InlineKeyword_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"static inline void Foo(){}");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #13
0
        public void GetDiagnostics_MisspelledMemberName_DiagnosticIncludesSuggestedMember()
        {
            File.WriteAllText(sourceFilePath, @"struct A { int Foo; }; int main() { struct A a; a.Fo = 2; }");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            StringAssert.Contains(diags.First().Message, "did you mean 'Foo'?");
        }
예제 #14
0
        public void GetDiagnostics_AVRGCCSpecificBuiltin_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"void fun() { __builtin_csrf(1); }");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #15
0
        public void GetDiagnostics_C99StyleSyntaxUsedWithC99TurnedOn_NoDiagnosticsReturned()
        {
            File.WriteAllText(sourceFilePath, @"int main() { for (int i = 0; i < 10; i++){} for (int i = 0; i < 10; i++){} return 0;}");
            var adapter = new ClangAdapter(sourceFilePath, new List <string>(), new List <string>(), Language.C99);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #16
0
        public void GetDiagnostics_EmptyCppFile_NoDiagnosticsReturned()
        {
            File.WriteAllText(cppSourceFilePath, "");
            var adapter = new ClangAdapter(cppSourceFilePath, new List <string>(), new List <string>(), Language.Cpp);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #17
0
        public void GetDiagnostics_ClassDeclarationInCpp_NoDiagnosticsReturned()
        {
            File.WriteAllText(cppSourceFilePath, @"
class C{};
");
            var adapter = new ClangAdapter(cppSourceFilePath, new List <string>(), new List <string>(), Language.Cpp);

            adapter.Process(null);
            Assert.AreEqual(0, adapter.GetDiagnostics().Count());
        }
예제 #18
0
        public void GetDiagnostics_ShortCastToIntPointerForARM_OneDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"volatile short x; int main() { return *(int *)x; }");

            var adapter = new ClangAdapter(sourceFilePath, new List <string>(), new List <string>(), Language.C, Arch.ARM);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(1, diags.Count());
        }
예제 #19
0
        public void GetDiagnostics_LongLongCastToUInt32ForARM_OneDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"int main() { typedef unsigned int uint32_t __attribute__((__mode__(SI))); uint32_t v = 0xABCDEFABCD; return 1; }");

            var adapter = new ClangAdapter(sourceFilePath, new List <string>(), new List <string>(), Language.C, Arch.ARM);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(1, diags.Count());
        }
예제 #20
0
        public void GetDiagnostics_LongCastToUInt32ForAVR_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"int main() { typedef unsigned int uint32_t __attribute__((__mode__(SI))); uint32_t v = 0xABCDEFABL; return 1; }");

            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #21
0
        [TestMethod] public void GetDiagnostics_ShortCastToIntPointerForAVR_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"volatile short x; int main() { return *(int *)x; }");

            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #22
0
        public void GetDiagnostics_Cpp11StyleSyntaxUsedWithCpp11TurnedOn_NoDiagnosticsReturned()
        {
            File.WriteAllText(cppSourceFilePath,
                              @"auto it = 4;");
            var adapter = new ClangAdapter(cppSourceFilePath, new List <string>(), new List <string>(), Language.Cpp11);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #23
0
        public void GetDiagnostics_asmExtension_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @" #define barrier()  asm volatile("""" ::: ""memory"")
               int main() { barrier(); }");

            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #24
0
        public void GetDiagnostics_boolKeyword_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @" bool test = true;");

            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #25
0
        public void GetDiagnostics_asmExtension_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @" #define barrier()  asm volatile("""" ::: ""memory"")
   int main() { barrier(); }");

            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #26
0
        public void GetDiagnostics_DestructorDefinedOutsideClassWithCpp11TurnedOn_NoDiagnosticsReturned()
        {
            File.WriteAllText(cppSourceFilePath,
                              @"class C { ~C(); };
                                C::~C() {}");
            var adapter = new ClangAdapter(cppSourceFilePath, new List <string>(), new List <string>(), Language.Cpp11);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #27
0
        public void GetSkippedBlocks_IfDirectiveWithoutDefinition_SkippedBlockIncludesIfBlock()
        {
            File.WriteAllText(sourceFilePath,
                              @"#if 2 - 2 
#define foo x*y
#endif
");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(1, 3) });
        }
예제 #28
0
        void AssertSkippedBlocksMatch(ClangAdapter adapter, IEnumerable <Tuple <int, int> > expected)
        {
            var preprocessor            = adapter.GetPreprocessor();
            var skippedBlockLineNumbers = preprocessor.GetSkippedBlockLineNumbers();

            Assert.AreEqual(expected.Count(), skippedBlockLineNumbers.Count());

            for (int i = 0; i < expected.Count(); ++i)
            {
                Assert.AreEqual(expected.ElementAt(i), skippedBlockLineNumbers.ElementAt(i));
            }
        }
예제 #29
0
 public void ExpandMacro_MacroDefinitionIncludesAnotherMacro_ExpansionExpandsInnerMacro()
 {
     File.WriteAllText(sourceFilePath, @"
     #define x 2
     #define foo x*y
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     var preprocessor = adapter.GetPreprocessor();
     {
         Assert.AreEqual("2*y", preprocessor.ExpandMacro("foo"));
     }
 }
예제 #30
0
        public void GetDiagnostics_SymbolInSourceCodeProvidedInPredefinedSymbolList_NoDiagnosticsReturned()
        {
            File.WriteAllText(sourceFilePath, @"int main() { return FOO; }");
            var adapter = new ClangAdapter(sourceFilePath, new List <string>(), new List <string>()
            {
                "FOO=2"
            });

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #31
0
        public void GetSkippedBlocks_UnmatchedExcludedIf_EverythingAfterIfReportedAsSkippedBlock()
        {
            File.WriteAllText(sourceFilePath,
                              @"int nothing = 0;
#if 0
#define blah 0
#define blah 2
");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(2, 5) });
        }
예제 #32
0
        public void GetDiagnostics_CFileInDiskHasOneWarningTextHasNoWarning_OneDiagnosticsReturned()
        {
            var sourceInEditor = "int func(){ return 0; }";
            var sourceInFile   = "int func(){}";

            File.WriteAllText(sourceFilePath, sourceInFile);
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(sourceInEditor);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #33
0
        public void GetDiagnostics_CFileInDiskWithOneWarning_OneDiagnosticsReturned()
        {
            var sourceText = "int func(){}";

            File.WriteAllText(sourceFilePath, sourceText);
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);

            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(1, diags.Count);
        }
예제 #34
0
        public void GetDiagnostics_SingleLineCommentWithAsterisk_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"
//*
int main() { return 0; }
");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #35
0
        public void GetSkippedBlocks_IfDirectiveWithElseDirectiveEvaluationTrue_SkippedBlockIncludesElseBlock()
        {
            File.WriteAllText(sourceFilePath,
                              @"#if 2 
#define foo x*y
#else
#define foo x-y
#endif
");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(3, 5) });
        }
예제 #36
0
 public void GetSkippedBlocks_IfBlockWithMultiplePreprocessorDefinitions_SkippedBlockIncludesAllLines()
 {
     File.WriteAllText(sourceFilePath,
     @"#if 0
     #define foo x+y
     #define fat boo
     #define fal laf
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     var preprocessor = adapter.GetPreprocessor();
     {
         var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
         var skippedBlock = skippedBlocks.First();
         Assert.AreEqual(2, skippedBlock.Item1);
         Assert.AreEqual(4, skippedBlock.Item2);
     }
 }
예제 #37
0
 public void GetSkippedBlocks_IfBlockWithMultiplePreprocessorDefinitionsIsTrue_SkippedBlockIsEmpty()
 {
     File.WriteAllText(sourceFilePath,
     @"#if 1
     #define foo x+y
     #define fat boo
     #define fal laf
     #endif
     int x = 20;
     #if 1
     #define foo x+y
     #define fat boo
     #define fal laf
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     var preprocessor = adapter.GetPreprocessor();
     {
         var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
         Assert.IsFalse(skippedBlocks.Any());
     }
 }
예제 #38
0
        public void GetDiagnostics_CFileInDiskHasOneWarningTextHasNoWarning_OneDiagnosticsReturned()
        {
            var sourceInEditor =  "int func(){ return 0; }";
            var sourceInFile =  "int func(){}";

            File.WriteAllText(sourceFilePath, sourceInFile);
            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(sourceInEditor);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #39
0
        public void GetDiagnostics_ShortCastToIntPointerForAVR_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"volatile short x; int main() { return *(int *)x; }");

            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #40
0
        public void GetSkippedBlocks_IfDefinedBlockWithDefinedMacro_SkippedBlockIncludesIfDefinedBlock()
        {
            File.WriteAllText(sourceFilePath,
            @"#if defined(__GNUC__)
            #  include <avr/io.h>
            #elif defined(__ICCAVR__)
            #  include <ioavr.h>
            #  include <intrinsics.h>
            #else
            #  error Unsupported compiler.
            #endif");
            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var preprocessor = adapter.GetPreprocessor();
            {
                var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
                var skippedBlock = skippedBlocks.First();
                Assert.AreEqual(4, skippedBlock.Item1);
                Assert.AreEqual(5, skippedBlock.Item2);

                skippedBlock = skippedBlocks.ElementAt(1);
                Assert.AreEqual(7, skippedBlock.Item1);
                Assert.AreEqual(7, skippedBlock.Item2);

            }
        }
예제 #41
0
 public void GetSkippedBlocks_IfMultipleElifDirectiveWithIfDirectiveFalseAndFirstElifDirectiveTrue_SkippedBlockIncludesFirstElifBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"#define X 0
     #define Y 1
     #define Z 2
     #if X
     #define foo x*y
     #elif Y
     #define foo x/y
     #elif Z
     #define foo x-y
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(5, 5), Tuple.Create(9, 9)});
 }
예제 #42
0
        public void GetSkippedBlocks_IfElseBlockWithElseBlockExcludedAndCodeTypedBeforeBlock_SkippedBlockIncludesExcludedCode()
        {
            var mainCode =
            @"#if BLAH
            #define foo x+y
            #define bar x-y
            #else
            #define fal laf
            #endif";
            File.WriteAllText(sourceFilePath, mainCode);
            var adapter = new ClangAdapter(sourceFilePath);

            var preprocessor = adapter.GetPreprocessor();
            adapter.Process(mainCode);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(3, 4) });

            var initialText = "#define BLAH 0" + Environment.NewLine + mainCode;
            adapter.Process(initialText);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(3, 4) });

            var laterText = "#define BLAH 2" + Environment.NewLine + mainCode;
            adapter.Process(laterText);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(6, 6) });

            adapter.Process(initialText);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(3, 4) });

            adapter.Process(laterText);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(6, 6) });

            adapter.Process(initialText);
            AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(3, 4) });
        }
예제 #43
0
 public void GetSkippedBlocks_IfDirectiveWithElseDirectiveEvaluationTrue_SkippedBlockIncludesElseBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"#if 2
     #define foo x*y
     #else
     #define foo x-y
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(4, 4)});
 }
예제 #44
0
 public void GetSkippedBlocks_IfDefinedBlockWithUndefinedMacro_SkippedBlockIncludesIfDefinedBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"#if defined(OOLALALA)
     #  include <avr/io.h>
     #endif");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     var preprocessor = adapter.GetPreprocessor();
     {
         var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
         var skippedBlock = skippedBlocks.First();
         Assert.AreEqual(2, skippedBlock.Item1);
         Assert.AreEqual(2, skippedBlock.Item2);
     }
 }
예제 #45
0
        public void GetDiagnostics_WarningMadeAndCorrectedInEditor_ZeroDiagnosticsReturned()
        {
            var initialSourceInEditor =  "int func(){ }";
            var currentSourceInEditor =  "int func(){ return 0; }";
            var sourceInFile =  "";

            File.WriteAllText(sourceFilePath, sourceInFile);
            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();
            Assert.AreEqual(0, diags.Count);

            adapter.Process(initialSourceInEditor);
            diags = adapter.GetDiagnostics();
            Assert.AreEqual(1, diags.Count);

            adapter.Process(currentSourceInEditor);
            diags = adapter.GetDiagnostics();
            Assert.AreEqual(0, diags.Count);
        }
예제 #46
0
 public void GetSkippedBlocks_UnmatchedExcludedIf_EverythingAfterIfReportedAsSkippedBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"int nothing = 0;
     #if 0
     #define blah 0
     #define blah 2
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(3, 0) });
 }
예제 #47
0
        void AssertSkippedBlocksMatch(ClangAdapter adapter, IEnumerable<Tuple<int, int>> expected)
        {
            var preprocessor = adapter.GetPreprocessor();
            var skippedBlockLineNumbers = preprocessor.GetSkippedBlockLineNumbers();

            Assert.AreEqual(expected.Count(), skippedBlockLineNumbers.Count());

            for (int i = 0; i < expected.Count(); ++i)
            {
                Assert.AreEqual(expected.ElementAt(i), skippedBlockLineNumbers.ElementAt(i));
            }
        }
예제 #48
0
 public void GetSkippedBlocks_IfNDefDirectiveWithDefinition_SkippedBlockIncludesElseBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"#define HUHU 1
     #ifndef HUHU
     #define foo x*y
     #else
     #define foo x-y
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(3, 3)});
 }
예제 #49
0
 public void GetSkippedBlocks_IfDefDirectiveWithoutDefinition_SkippedBlockIncludesIfdefBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"#ifdef x
     #define foo x*y
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(2,2)});
 }
예제 #50
0
        public void GetDiagnostics_UnknownAttribute_WarningReported()
        {
            File.WriteAllText(sourceFilePath, @"__attribute__((__interrupt__)) void rtc() {}");

            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics().ToList();

            Assert.AreEqual(1, diags.Count());
            var diag = diags[0];

            Assert.AreEqual(DiagnosticLevel.Warning, diag.Level);
        }
예제 #51
0
        public void GetDiagnostics_SymbolInSourceCodeProvidedInPredefinedSymbolList_NoDiagnosticsReturned()
        {
            File.WriteAllText(sourceFilePath, @"int main() { return FOO; }");
            var adapter = new ClangAdapter(sourceFilePath, new List<string>(), new List<string>() { "FOO=2" });
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
예제 #52
0
        public void GetSkippedBlocks_IfSingleElifDirectiveWithElifDirectiveFalse_SkippedBlockIncludesElifBlock()
        {
            File.WriteAllText(sourceFilePath,
            @"#define X 1
            #define Y 0
            #define Z 0
            #if X
            #define foo x*y
            #elif Z + 0
            #define foo x+y
            #elif Y
            #define foo x/y
            #elif Z
            #define foo x-y
            #endif
            ");
            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var preprocessor = adapter.GetPreprocessor();
            {
                var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();

                var skippedBlock = skippedBlocks.First();
                Assert.AreEqual(7, skippedBlock.Item1);
                Assert.AreEqual(7, skippedBlock.Item2);

                skippedBlock = skippedBlocks.ElementAt(1);
                Assert.AreEqual(9, skippedBlock.Item1);
                Assert.AreEqual(9, skippedBlock.Item2);

                skippedBlock = skippedBlocks.ElementAt(2);
                Assert.AreEqual(11, skippedBlock.Item1);
                Assert.AreEqual(11, skippedBlock.Item2);
            }
        }
예제 #53
0
        public void GetDiagnostics_SingleLineCommentWithAsterisk_NoDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"
            //*
            int main() { return 0; }
            ");
            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count());
        }
예제 #54
0
 public void GetSkippedBlocks_IfMultipleElifDirectiveWithIfDirectiveFalseAndSecondElifDirectiveTrue_SkippedBlockIncludesSecondElifBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"#define X 0
     #define Y 0
     #define Z 2
     #if X
     #define foo x*y
     #elif Y
     #define foo x/y
     #elif Z
     #define foo x-y
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     var preprocessor = adapter.GetPreprocessor();
     {
         var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
         var skippedBlock = skippedBlocks.First();
         Assert.AreEqual(4, skippedBlock.Item1);
         Assert.AreEqual(8, skippedBlock.Item2);
     }
 }
예제 #55
0
        public void GetDiagnostics_ShortCastToIntPointerForARM_OneDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"volatile short x; int main() { return *(int *)x; }");

            var adapter = new ClangAdapter(sourceFilePath, new List<string>(), new List<string>(), Language.C, Arch.ARM);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(1, diags.Count());
        }
예제 #56
0
        public void GetSkippedBlocks_TwoIfBlocksBothFalse_SkippedBlockIncludesBothBlocks()
        {
            File.WriteAllText(sourceFilePath,
            @"#if 0
            #define foo x+y
            #endif
            #if 0
            #define foo x-y
            #endif
            ");
            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var preprocessor = adapter.GetPreprocessor();
            {
                var skippedBlocks = preprocessor.GetSkippedBlockLineNumbers();
                var skippedBlock = skippedBlocks.First();
                Assert.AreEqual(2, skippedBlock.Item1);
                Assert.AreEqual(2, skippedBlock.Item2);

                skippedBlock = skippedBlocks.ElementAt(1);
                Assert.AreEqual(5, skippedBlock.Item1);
                Assert.AreEqual(5, skippedBlock.Item2);
            }
        }
예제 #57
0
 public void GetSkippedBlocks_IfSingleElifDirectiveWithIfDirectiveFalse_SkippedBlockIncludesIfBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"#define X 0
     #define Y 1
     #if X
     #define foo x*y
     #elif Y
     #define foo x/y
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(4, 4)});
 }
예제 #58
0
        public void GetDiagnostics_MisspelledMemberName_DiagnosticIncludesSuggestedMember()
        {
            File.WriteAllText(sourceFilePath, @"struct A { int Foo; }; int main() { struct A a; a.Fo = 2; }");
            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            StringAssert.Contains(diags.First().Message, "did you mean 'Foo'?");
        }
예제 #59
0
        public void GetDiagnostics_LongLongCastToUInt32ForARM_OneDiagnosticsReported()
        {
            File.WriteAllText(sourceFilePath, @"int main() { typedef unsigned int uint32_t __attribute__((__mode__(SI))); uint32_t v = 0xABCDEFABCD; return 1; }");

            var adapter = new ClangAdapter(sourceFilePath, new List<string>(), new List<string>(), Language.C, Arch.ARM);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(1, diags.Count());
        }
예제 #60
0
 public void GetSkippedBlocks_NestedIfDefDirectiveWithOuterBlockSkipped_SkippedBlockIncludesEntireOuterBlock()
 {
     File.WriteAllText(sourceFilePath,
     @"#if 0
     #if 0
     #define foo x*y
     #elif 0
     #define foo x/y
     #else
     #define blah x-y
     #endif
     #define blah
     #endif
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     AssertSkippedBlocksMatch(adapter, new[] { Tuple.Create(2, 9)});
 }