コード例 #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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        public void GetDiagnostics_EmptyCFile_NoDiagnosticsReturned()
        {
            File.WriteAllText(sourceFilePath, "");
            var adapter = new ClangAdapter(sourceFilePath);
            var diags   = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
コード例 #8
0
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangServices.cs プロジェクト: ted-ks/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        [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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
 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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: jizillon/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: AndyyKayy/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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
ファイル: ClangAdapterTests.cs プロジェクト: saaadhu/naggy
        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)});
 }