comparison test/testc3.py @ 389:2ec730e45ea1

Added check for recursive struct
author Windel Bouwman
date Fri, 16 May 2014 12:29:31 +0200
parents c2ddc8a36f5e
children 6ae782a085e0
comparison
equal deleted inserted replaced
388:e07c2a9abac1 389:2ec730e45ea1
62 else: 62 else:
63 return [io.StringIO(snippet)] 63 return [io.StringIO(snippet)]
64 64
65 def expectErrors(self, snippet, rows): 65 def expectErrors(self, snippet, rows):
66 """ Helper to test for expected errors on rows """ 66 """ Helper to test for expected errors on rows """
67 ircode = list(self.builder.build([io.StringIO(snippet)])) 67 list(self.builder.build([io.StringIO(snippet)]))
68 actualErrors = [err.row for err in self.diag.diags] 68 actualErrors = [err.row for err in self.diag.diags]
69 if rows != actualErrors: 69 if rows != actualErrors:
70 self.diag.printErrors() 70 self.diag.printErrors()
71 self.assertSequenceEqual(rows, actualErrors) 71 self.assertSequenceEqual(rows, actualErrors)
72 # self.assertFalse(all(ircode)) 72 # self.assertFalse(all(ircode))
104 104
105 def testConstant(self): 105 def testConstant(self):
106 snip = """module C; 106 snip = """module C;
107 const int a = 2; 107 const int a = 2;
108 """ 108 """
109 i = self.expectOK(snip) 109 self.expectOK(snip)
110 110
111 @unittest.skip('Not checked yet') 111 @unittest.skip('Not checked yet')
112 def testConstantMutual(self): 112 def testConstantMutual(self):
113 snip = """module C; 113 snip = """module C;
114 const int a = b + 1; 114 const int a = b + 1;
116 function void f() 116 function void f()
117 { 117 {
118 return b; 118 return b;
119 } 119 }
120 """ 120 """
121 i = self.expectOK(snip) 121 self.expectOK(snip)
122 122
123 def testPackageNotExists(self): 123 def testPackageNotExists(self):
124 p1 = """module p1; 124 p1 = """module p1;
125 import p23; 125 import p23;
126 """ 126 """
504 *cast<gpio>(*a); 504 *cast<gpio>(*a);
505 } 505 }
506 """ 506 """
507 self.expectErrors(snippet, [7]) 507 self.expectErrors(snippet, [7])
508 508
509 def testLinkedList(self):
510 """
511 Test if a struct can contain a field with a pointer to itself
512 """
513 snippet = """
514 module testlinkedlist;
515
516 type struct {
517 int x;
518 list_t* next;
519 } list_t;
520
521 function void t()
522 {
523 var list_t* a;
524 a = a->next;
525 }
526 """
527 self.expectOK(snippet)
528
529 def testInfiniteStruct(self):
530 """
531 Test if a struct can contain a field with itself as type?
532 This should not be possible!
533 """
534 snippet = """
535 module testnestedstruct;
536
537 type struct {
538 int x;
539 list_t inner;
540 } list_t;
541
542 """
543 self.expectErrors(snippet, [0])
544
545 def testMutualStructs(self):
546 """
547 Test if two structs can contain each other!
548 This should not be possible!
549 """
550 snippet = """
551 module testnestedstruct;
552
553 type struct {
554 int x;
555 B other;
556 } A;
557
558 type struct {
559 int x;
560 A other;
561 } B;
562
563 """
564 self.expectErrors(snippet, [0])
565
509 def testComplexType(self): 566 def testComplexType(self):
510 snippet = """ 567 snippet = """
511 module testpointer; 568 module testpointer;
512 type int my_int; 569 type int my_int;
513 570