Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        public void GetDiagnostics_EmptyCFile_NoDiagnosticsReturned()
        {
            File.WriteAllText(sourceFilePath, "");
            var adapter = new ClangAdapter(sourceFilePath);
            var diags   = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
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());
        }
Exemplo n.º 7
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'?");
        }
Exemplo n.º 8
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());
        }
Exemplo n.º 9
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());
        }
Exemplo n.º 10
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());
        }
Exemplo n.º 11
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());
        }
Exemplo n.º 12
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());
        }
Exemplo n.º 13
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());
        }
Exemplo n.º 14
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);
            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);
        }
Exemplo n.º 15
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());
        }
Exemplo n.º 16
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);
        }
Exemplo n.º 17
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());
        }
Exemplo n.º 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());
        }
Exemplo n.º 19
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());
        }
Exemplo n.º 20
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);
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
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);
        }
Exemplo n.º 23
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());
        }
Exemplo n.º 24
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);
        }
Exemplo n.º 25
0
        public void GetDiagnostics_FunctionWithNoReturnType_WarningReported()
        {
            File.WriteAllText(sourceFilePath, @"func() { return 0; }");

            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);
        }
Exemplo n.º 26
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);
        }
Exemplo n.º 27
0
        public void GetDiagnostics_IntFunctionNotReturningAValue_DiagnosticDetailsAreCorrect()
        {
            File.WriteAllText(sourceFilePath, @"
/* Some source file */
int fun() {
}
");
            var adapter = new ClangAdapter(sourceFilePath);

            adapter.Process(null);
            var diag = adapter.GetDiagnostics().Single();

            Assert.AreEqual(sourceFilePath, diag.FilePath);
            Assert.AreEqual(4, diag.StartLine);
            Assert.AreEqual(1, diag.StartColumn);
        }
Exemplo n.º 28
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());
 }
Exemplo n.º 29
0
        public void GetDiagnostics_DestructorDefinedOutsideClassWithCppTurnedOn_NoDiagnosticsReturned()
        {
            File.WriteAllText(cppSourceFilePath,
                              @"class C { ~C(); };
                                C::~C() {}");
            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);
        }
Exemplo n.º 30
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);
        }
Exemplo n.º 31
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);
        }
Exemplo n.º 32
0
        public void GetDiagnostics_EmptyCFile_NoDiagnosticsReturned()
        {
            File.WriteAllText(sourceFilePath, "");
            var adapter = new ClangAdapter(sourceFilePath);
            adapter.Process(null);
            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(0, diags.Count);
        }
Exemplo n.º 33
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());
        }
Exemplo n.º 34
0
        public void GetDiagnostics_FunctionWithNoReturnType_WarningReported()
        {
            File.WriteAllText(sourceFilePath, @"func() { return 0; }");

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

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

            Assert.AreEqual(DiagnosticLevel.Warning, diag.Level);
        }
Exemplo n.º 35
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);
        }
Exemplo n.º 36
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);
        }
Exemplo n.º 37
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());
        }
Exemplo n.º 38
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);
        }
Exemplo n.º 39
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());
        }
Exemplo n.º 40
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());
        }
Exemplo n.º 41
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'?");
        }
Exemplo n.º 42
0
        public void GetDiagnostics_CppFileInDiskWithOneWarning_OneDiagnosticsReturned()
        {
            var sourceText =  "int func(){}";
            File.WriteAllText(cppSourceFilePath, sourceText);
            var adapter = new ClangAdapter(cppSourceFilePath, new List<string>(), new List<string>(), Language.Cpp);

            adapter.Process(null);

            var diags = adapter.GetDiagnostics();

            Assert.AreEqual(1, diags.Count);
        }
Exemplo n.º 43
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());
        }
Exemplo n.º 44
0
 public void GetDiagnostics_IntFunctionNotReturningAValue_DiagnosticDetailsAreCorrect()
 {
     File.WriteAllText(sourceFilePath, @"
     /* Some source file */
     int fun() {
     }
     ");
     var adapter = new ClangAdapter(sourceFilePath);
     adapter.Process(null);
     var diag = adapter.GetDiagnostics().Single();
     Assert.AreEqual(sourceFilePath, diag.FilePath);
     Assert.AreEqual(4, diag.StartLine);
     Assert.AreEqual(1, diag.StartColumn);
 }
Exemplo n.º 45
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());
        }
Exemplo n.º 46
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);
        }
Exemplo n.º 47
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);
        }