Best JavaScript code snippet using chai
ParserSuite.py
Source:ParserSuite.py
1import unittest2from TestUtils import TestParser3class ParserSuite(unittest.TestCase):4 def test_simple_program(self):5 """Simple program: int main() {} """6 input = """Var: x,y=1,z;"""7 expect = "successful"8 self.assertTrue(TestParser.checkParser(input,expect,201))9 10 def test_wrong_miss_close(self):11 """Miss variable"""12 input = """Var: ;"""13 expect = "Error on line 1 col 5: ;"14 self.assertTrue(TestParser.checkParser(input,expect,202))15 def test_simple_program1(self):16 input = """Function: foo Parameter:a,b,c Body: EndBody."""17 expect = "successful"18 self.assertTrue(TestParser.checkParser(input,expect,203))19 def test_simple_program2(self):20 input = """Function: foo21 Parameter:a,b,c22 Body:23 Var:x;24 d = 1; 25 EndBody."""26 expect = "successful"27 self.assertTrue(TestParser.checkParser(input,expect,204))28 def test_simple_program3(self):29 input = """ Function: foo30 Parameter:31 Body:32 If n == 0 Then33 Return 1;34 Else 35 c = a+b;36 EndIf.37 EndBody."""38 expect = "successful"39 self.assertTrue(TestParser.checkParser(input,expect,205))40 def test_simple_program4(self):41 input = """Function: main42 Parameter:43 Body:44 If 1 == 0.0 Then45 Return 1;46 EndIf.47 EndBody."""48 expect = "successful"49 self.assertTrue(TestParser.checkParser(input,expect,206))50 def test_simple_program5(self):51 input = """Function: foo52 Parameter:a,b,c53 Body:54 Var:x;55 If n == 0 Then56 Return 1;57 EndIf.58 EndBody."""59 expect = "successful"60 self.assertTrue(TestParser.checkParser(input,expect,207))61 #Test statements62 def test_if_stm(self):63 input = """ Function: main64 Parameter:65 Body:66 If e == 1 Then67 a = 2;68 Return a;69 EndIf.70 EndBody."""71 expect = "successful"72 self.assertTrue(TestParser.checkParser(input,expect,208))73 def test_wrong_if_stm(self):74 input = """ Function: main75 Parameter:76 Body:77 If e = 1 Then78 a = 2;79 Return a;80 EndIf.81 EndBody."""82 expect = "Error on line 4 col 33: ="83 self.assertTrue(TestParser.checkParser(input,expect,209))84 def test_if_stm1(self):85 input = """ Function: main86 Parameter:87 Body:88 If e == 1 Then89 a = 2;90 Return a;91 Else92 b = 2;93 Return 1;94 EndIf.95 EndBody."""96 expect = "successful"97 self.assertTrue(TestParser.checkParser(input,expect,210))98 def test_wrong_if_stm1(self):99 input = """ Function: main100 Parameter:101 Body: 102 If e == 1 Then103 a = 2;104 Return a;105 Else106 Return 1;107 EndBody."""108 expect = "Error on line 9 col 24: EndBody"109 self.assertTrue(TestParser.checkParser(input,expect,211))110 def test_logical_if_stm(self):111 input = """ Function: main112 Parameter:113 Body:114 If (e == 1) && f Then115 a = 2;116 Return a;117 ElseIf118 Return 1;119 EndIf.120 EndBody."""121 expect = "Error on line 8 col 32: Return"122 self.assertTrue(TestParser.checkParser(input,expect,212))123 def test_logical_if_stm1(self):124 input = """ Function: main125 Parameter:126 Body:127 If (e == 1) && f Then128 a = 2;129 Return a;130 ElseIf i < 2 Then131 a = 2;132 Return 1;133 EndIf.134 EndBody."""135 expect = "successful"136 self.assertTrue(TestParser.checkParser(input,expect,213))137 def test_for_stm(self):138 input = """Function: main139 Parameter:140 Body:141 For(i = 1, i < 10,1) Do142 printLn(i);143 EndFor.144 EndBody. """145 expect = "successful"146 self.assertTrue(TestParser.checkParser(input,expect,214))147 def test_for_stm1(self):148 input = """Function: main149 Parameter:150 Body:151 For(i = 1; i < 10,1) Do152 printLn(i);153 EndFor.154 EndBody. """155 expect = "Error on line 4 col 37: ;"156 self.assertTrue(TestParser.checkParser(input,expect,215))157 def test_for_stm2(self):158 input = """Function: main159 Parameter:160 Body:161 For(i = 1, i < 10,1 Do162 printLn(i);163 EndFor.164 EndBody. """165 expect = "Error on line 4 col 48: Do"166 self.assertTrue(TestParser.checkParser(input,expect,216))167 def test_for_stm3(self):168 input = """Function: main169 Parameter:170 Body:171 For(i = 1, i < 10,1)172 printLn(i);173 EndFor.174 EndBody. """175 expect = "Error on line 5 col 32: printLn"176 self.assertTrue(TestParser.checkParser(input,expect,217))177 def test_for_stm4(self):178 input = """Function: main179 Parameter:180 Body:181 For(i, i < 10,1)182 printLn(i);183 EndFor.184 EndBody. """185 expect = "Error on line 4 col 33: ,"186 self.assertTrue(TestParser.checkParser(input,expect,218))187 def test_for_stm5(self):188 input = """Function: main189 Parameter:190 Body:191 For()192 printLn(i);193 EndFor.194 EndBody. """195 expect = "Error on line 4 col 32: )"196 self.assertTrue(TestParser.checkParser(input,expect,219))197 def test_while_stm(self):198 input = """Function: main199 Parameter:200 Body:201 While i < 10 Do202 i = i+1;203 printLn(i);204 EndWhile.205 EndBody. """206 expect = "successful"207 self.assertTrue(TestParser.checkParser(input,expect,220))208 def test_while_stm1(self):209 input = """Function: main210 Parameter:211 Body:212 While Do213 i = i+1;214 printLn(i);215 EndWhile.216 EndBody. """217 expect = "Error on line 4 col 35: Do"218 self.assertTrue(TestParser.checkParser(input,expect,221))219 def test_while_stm2(self):220 input = """Function: main221 Parameter:222 Body:223 While i < 1224 i = i+1;225 printLn(i);226 EndWhile.227 EndBody. """228 expect = "Error on line 5 col 32: i"229 self.assertTrue(TestParser.checkParser(input,expect,222))230 def test_while_stm3(self):231 input = """Function: main232 Parameter:233 Body:234 While i < 1 Do235 i = i+1;236 printLn(i);237 EndWhile238 EndBody. """239 expect = "Error on line 8 col 24: EndBody"240 self.assertTrue(TestParser.checkParser(input,expect,223))241 def test_do_while_stm(self):242 input = """Function: main243 Parameter:244 Body:245 Do246 i = i+1;247 While i < 10248 EndDo.249 EndBody. """250 expect = "successful"251 self.assertTrue(TestParser.checkParser(input,expect,224))252 def test_do_while_stm1(self):253 input = """Function: main254 Parameter:255 Body:256 Do:257 i = i+1;258 While i < 10259 EndDo.260 EndBody. """261 expect = "Error on line 4 col 30: :"262 self.assertTrue(TestParser.checkParser(input,expect,225))263 def test_do_while_stm2(self):264 input = """Function: main265 Parameter:266 Body:267 Do268 i = i+1;269 While270 EndDo.271 EndBody. """272 expect = "Error on line 7 col 28: EndDo"273 self.assertTrue(TestParser.checkParser(input,expect,226))274 def test_do_while_stm3(self):275 input = """Function: main276 Parameter:277 Body:278 Do279 i = i+1;280 While i < 10281 EndDo282 EndBody. """283 expect = "Error on line 8 col 24: EndBody"284 self.assertTrue(TestParser.checkParser(input,expect,227))285 def test_break_stm(self):286 input = """Function: main287 Parameter:288 Body:289 Break;290 EndBody. """291 expect = "successful"292 self.assertTrue(TestParser.checkParser(input,expect,228))293 def test_break_stm1(self):294 input = """Function: main295 Parameter:296 Body:297 Break298 EndBody. """299 expect = "Error on line 5 col 24: EndBody"300 self.assertTrue(TestParser.checkParser(input,expect,229))301 def test_continue_stm(self):302 input = """Function: main303 Parameter:304 Body:305 Continue;306 EndBody. """307 expect = "successful"308 self.assertTrue(TestParser.checkParser(input,expect,230))309 def test_continue_stm1(self):310 input = """Function: main311 Parameter:312 Body:313 Continue314 EndBody. """315 expect = "Error on line 5 col 24: EndBody"316 self.assertTrue(TestParser.checkParser(input,expect,231))317 def test_call_func_stm(self):318 input = """ Function: foo 319 Parameter:a[1]320 Body:321 b = a[1+2];322 a[i+2] = (1+3)+4;323 a = fooo(30)+b+c;324 a = 0[10];325 EndBody."""326 expect = "successful"327 self.assertTrue(TestParser.checkParser(input,expect,232))328 def test_call_func_stm1(self):329 input = """ Function: foo 330 Parameter:a[1]331 Body:332 b = a[1+2];333 a[i+2] = (1+3)+4;334 foo(30)335 a = 0[10];336 EndBody."""337 expect = "Error on line 7 col 28: a"338 self.assertTrue(TestParser.checkParser(input,expect,233))339 def test_call_func_stm2(self):340 input = """ Function: foo 341 Parameter:a[1]342 Body:343 b = a[1+2];344 a[i+2] = (1+3)+4;345 a = foo(30;346 a = 0[10];347 EndBody."""348 expect = "Error on line 6 col 38: ;"349 self.assertTrue(TestParser.checkParser(input,expect,234))350 def test_call_func_stm3(self):351 input = """ Function: foo 352 Parameter:a[1]353 Body:354 b = a[1+2];355 a[i+2] = (1+3)+4;356 a = foo(,,,,);357 a = 0[10];358 EndBody."""359 expect = "Error on line 6 col 36: ,"360 self.assertTrue(TestParser.checkParser(input,expect,235))361 def test_call_func_stm4(self):362 input = """ Function: foo 363 Parameter:a[1]364 Body:365 a = True;366 foo(True,12,"abc",12.0,12e1,12.,000.e-1);367 EndBody."""368 expect = "successful"369 self.assertTrue(TestParser.checkParser(input,expect,236))370 def test_call_func_stm5(self):371 input = """ Function: foo 372 Parameter:a[1]373 Body:374 a = True;375 foo(a == 1,a < 2,"abc" > 12.0,b >. d,e <.f,1==3,12e4 != 5,000.e-1 <=0, 12.1 >= 8, 1.0 =/=2);376 EndBody."""377 expect = "successful"378 self.assertTrue(TestParser.checkParser(input,expect,237))379 def test_assign_stm(self):380 input = """ Function: foo 381 Parameter:a[1]382 Body:383 Var: a[1],b,c,x,y,z;384 a[1] = {True,False,12,0x12A,0X12B,0o123,0.12,12.,1e-1,1.e12,"abc","asd"};385 b = a[a[b[c[d[e[g[f[h[1]]]]]]]]];386 c = a[12][b[12]][d[c[e[123]]]];387 x = (1+.2)*(3+8)-(2\\10)*a[12]+7-a;388 y = !!!!!!!!!!!!!!!!!!!!!!a[1];389 z = (1%2*(3+4*(6-.2\\(4*(2*1)+.3))));390 EndBody."""391 expect = "successful"392 self.assertTrue(TestParser.checkParser(input,expect,238))393 def test_assign_stm1(self):394 input = """ Function: foo 395 Parameter:a[1]396 Body:397 Var: a[1],b,c,x,y,z;398 a[1] == {True,False,12,0x12A,0X12B,0o123,0.12,12.,1e-1,1.e12,"abc","asd"};399 b = a[a[b[c[d[e[g[f[h[1]]]]]]]]];400 c = a[12][b[12]][d[c[e[123]]]];401 x = (1+.2)*(3+8)-(2\\10)*a[12]+7-a;402 y = !!!!!!!!!!!!!!!!!!!!!!a[1];403 z = (1%2*(3+4*(6-.2\\(4*(2*1)+.3))));404 EndBody."""405 expect = "Error on line 5 col 33: =="406 self.assertTrue(TestParser.checkParser(input,expect,239))407 #Test Expression408 def test_exp(self):409 input = """ Function: foo 410 Parameter:a[1]411 Body:412 Var: a[1],b,c,x,y,z;413 a[1] = {True,False,12,0x12A,0X12B,0o123,0.12,12.,1e-1,1.e12,"abc","asd"};414 b = a[a[b[c[d[e[g[f[h[1]]]]]]]]];415 c = a[12][b[12]][d[c[e[123]]]];416 x = (1+.2)*(3+8)-(2\\10)*a[12]+7-a;417 y = !!!!!!!!!!!!!!!!!!!!!!a[1];418 z = (1%2*(3+4*(6-.2\\(4*(2*1)+.3))));419 EndBody."""420 expect = "successful"421 self.assertTrue(TestParser.checkParser(input,expect,239))422 def test_exp1(self):423 input = """ Function: foo 424 Parameter:a[1]425 Body:426 Var: a[1],b,c,x,y,z;427 a[1] = (a>b)&&(c<d);428 b = (c >= d) && (e >. g);429 c = ((c>=d) && e) >. g;430 x = !(((c > 1)&&c)||d);431 EndBody."""432 expect = "successful"433 self.assertTrue(TestParser.checkParser(input,expect,241))434 def test_exp2(self):435 input = """ Function: foo 436 Parameter:a[1]437 Body:438 Var: a[1],b,c,x,y,z;439 a[1] = (a>b)&&(c<d);440 b = c >= d && e >. g;441 c = ((c>=d) && e) >. g;442 x = !(((c > 1)&&c)||d);443 EndBody."""444 expect = "Error on line 6 col 44: >."445 self.assertTrue(TestParser.checkParser(input,expect,242))446 def test_exp3(self):447 input = """ Function: foo 448 Parameter:a[1]449 Body:450 Var: a[1],b,c,x,y,z;451 a[1] = (a>b)&&(c<d);452 b = (c >= d) && e >. g;453 c = ((c>=d) && e) >. g;454 x = !(((c > 1)&&c)||d);455 EndBody."""456 expect = "successful"457 self.assertTrue(TestParser.checkParser(input,expect,243))458 #Test mix459 def test_mix1(self):460 input = """461 Var: x = -1;462 Function: foo 463 Parameter:a[1]464 Body:465 EndBody."""466 expect = "Error on line 2 col 29: -"467 self.assertTrue(TestParser.checkParser(input,expect,244))468 def test_mix2(self):469 input = """ Var: x = 1;470 Function: foo 471 Parameter:a[1]472 Body:473 EndBody.474 Var: y = 2;"""475 expect = "Error on line 6 col 20: Var"476 self.assertTrue(TestParser.checkParser(input,expect,245))477 def test_mix3(self):478 input = """ Var: x = 1;479 Function: foo 480 Parameter:a[1]481 Body:482 Var: x,y;483 Var:z;484 If n == 0 Then485 Var:z;486 ElseIf n == 0 Then487 Var:a;488 Else489 Var:b;490 EndIf.491 EndBody."""492 expect = "successful"493 self.assertTrue(TestParser.checkParser(input,expect,246))494 def test_mix4(self):495 input = """ Var: x = 1;496 Var: y,z = 2,3;497 Function: foo 498 Parameter:a[1]499 Body:500 Var: x,y;501 Var:z;502 If n == 0 Then503 Var:z;504 ElseIf n == 0 Then505 Var:a;506 Else507 Var:b;508 EndIf.509 EndBody."""510 expect = "successful"511 self.assertTrue(TestParser.checkParser(input,expect,247))512 def test_mix5(self):513 input = """ Var: x = 1;514 Var: y,z = 2,3;515 """516 expect = "successful"517 self.assertTrue(TestParser.checkParser(input,expect,248))518 def test_mix6(self):519 input = """ Var: x = 1;520 Var: y,z = 2,3;521 Function: foo 522 Parameter:a[1],a,b,c523 Body:524 Var: x,y;525 Var:z;526 If n == 0 Then527 Var:z;528 ElseIf n == 0 Then529 Var:a;530 Else531 Var:b;532 EndIf.533 Var: d,f;534 EndBody.535 """536 expect = "Error on line 15 col 28: Var"537 self.assertTrue(TestParser.checkParser(input,expect,249))538 def test_mix7(self):539 input = """ Var: x = 1;540 Var: y,z = 2,3;541 Function: foo 542 Parameter:a[1],a,b,c543 Body:544 Var: x,y;545 Var:z;546 If n == 0 Then547 Var:z;548 Var:b;549 ElseIf n == 0 Then550 Var:a;551 a = 1;552 Var: x = 9;553 Else554 Var:b;555 EndIf.556 EndBody.557 """558 expect = "Error on line 14 col 32: Var"559 self.assertTrue(TestParser.checkParser(input,expect,250))560 def test_mix8(self):561 input = """ Var: x = 1;562 Var: y,z = 2,3;563 Function: foo 564 Parameter:a[1],a,b,c565 Body:566 Var: x,y;567 Var:z;568 If n == 0 Then569 Var:z;570 Var:b;571 ElseIf n == 0 Then572 Var:a;573 a = 1;574 Else575 Var:b;576 EndIf.577 For (i = 0, i < 10,i+1) Do578 Var: x = 1;579 printLn();580 EndFor.581 EndBody.582 """583 expect = "successful"584 self.assertTrue(TestParser.checkParser(input,expect,251))585 def test_mix9(self):586 input = """ Var: x = 1;587 Var: y,z = 2,3;588 Function: foo 589 Parameter:a[1],a,b,c590 Body:591 Var: x,y;592 Var:z;593 For (i = 0, i < 10,i+1) Do594 Var: x = 1;595 printLn();596 Var: a,b;597 EndFor.598 EndBody.599 """600 expect = "Error on line 11 col 32: Var"601 self.assertTrue(TestParser.checkParser(input,expect,252))602 def test_mix10(self):603 input = """ Var: x = 1;604 Var: y,z = 2,3;605 Function: foo 606 Parameter:a[1],a,b,c607 Body:608 Var: x,y;609 Var:z;610 Do 611 Var: x,y;612 x = x+1;613 y = y+1;614 While (x < 10)&&(y<5)615 EndDo.616 EndBody.617 """618 expect = "successful"619 self.assertTrue(TestParser.checkParser(input,expect,253))620 def test_mix11(self):621 input = """ Var: x = 1;622 Var: y,z = 2,3;623 Function: foo 624 Parameter:a[1],a,b,c625 Body:626 Var: x,y;627 Var:z;628 Do 629 Var: x,y;630 x = x+1;631 y = y+1;632 While (x < 10)&&(y<5)633 EndDo.634 EndBody.635 """636 expect = "successful"637 self.assertTrue(TestParser.checkParser(input,expect,253))638 def test_mix12(self):639 input = """ Var: x = 1;640 Var: y,z = 2,3;641 Function: foo 642 Parameter:a[1],a,b,c643 Body:644 Var: x,y;645 Var:z;646 While i < 10 Do647 Var: x,y;648 x = x+1;649 y = y+1;650 Var:a;651 While (x < 10)&&(y<5)652 EndDo.653 EndBody.654 """655 expect = "Error on line 12 col 32: Var"656 self.assertTrue(TestParser.checkParser(input,expect,254))657 def test_mix12(self):658 input = """ Var: x = 1;659 Var: y,z = 2,3;660 Function: foo 661 Parameter:a[1],a,b,c662 Body:663 Var: x,y;664 Var:z;665 While i < 10 Do666 Var: x,y;667 x = x+1;668 y = y+1;669 EndWhile.670 EndBody.671 """672 expect = "successful"673 self.assertTrue(TestParser.checkParser(input,expect,255))674 def test_mix13(self):675 input = """ Var: x = 1;676 Var: y,z = 2,3;677 Function: foo 678 Parameter:a[1],a,b,c679 Body:680 Var: x,y;681 Var:z;682 While i < 10 Do683 Var: x,y;684 x = x+1;685 y = y+1;686 Var:a;687 EndWhile.688 EndBody.689 """690 expect = "Error on line 12 col 32: Var"691 self.assertTrue(TestParser.checkParser(input,expect,256))692 def test_mix14(self):693 input = """ Var: x = 1;694 Var: y,z = 2,3;695 Function: foo 696 Parameter:a[1],a,b,c697 Body:698 Var: x,y;699 Var:z;700 While i < 10 Do701 Var: x,y;702 x = x+1;703 y = y+1;704 EndWhile.705 EndBody.706 Function: facb707 Parameter: a,b,c708 Body:709 Var: x,y;710 foo(c,b,a);711 Return 1;712 EndBody.713 """714 expect = "successful"715 self.assertTrue(TestParser.checkParser(input,expect,257)) 716 def test_mix15(self):717 input = """ Var: x = 1;718 Var: y,z = 2,3;719 Function: foo 720 Parameter:a[1],a,b,c721 Body:722 Var: x,y;723 Var:z;724 While i < 10 Do725 Var: x,y;726 x = x+1;727 y = y+1;728 EndWhile.729 EndBody.730 Function: facb731 Parameter: a,b,c732 Body:733 Var: x,y;734 foo(c,b,a);735 Return 1;736 EndBody.737 Function: main738 Parameter:739 Body:740 foo(1,2,3);741 facb(4,5,6);742 EndBody.743 """744 expect = "successful"745 self.assertTrue(TestParser.checkParser(input,expect,258))746 def test_mix16(self):747 input = """ Var: x = 1;748 Var: y,z = 2,3;749 Function: foo 750 Parameter:a[1],a,b,c751 Body:752 Var: x,y;753 Var:z;754 While i < 10 Do755 Var: x,y;756 x = x+1;757 y = y+1;758 EndWhile.759 EndBody.760 Function: facb761 Parameter: a,b,c762 Body:763 Var: x,y;764 foo(c,b,a);765 Return 1;766 EndBody.767 Function: main768 Parameter:769 Body:770 foo(1,2,3);771 facb(\n,1,2);772 EndBody.773 """774 expect = "Error on line 26 col 0: ,"775 self.assertTrue(TestParser.checkParser(input,expect,259))776 def test_mix17(self):777 input = """ Var: x = 1;778 Var: y,z = 2,3;779 Function: foo 780 Parameter:a[1],a,b,c781 Body:782 ** This is a comment783 *aa784 v785 c786 **787 Var: x,y;788 Var:z;789 While i < 10 Do790 Var: x,y;791 x = x+1;792 y = y+1;793 EndWhile.794 EndBody.795 Function: facb796 Parameter: a,b,c797 Body:798 Var: x,y;799 foo(c,b,a);800 Return 1;801 EndBody.802 Function: main803 Parameter:804 Body:805 foo(1,2,3);806 facb(a,1,2);807 EndBody.808 """809 expect = "successful"810 self.assertTrue(TestParser.checkParser(input,expect,260))811 def test_mix18(self):812 input = """ Var: x = 1;813 Var: y,z = 2,3;814 Function: foo 815 Parameter:a[1],a,b,c816 Body:817 Var: x,y;818 Var:z;819 While i < 10 Do820 Var: x,y;821 x = x+1;822 y = y+1;823 If a == 0 Then824 Var: b;825 x = x*2;826 EndIf.827 EndWhile.828 EndBody.829 Function: facb830 Parameter: a,b,c831 Body:832 Var: x,y;833 foo(c,b,a);834 Return 1;835 EndBody.836 Function: main837 Parameter:838 Body:839 foo(1,2,3);840 facb(a,1,2);841 EndBody.842 """843 expect = "successful"844 self.assertTrue(TestParser.checkParser(input,expect,261))845 def test_mix19(self):846 input = """ Var: x = 1;847 Var: y,z = 2,3;848 Function: foo 849 Parameter:a[1],a,b,c850 Body:851 Body:852 EndBody.853 EndBody.854 Function: main855 Parameter:856 Body:857 foo(1,2,3);858 facb(a,1,2);859 EndBody.860 """861 expect = "Error on line 6 col 28: Body"862 self.assertTrue(TestParser.checkParser(input,expect,262))863 def test_mix20(self):864 input = """ Var: x = 1;865 Var: y,z = 2,3;866 Function: foo 867 Parameter:a[1],a,b,c868 Body:869 Function: abc870 Parameter: x,y,z871 Body:872 EndBody.873 EndBody.874 Function: main875 Parameter:876 Body:877 foo(1,2,3);878 facb(a,1,2);879 EndBody.880 """881 expect = "Error on line 6 col 24: Function"882 self.assertTrue(TestParser.checkParser(input,expect,263))883 def test_mix21(self):884 input = """ Var: x = 1;885 Var: y,z = 2,3;886 Function: foo 887 Parameter:a[1],a,b,c888 Body:889 If n == 10 Then890 For(i = 1, i < 9, 1) Do891 While i < 0 Do892 Do 893 Var: a;894 a = a+1;895 If a < 50 Then 896 Continue;897 ElseIf a > 50 Then898 Break;899 Else900 Return 0;901 EndIf.902 While a < 100903 EndDo.904 EndWhile.905 EndFor.906 EndIf.907 EndBody.908 Function: main909 Parameter:910 Body:911 foo(1,2,3);912 facb(a,1,2);913 EndBody.914 """915 expect = "successful"916 self.assertTrue(TestParser.checkParser(input,expect,264))917 def test_mix22(self):918 input = """ Var: x = 1;919 Var: y,z = 2,3;920 Function: foo 921 Parameter:a[1],a,b,c922 Body:923 Var: i = 2;924 While i < 10 Do925 i = i + 1;926 Do927 i = i + 2;928 While i < 7929 EndDo.930 Return 1;931 EndWhile. 932 EndBody.933 Function: main934 Parameter:935 Body:936 foo(1,2,3);937 facb(a,1,2);938 EndBody.939 """940 expect = "successful"941 self.assertTrue(TestParser.checkParser(input,expect,265))942 def test_mix23(self):943 input = """ Var: x = 1;944 Var: y,z = 2,3;945 Function: foo 946 Parameter:a[1],a,b,c947 Body:948 Var: i = 1;949 While i < 0 Do950 i = i + 1;951 While i > 10 Do952 a = a + 1;953 While i < 10954 EndDo.955 EndWhile.956 EndWhile.957 EndBody.958 Function: main959 Parameter:960 Body:961 foo(1,2,3);962 facb(a,1,2);963 EndBody.964 """965 expect = "Error on line 11 col 32: While"966 self.assertTrue(TestParser.checkParser(input,expect,266))967 def test_mix24(self):968 input = """ Var: x = 1;969 Var: y,z = 2,3;970 Function: foo 971 Parameter:a[1],a,b,c972 Body:973 foo[123);974 EndBody.975 Function: main976 Parameter:977 Body:978 foo(1,2,3);979 facb(a,1,2);980 EndBody.981 """982 expect = "Error on line 6 col 35: )"983 self.assertTrue(TestParser.checkParser(input,expect,267))984 def test_mix25(self):985 input = """ Var: x = 1;986 Var: y,z = 2,3;987 Function: foo 988 Parameter:a,b,c989 Body:990 a = c()+d()+f();991 Return a;992 EndBody.993 Function: main994 Parameter:995 Body:996 foo(1,2,3);997 EndBody.998 """999 expect = "successful"1000 self.assertTrue(TestParser.checkParser(input,expect,268))1001 def test_mix26(self):1002 input = """ Var: x = 1;1003 Var: y,z = 2,3;1004 Function: foo 1005 Parameter:a,b1006 Body:1007 a = c()+d()+f();1008 For( i = a(),i < b(),c()) Do1009 Return d();1010 EndFor.1011 Return a;1012 EndBody.1013 Function: main1014 Parameter:1015 Body:1016 foo(1,2,3);1017 EndBody.1018 """1019 expect = "successful"1020 self.assertTrue(TestParser.checkParser(input,expect,269))1021 def test_mix27(self):1022 input = """ Var: x = 1;1023 Var: y,z = 2,3;1024 Function: foo 1025 Parameter:a = c(),b1026 Body:1027 a = c()+d()+f();1028 For( i = a(),i < b(),c()) Do1029 Return d();1030 EndFor.1031 Return a;1032 EndBody.1033 Function: main1034 Parameter:1035 Body:1036 foo(1,2,3);1037 EndBody.1038 """1039 expect = "Error on line 4 col 36: ="1040 self.assertTrue(TestParser.checkParser(input,expect,270))1041 def test_mix28(self):1042 input = """ Var: x = 1;1043 Var: y,z = 2,3;1044 Function: foo 1045 Parameter:a,b1046 Body:1047 a = c()+d()+f();1048 b = (c(d(e(f(g(1))))));1049 For( i = a(),i < b(),c()) Do1050 Return d();1051 EndFor.1052 Return a;1053 EndBody.1054 Function: main1055 Parameter:1056 Body:1057 foo(1,2,3);1058 EndBody.1059 """1060 expect = "successful"1061 self.assertTrue(TestParser.checkParser(input,expect,271))1062 def test_mix29(self):1063 input = """ Var: x = 1;1064 Var: y,z = 2,3;1065 Function: foo 1066 Parameter:a,b1067 Body:1068 a = c()+d()+f();1069 ** Cmt ** 1070 b = (c(d(e(f(g(1-2)*3)\\4)%5)+6));1071 For( i = a(),i < b(),c()) Do1072 Return d();1073 EndFor.1074 Return a;1075 EndBody.1076 Function: main1077 Parameter:1078 Body:1079 foo(1,2,3);1080 EndBody.1081 """1082 expect = "successful"1083 self.assertTrue(TestParser.checkParser(input,expect,272))1084 def test_mix30(self):1085 input = """ Var: x = 1;1086 Var: y,z = 2,3;1087 Function: foo 1088 Parameter:a,b1089 Body:1090 a = c()+d()+f();1091 ** Cmt \r\b\t\f\n** 1092 b = (c(d(e(f(g(1-2)*3)\\4)%5)+6));1093 For( i = a(****),i < b(**Cmt \r\b\t\f\n**),c()) Do1094 Return d();1095 EndFor.1096 Return a;1097 EndBody.1098 Function: main1099 Parameter:1100 Body:1101 foo(1,2,3);1102 EndBody.1103 """1104 expect = "successful"1105 self.assertTrue(TestParser.checkParser(input,expect,273))1106 def test_mix31(self):1107 input = """ Var: x = 1;1108 Var: y,z = 2,3;1109 Function: foo 1110 Parameter:a,b1111 Body:1112 a = c()+d()+f();1113 ** Cmt \r\b\t\f\n** 1114 b = (c(d(e(f(g(1-2)*3)\\4)%5)+6));1115 For( i = a(****),i < b(**Cmt \r\b\t\f\n**),c("'"'"")) Do1116 Return d();1117 EndFor.1118 Return a;1119 EndBody.1120 Function: main1121 Parameter:1122 Body:1123 foo(1,2,3);1124 EndBody.1125 """1126 expect = "successful"1127 self.assertTrue(TestParser.checkParser(input,expect,274))1128 def test_mix32(self):1129 input = """ Var: x = 1;1130 Var: y,z = 2,3;1131 Function: foo 1132 Parameter:a,b1133 Body:1134 a = c()+d()+f();1135 ** Cmt \r\b\t\f\n** 1136 b = (c(d(e(f(g(1-2)*3)\\4)%5)+6));1137 For( i = a(****),i < b(****),c("'"")"'"") Do1138 Return d();1139 EndFor.1140 Return a;1141 EndBody.1142 Function: main1143 Parameter:1144 Body:1145 foo(1,2,3);1146 EndBody.1147 """1148 expect = r'''Error on line 10 col 64: '"'''1149 self.assertTrue(TestParser.checkParser(input,expect,275))1150 def test_mix33(self):1151 input = """ Var: x = 1;1152 Var: y,z = 2,3;1153 Function: foo 1154 Parameter:a,b1155 Body:1156 a = c()+d()+f();1157 ** Cmt \r\b\t\f\n** 1158 b = (c(d(e(f(g(1-2)*3)\\4)%5)+6));1159 While ((i + 5) >=. 7)&&(9-(8*9\\.9) +. 6)||(7-.4%5+9*.6) Do1160 printLn("Goodbye world");1161 EndWhile.1162 Return a;1163 EndBody.1164 Function: main1165 Parameter:1166 Body:1167 foo(1,2,3);1168 EndBody.1169 """1170 expect = "successful"1171 self.assertTrue(TestParser.checkParser(input,expect,276))1172 def test_mix34(self):1173 input = """ Var: x = 1;1174 Var: y,z = 2,3;1175 Function: foo 1176 Parameter:a,b1177 Body:1178 a = c()+d()+f();1179 ** Cmt \r\b\t\f\n** 1180 b = (c(d(e(f(g(1-2)*3)\\4)%5)+6));1181 While a[{5}] Do 1182 printLn("Goodbye world");1183 EndWhile.1184 Return a;1185 EndBody.1186 Function: main1187 Parameter:1188 Body:1189 foo(1,2,3);1190 EndBody.1191 """ ######################################33331192 expect = "successful"1193 self.assertTrue(TestParser.checkParser(input,expect,277))1194 def test_mix35(self):1195 input = """ Var: x = 1;1196 Var: y,z[12.0] = 2,3;1197 Function: main1198 Parameter:1199 Body:1200 foo(1,2,3,print("abc"));1201 EndBody.1202 """1203 expect = "Error on line 2 col 29: 12.0"1204 self.assertTrue(TestParser.checkParser(input,expect,278))1205 def test_mix36(self):1206 input = """ Var: x = 1;1207 Var: y,z[12][1][1234567890000] = 2,3;1208 Function: main1209 Parameter:1210 Body:1211 foo(1[0x1245ABCDF],a(0o1234567),True);1212 EndBody.1213 """1214 expect = "successful"1215 self.assertTrue(TestParser.checkParser(input,expect,279))1216 def test_mix37(self):1217 input = """ Var: x = 1;1218 Var: y,z[12][1][1234567890000] = 2,3;1219 Function: main1220 Parameter:1221 Body:1222 Var: x,a = 1,"a";1223 a = !!!!!!!!!x;1224 a = x!!!!!!!!;1225 foo(a,a(0o1234567),True);1226 EndBody.1227 """1228 expect = "Error on line 8 col 33: !"1229 self.assertTrue(TestParser.checkParser(input,expect,280))1230 def test_mix38(self):1231 input = """ Var: x = 1;1232 Var: y,z[12][1][1234567890000] = 2,3;1233 Function: main1234 Parameter:1235 Body:1236 Var: x,a = 1,"a";1237 a = !!!!!!!!!x;1238 a = (a&&(&&b));1239 foo(a,a(0o1234567),True);1240 EndBody.1241 """1242 expect = "Error on line 8 col 37: &&"1243 self.assertTrue(TestParser.checkParser(input,expect,281))1244 def test_mix39(self):1245 input = """ Var: x = 1;1246 Var: y,z[12][1][1234567890000] = 2,3;1247 Function: main1248 Parameter:1249 Body:1250 While (i-.(1&&(4||2)))=/=5>=.7 Do1251 printLn(1);1252 Continue;1253 EndWhile.1254 EndBody.1255 """1256 expect = "Error on line 6 col 54: >=."1257 self.assertTrue(TestParser.checkParser(input,expect,282))1258 def test_mix40(self):1259 input = """ Var: x = 1;1260 Var: y,z[12][1][1234567890000] = 2,3;1261 Function: main1262 Parameter:1263 Body:1264 While ((i-.(1&&(4||2)))=/=5)>=.7-. Do1265 printLn(1);1266 Continue;1267 EndWhile.1268 EndBody.1269 """1270 expect = "Error on line 6 col 63: Do"1271 self.assertTrue(TestParser.checkParser(input,expect,283))1272 def test_mix41(self):1273 input = """ Var: x = 1;1274 Var: y,z[12][1][1234567890000] = 2,3;1275 Function: main1276 Parameter:1277 Body:1278 While ((i-.(1&&(4||2)))=/=5)>=.7&& foo() Do1279 printLn(1);1280 Continue;1281 EndWhile.1282 EndBody.1283 """1284 expect = "successful"1285 self.assertTrue(TestParser.checkParser(input,expect,284))1286 def test_mix42(self):1287 input = """ Var: x = 1;1288 Var: y,z[12][1][1234567890000] = 2,3;1289 Function: main1290 Parameter:1291 Body:1292 While ((i-.(1&&(4||2)))=/=5)>=.7&& foo() Do1293 printLn(1);1294 Continue;1295 If (n_123_ACV____ == 1e12123) || a[[[[[[["a"]]]]]]] Then1296 EndIf.1297 EndWhile.1298 EndBody.1299 """1300 expect = "Error on line 9 col 67: ["1301 self.assertTrue(TestParser.checkParser(input,expect,285))1302 def test_mix43(self):1303 input = """ Function: main1304 Parameter:1305 Body:1306 foo((1+2*(3-0x1\\(12.0 -. 0o1236*(True+"abc"\\.(**This is cmt***.12e1))))),2,3);1307 EndBody.1308 """1309 expect = "Error on line 4 col 89: *."1310 self.assertTrue(TestParser.checkParser(input,expect,286))1311 def test_mix44(self):1312 input = """ Var: x = 1;1313 Var: y,z = 2,3;1314 Function: foo 1315 Parameter:a[0x123ABC][0o12345],a,b,c1316 Body:1317 Var: x,y;1318 Var:z;1319 Do1320 Var: x,y;1321 x = x+1 + ** Error here??** 1;1322 While !!!!(x < 0x123A)!!!! 1323 EndDo.1324 EndBody.1325 """1326 expect = "Error on line 11 col 50: !"1327 self.assertTrue(TestParser.checkParser(input,expect,287))1328 def test_mix45(self):1329 input = """ Var: x = 1;1330 Var: y,z = 2,3;1331 Function: foo 1332 Parameter:a[0x123ABC][0o12345],a,b,c1333 Body:1334 Var: x,y;1335 Var:z;1336 Do1337 Var: x,y;1338 x = x+1 + ** Error here?? \b\r\f\n\t\'\\** 1;1339 y = y+1 + **This is cmnt? Right,hihi**"abc"+True ;1340 While !!!!(x < 0x123A-.) 1341 EndDo.1342 EndBody.1343 """1344 expect = "Error on line 13 col 51: )"1345 self.assertTrue(TestParser.checkParser(input,expect,288))1346 def test_mix46(self):1347 input = """ Function: main 1348 Parameter:a[0x123ABC][0o12345],a,b,c1349 Body:1350 printLn(1234,0xAAA,{{{{12,34}}}},a[1][2][3][4.0+0x123]);1351 print("Goodbye world","Happy Women Day");1352 EndBody.1353 """1354 expect = "successful"1355 self.assertTrue(TestParser.checkParser(input,expect,289))1356 def test_mix47(self):1357 input = """ Function: main 1358 Parameter:a[0x123ABC][0o12345],a,b,c1359 Body:1360 int_of_float(12);1361 float_to_int(12.0);1362 int_of_string(12);1363 string_of_int("12");1364 float_of_string(12.1);1365 string_of_float("12.0");1366 EndBody.1367 """1368 expect = "successful"1369 self.assertTrue(TestParser.checkParser(input,expect,290))1370 def test_mix48(self):1371 input = """ Function: main 1372 Parameter:a[0x123ABC][0o12345],a,b,c1373 Var: x = 1;1374 Body:1375 **Goodbye world**1376 EndBody.1377 """1378 expect = "Error on line 3 col 24: Var"1379 self.assertTrue(TestParser.checkParser(input,expect,291))1380 def test_mix49(self):1381 input = """ Function: main 1382 Parameter:a[0x123ABC][0o12345],a,b,c1383 Body:1384 x[{1,2}+True\\.False =/= {True,"False"}*.12e1] = 1;1385 EndBody.1386 """1387 expect = "successful"1388 self.assertTrue(TestParser.checkParser(input,expect,292))1389 def test_mix50(self):1390 input = """ Function: main 1391 Parameter:a[0x123ABC][0o12345],a,b,c1392 Body:1393 x[({1,2}+True\\.False) =/= ({True,"False"}*.12e1) **People!!! This is a comment, Okey**] = 1;1394 EndBody.1395 """1396 expect = "successful"1397 self.assertTrue(TestParser.checkParser(input,expect,293))1398 def test_mix51(self):1399 input = """ Function: main 1400 Parameter:a[0x123ABC][0o12345],a,b,c1401 Body:1402 x[({{1,2},{True\\.False}}) =/= ({True,"False"}*.12e1) **People!!! This is a comment, Okey**] = 1;1403 EndBody.1404 """1405 expect = "Error on line 4 col 43: \."1406 self.assertTrue(TestParser.checkParser(input,expect,294))1407 def test_mix52(self):1408 input = """ Var: x = 1;1409 Var: y,z = 2,3;1410 Function: foo 1411 Parameter:a[0x123ABC][0o12345],a,b,c1412 Body:1413 Var: x,y;1414 Var:z;1415 Do1416 Var: x,y;1417 x = x+1 + ** Error here?? \b\r\f\n\t\'\\** 1;1418 y = y+1 + **This is cmnt? Right,hihi**"abc"+True ;1419 While a[!!(x < 0x123A)][!!(1-1.0)b[15]] 1420 EndDo.1421 EndBody.1422 """1423 expect = "Error on line 13 col 61: b"1424 self.assertTrue(TestParser.checkParser(input,expect,295))1425 def test_mix53(self):1426 input = """ Var: x = 1;1427 Var: y,z = 2,3;1428 Function: foo 1429 Parameter:a[0x123ABC][0o12345],a,b,c1430 Body:1431 Var: x,y;1432 Var:z;1433 Do1434 Var: x,y;1435 x = x+1 + ** Error here?? \b\r\f\n\t\'\\** 1;1436 y = y+1 + **This is cmnt? Right,hihi**"abc"+True ;1437 While a[!!(x < 0x123A)][!!(1-1.0)*b[15]] 1438 EndDo.1439 Do1440 While a[!!(x < 0x123A)][!!(1-1.0)*b[15]] 1441 EndDo.1442 If (n_123_ACV____ == 1e12123) || a[b[c[d[e[f[g["a"]]]]]]] Then1443 EndIf.1444 EndBody.1445 """1446 expect = "successful"1447 self.assertTrue(TestParser.checkParser(input,expect,296))1448 def test_mix54(self):1449 input = """ Function: foo 1450 Parameter:a[0x123ABC][0o12345],a,b,c1451 Body:1452 While True Do 1453 EndWhile.1454 Do1455 While True 1456 EndDo.1457 If True Then1458 ElseIf True Then1459 Else1460 EndIf.1461 For(i=True,i<True,True) Do1462 EndFor.1463 EndBody.1464 """1465 expect = "successful"1466 self.assertTrue(TestParser.checkParser(input,expect,297))1467 def test_mix55(self):1468 input = """ Function: foo 1469 Parameter:a[0x123ABC][0o12345],a,b,c1470 Body:1471 Var:a;1472 Var:a_;1473 Var:aB;1474 Var:a_B**This is cmt**;1475 Var:a123a_123A;1476 Var:a_b_123_B[123][0x123];1477 EndBody.1478 """1479 expect = "successful"1480 self.assertTrue(TestParser.checkParser(input,expect,298))1481 def test_mix56(self):1482 input = """ Function: foo 1483 Parameter:a[0x123ABC][0o12345],a,b,c1484 Body:1485 Var:a;1486 Var:a_;1487 Var:aB;1488 Var:a_B**This is cmt**;1489 Var:a123a_123A;1490 Var:a_b_123_B[123][0x123];1491 EndBody.1492 """1493 expect = "successful"1494 self.assertTrue(TestParser.checkParser(input,expect,299))1495 def test_mix57(self):1496 input = """ Function: foo 1497 Parameter:a[0x123ABC][0o12345],a,b,c1498 Body:1499 Var:a;1500 Var:a_;1501 Var:aB;1502 Var:a_B**This is cmt**;1503 Var:a123a_123A;1504 Var:a_b_123_B[123][0x123];1505 If True Then1506 EndIf.1507 Var: error[1][2][3];1508 EndBody.1509 """1510 expect = "Error on line 12 col 28: Var"1511 self.assertTrue(TestParser.checkParser(input,expect,300))1512 1513 ...
conditionals_multiple.py
Source:conditionals_multiple.py
1#!/usr/bin/python2# Copyright 2008 Jurko Gospodnetic3# Distributed under the Boost Software License, Version 1.0.4# (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)5# Tests that properties conditioned on more than one other property work as6# expected.7import BoostBuild8################################################################################9#10# test_multiple_conditions()11# --------------------------12#13################################################################################14def test_multiple_conditions():15 """Basic tests for properties conditioned on multiple other properties.16 """17 t = BoostBuild.Tester("--ignore-regular-config toolset=testToolset",18 pass_toolset=False, use_test_config=False)19 t.write("testToolset.jam", """20import feature ;21feature.extend toolset : testToolset ;22rule init ( ) { }23""")24 t.write("jamroot.jam", """25import feature ;26import notfile ;27import toolset ;28feature.feature description : : free incidental ;29feature.feature aaa : 1 0 : incidental ;30feature.feature bbb : 1 0 : incidental ;31feature.feature ccc : 1 0 : incidental ;32rule buildRule ( name : targets ? : properties * )33{34 for local description in [ feature.get-values description : $(properties) ]35 {36 ECHO "description:" /$(description)/ ;37 }38}39notfile testTarget1 : @buildRule : :40 <description>d41 <aaa>0:<description>a042 <aaa>1:<description>a143 <aaa>0,<bbb>0:<description>a0-b044 <aaa>0,<bbb>1:<description>a0-b145 <aaa>1,<bbb>0:<description>a1-b046 <aaa>1,<bbb>1:<description>a1-b147 <aaa>0,<bbb>0,<ccc>0:<description>a0-b0-c048 <aaa>0,<bbb>0,<ccc>1:<description>a0-b0-c149 <aaa>0,<bbb>1,<ccc>1:<description>a0-b1-c150 <aaa>1,<bbb>0,<ccc>1:<description>a1-b0-c151 <aaa>1,<bbb>1,<ccc>0:<description>a1-b1-c052 <aaa>1,<bbb>1,<ccc>1:<description>a1-b1-c1 ;53""")54 t.run_build_system("aaa=1 bbb=1 ccc=1")55 t.expect_output_line("description: /d/" )56 t.expect_output_line("description: /a0/" , False)57 t.expect_output_line("description: /a1/" )58 t.expect_output_line("description: /a0-b0/" , False)59 t.expect_output_line("description: /a0-b1/" , False)60 t.expect_output_line("description: /a1-b0/" , False)61 t.expect_output_line("description: /a1-b1/" )62 t.expect_output_line("description: /a0-b0-c0/", False)63 t.expect_output_line("description: /a0-b0-c1/", False)64 t.expect_output_line("description: /a0-b1-c1/", False)65 t.expect_output_line("description: /a1-b0-c1/", False)66 t.expect_output_line("description: /a1-b1-c0/", False)67 t.expect_output_line("description: /a1-b1-c1/" )68 t.run_build_system("aaa=0 bbb=0 ccc=1")69 t.expect_output_line("description: /d/" )70 t.expect_output_line("description: /a0/" )71 t.expect_output_line("description: /a1/" , False)72 t.expect_output_line("description: /a0-b0/" )73 t.expect_output_line("description: /a0-b1/" , False)74 t.expect_output_line("description: /a1-b0/" , False)75 t.expect_output_line("description: /a1-b1/" , False)76 t.expect_output_line("description: /a0-b0-c0/", False)77 t.expect_output_line("description: /a0-b0-c1/" )78 t.expect_output_line("description: /a0-b1-c1/", False)79 t.expect_output_line("description: /a1-b0-c1/", False)80 t.expect_output_line("description: /a1-b1-c0/", False)81 t.expect_output_line("description: /a1-b1-c1/", False)82 t.run_build_system("aaa=0 bbb=0 ccc=0")83 t.expect_output_line("description: /d/" )84 t.expect_output_line("description: /a0/" )85 t.expect_output_line("description: /a1/" , False)86 t.expect_output_line("description: /a0-b0/" )87 t.expect_output_line("description: /a0-b1/" , False)88 t.expect_output_line("description: /a1-b0/" , False)89 t.expect_output_line("description: /a1-b1/" , False)90 t.expect_output_line("description: /a0-b0-c0/" )91 t.expect_output_line("description: /a0-b0-c1/", False)92 t.expect_output_line("description: /a0-b1-c1/", False)93 t.expect_output_line("description: /a1-b0-c1/", False)94 t.expect_output_line("description: /a1-b1-c0/", False)95 t.expect_output_line("description: /a1-b1-c1/", False)96 t.cleanup()97################################################################################98#99# test_multiple_conditions_with_toolset_version()100# -----------------------------------------------101#102################################################################################103def test_multiple_conditions_with_toolset_version():104 """Regression tests for properties conditioned on the toolset version105 subfeature and some additional properties.106 """107 toolset = "testToolset" ;108 t = BoostBuild.Tester("--ignore-regular-config", pass_toolset=False, use_test_config=False)109 t.write( toolset + ".jam", """110import feature ;111feature.extend toolset : %(toolset)s ;112feature.subfeature toolset %(toolset)s : version : 0 1 ;113rule init ( version ? ) { }114""" % {"toolset": toolset})115 t.write("jamroot.jam", """116import feature ;117import notfile ;118import toolset ;119toolset.using testToolset ;120feature.feature description : : free incidental ;121feature.feature aaa : 0 1 : incidental ;122feature.feature bbb : 0 1 : incidental ;123feature.feature ccc : 0 1 : incidental ;124rule buildRule ( name : targets ? : properties * )125{126 local ttt = [ feature.get-values toolset : $(properties) ] ;127 local vvv = [ feature.get-values toolset-testToolset:version : $(properties) ] ;128 local aaa = [ feature.get-values aaa : $(properties) ] ;129 local bbb = [ feature.get-values bbb : $(properties) ] ;130 local ccc = [ feature.get-values ccc : $(properties) ] ;131 ECHO "toolset:" /$(ttt)/ "version:" /$(vvv)/ "aaa/bbb/ccc:" /$(aaa)/$(bbb)/$(ccc)/ ;132 for local description in [ feature.get-values description : $(properties) ]133 {134 ECHO "description:" /$(description)/ ;135 }136}137notfile testTarget1 : @buildRule : :138 <toolset>testToolset,<aaa>0:<description>t-a0139 <toolset>testToolset,<aaa>1:<description>t-a1140 <toolset>testToolset-0,<aaa>0:<description>t0-a0141 <toolset>testToolset-0,<aaa>1:<description>t0-a1142 <toolset>testToolset-1,<aaa>0:<description>t1-a0143 <toolset>testToolset-1,<aaa>1:<description>t1-a1144 <toolset>testToolset,<aaa>0,<bbb>0:<description>t-a0-b0145 <toolset>testToolset,<aaa>0,<bbb>1:<description>t-a0-b1146 <toolset>testToolset,<aaa>1,<bbb>0:<description>t-a1-b0147 <toolset>testToolset,<aaa>1,<bbb>1:<description>t-a1-b1148 <aaa>0,<toolset>testToolset,<bbb>0:<description>a0-t-b0149 <aaa>0,<toolset>testToolset,<bbb>1:<description>a0-t-b1150 <aaa>1,<toolset>testToolset,<bbb>0:<description>a1-t-b0151 <aaa>1,<toolset>testToolset,<bbb>1:<description>a1-t-b1152 <aaa>0,<bbb>0,<toolset>testToolset:<description>a0-b0-t153 <aaa>0,<bbb>1,<toolset>testToolset:<description>a0-b1-t154 <aaa>1,<bbb>0,<toolset>testToolset:<description>a1-b0-t155 <aaa>1,<bbb>1,<toolset>testToolset:<description>a1-b1-t156 <toolset>testToolset-0,<aaa>0,<bbb>0:<description>t0-a0-b0157 <toolset>testToolset-0,<aaa>0,<bbb>1:<description>t0-a0-b1158 <toolset>testToolset-0,<aaa>1,<bbb>0:<description>t0-a1-b0159 <toolset>testToolset-0,<aaa>1,<bbb>1:<description>t0-a1-b1160 <toolset>testToolset-1,<aaa>0,<bbb>0:<description>t1-a0-b0161 <toolset>testToolset-1,<aaa>0,<bbb>1:<description>t1-a0-b1162 <toolset>testToolset-1,<aaa>1,<bbb>0:<description>t1-a1-b0163 <toolset>testToolset-1,<aaa>1,<bbb>1:<description>t1-a1-b1164 <aaa>0,<toolset>testToolset-1,<bbb>0:<description>a0-t1-b0165 <aaa>0,<toolset>testToolset-1,<bbb>1:<description>a0-t1-b1166 <aaa>1,<toolset>testToolset-0,<bbb>0:<description>a1-t0-b0167 <aaa>1,<toolset>testToolset-0,<bbb>1:<description>a1-t0-b1168 <bbb>0,<aaa>1,<toolset>testToolset-0:<description>b0-a1-t0169 <bbb>0,<aaa>0,<toolset>testToolset-1:<description>b0-a0-t1170 <bbb>0,<aaa>1,<toolset>testToolset-1:<description>b0-a1-t1171 <bbb>1,<aaa>0,<toolset>testToolset-1:<description>b1-a0-t1172 <bbb>1,<aaa>1,<toolset>testToolset-0:<description>b1-a1-t0173 <bbb>1,<aaa>1,<toolset>testToolset-1:<description>b1-a1-t1 ;174""")175 t.run_build_system("aaa=1 bbb=1 ccc=1 toolset=%s-0" % toolset)176 t.expect_output_line("description: /t-a0/" , False)177 t.expect_output_line("description: /t-a1/" )178 t.expect_output_line("description: /t0-a0/" , False)179 t.expect_output_line("description: /t0-a1/" )180 t.expect_output_line("description: /t1-a0/" , False)181 t.expect_output_line("description: /t1-a1/" , False)182 t.expect_output_line("description: /t-a0-b0/" , False)183 t.expect_output_line("description: /t-a0-b1/" , False)184 t.expect_output_line("description: /t-a1-b0/" , False)185 t.expect_output_line("description: /t-a1-b1/" )186 t.expect_output_line("description: /a0-t-b0/" , False)187 t.expect_output_line("description: /a0-t-b1/" , False)188 t.expect_output_line("description: /a1-t-b0/" , False)189 t.expect_output_line("description: /a1-t-b1/" )190 t.expect_output_line("description: /a0-b0-t/" , False)191 t.expect_output_line("description: /a0-b1-t/" , False)192 t.expect_output_line("description: /a1-b0-t/" , False)193 t.expect_output_line("description: /a1-b1-t/" )194 t.expect_output_line("description: /t0-a0-b0/", False)195 t.expect_output_line("description: /t0-a0-b1/", False)196 t.expect_output_line("description: /t0-a1-b0/", False)197 t.expect_output_line("description: /t0-a1-b1/" )198 t.expect_output_line("description: /t1-a0-b0/", False)199 t.expect_output_line("description: /t1-a0-b1/", False)200 t.expect_output_line("description: /t1-a1-b0/", False)201 t.expect_output_line("description: /t1-a1-b1/", False)202 t.expect_output_line("description: /a0-t1-b0/", False)203 t.expect_output_line("description: /a0-t1-b1/", False)204 t.expect_output_line("description: /a1-t0-b0/", False)205 t.expect_output_line("description: /a1-t0-b1/" )206 t.expect_output_line("description: /b0-a1-t0/", False)207 t.expect_output_line("description: /b0-a0-t1/", False)208 t.expect_output_line("description: /b0-a1-t1/", False)209 t.expect_output_line("description: /b1-a0-t1/", False)210 t.expect_output_line("description: /b1-a1-t0/" )211 t.expect_output_line("description: /b1-a1-t1/", False)212 t.run_build_system("aaa=1 bbb=1 ccc=1 toolset=%s-1" % toolset)213 t.expect_output_line("description: /t-a0/" , False)214 t.expect_output_line("description: /t-a1/" )215 t.expect_output_line("description: /t0-a0/" , False)216 t.expect_output_line("description: /t0-a1/" , False)217 t.expect_output_line("description: /t1-a0/" , False)218 t.expect_output_line("description: /t1-a1/" )219 t.expect_output_line("description: /t-a0-b0/" , False)220 t.expect_output_line("description: /t-a0-b1/" , False)221 t.expect_output_line("description: /t-a1-b0/" , False)222 t.expect_output_line("description: /t-a1-b1/" )223 t.expect_output_line("description: /a0-t-b0/" , False)224 t.expect_output_line("description: /a0-t-b1/" , False)225 t.expect_output_line("description: /a1-t-b0/" , False)226 t.expect_output_line("description: /a1-t-b1/" )227 t.expect_output_line("description: /a0-b0-t/" , False)228 t.expect_output_line("description: /a0-b1-t/" , False)229 t.expect_output_line("description: /a1-b0-t/" , False)230 t.expect_output_line("description: /a1-b1-t/" )231 t.expect_output_line("description: /t0-a0-b0/", False)232 t.expect_output_line("description: /t0-a0-b1/", False)233 t.expect_output_line("description: /t0-a1-b0/", False)234 t.expect_output_line("description: /t0-a1-b1/", False)235 t.expect_output_line("description: /t1-a0-b0/", False)236 t.expect_output_line("description: /t1-a0-b1/", False)237 t.expect_output_line("description: /t1-a1-b0/", False)238 t.expect_output_line("description: /t1-a1-b1/" )239 t.expect_output_line("description: /a0-t1-b0/", False)240 t.expect_output_line("description: /a0-t1-b1/", False)241 t.expect_output_line("description: /a1-t0-b0/", False)242 t.expect_output_line("description: /a1-t0-b1/", False)243 t.expect_output_line("description: /b0-a1-t0/", False)244 t.expect_output_line("description: /b0-a0-t1/", False)245 t.expect_output_line("description: /b0-a1-t1/", False)246 t.expect_output_line("description: /b1-a0-t1/", False)247 t.expect_output_line("description: /b1-a1-t0/", False)248 t.expect_output_line("description: /b1-a1-t1/" )249 t.cleanup()250################################################################################251#252# main()253# ------254#255################################################################################256test_multiple_conditions()...
configuration.py
Source:configuration.py
1#!/usr/bin/python2# Copyright 2008, 2012 Jurko Gospodnetic3# Distributed under the Boost Software License, Version 1.0.4# (See accompanying file LICENSE_1_0.txt or copy at5# http://www.boost.org/LICENSE_1_0.txt)6# Test Boost Build configuration file handling.7import BoostBuild8import os9import os.path10import re11###############################################################################12#13# test_user_configuration()14# -------------------------15#16###############################################################################17def test_user_configuration():18 """19 Test Boost Build user configuration handling. Both relative and absolute20 path handling is tested.21 """22 implicitConfigLoadMessage = \23 "notice: Loading user-config configuration file: *"24 explicitConfigLoadMessage = \25 "notice: Loading explicitly specified user configuration file:"26 disabledConfigLoadMessage = \27 "notice: User configuration file loading explicitly disabled."28 testMessage = "_!_!_!_!_!_!_!_!_ %s _!_!_!_!_!_!_!_!_"29 toolsetName = "__myDummyToolset__"30 subdirName = "ASubDirectory"31 configFileNames = ["ups_lala_1.jam", "ups_lala_2.jam",32 os.path.join(subdirName, "ups_lala_3.jam")]33 t = BoostBuild.Tester(["toolset=%s" % toolsetName,34 "--debug-configuration"], pass_toolset=False, use_test_config=False)35 for configFileName in configFileNames:36 message = "ECHO \"%s\" ;" % testMessage % configFileName37 # We need to double any backslashes in the message or Jam will38 # interpret them as escape characters.39 t.write(configFileName, message.replace("\\", "\\\\"))40 # Prepare a dummy toolset so we do not get errors in case the default one41 # is not found.42 t.write(toolsetName + ".jam", """\43import feature ;44feature.extend toolset : %s ;45rule init ( ) { }46""" % toolsetName)47 # Python version of the same dummy toolset.48 t.write(toolsetName + ".py", """\49from b2.build import feature50feature.extend('toolset', ['%s'])51def init(): pass52""" % toolsetName)53 t.write("jamroot.jam", """\54local test-index = [ MATCH ---test-id---=(.*) : [ modules.peek : ARGV ] ] ;55ECHO test-index: $(test-index:E=(unknown)) ;56""")57 class LocalTester:58 def __init__(self, tester):59 self.__tester = tester60 self.__test_ids = []61 def __assertionFailure(self, message):62 BoostBuild.annotation("failure", "Internal test assertion failure "63 "- %s" % message)64 self.__tester.fail_test(1)65 def __call__(self, test_id, env, extra_args=None, *args, **kwargs):66 if env == "" and not canSetEmptyEnvironmentVariable:67 self.__assertionFailure("Can not set empty environment "68 "variables on this platform.")69 self.__registerTestId(str(test_id))70 if extra_args is None:71 extra_args = []72 extra_args.append("---test-id---=%s" % test_id)73 env_name = "BOOST_BUILD_USER_CONFIG"74 previous_env = os.environ.get(env_name)75 _env_set(env_name, env)76 try:77 self.__tester.run_build_system(extra_args, *args, **kwargs)78 finally:79 _env_set(env_name, previous_env)80 def __registerTestId(self, test_id):81 if test_id in self.__test_ids:82 self.__assertionFailure("Multiple test cases encountered "83 "using the same test id '%s'." % test_id)84 self.__test_ids.append(test_id)85 test = LocalTester(t)86 test(1, None)87 t.expect_output_lines(explicitConfigLoadMessage, False)88 t.expect_output_lines(disabledConfigLoadMessage, False)89 t.expect_output_lines(testMessage % configFileNames[0], False)90 t.expect_output_lines(testMessage % configFileNames[1], False)91 t.expect_output_lines(testMessage % configFileNames[2], False)92 test(2, None, ["--user-config="])93 t.expect_output_lines(implicitConfigLoadMessage, False)94 t.expect_output_lines(explicitConfigLoadMessage, False)95 t.expect_output_lines(disabledConfigLoadMessage)96 t.expect_output_lines(testMessage % configFileNames[0], False)97 t.expect_output_lines(testMessage % configFileNames[1], False)98 t.expect_output_lines(testMessage % configFileNames[2], False)99 test(3, None, ['--user-config=""'])100 t.expect_output_lines(implicitConfigLoadMessage, False)101 t.expect_output_lines(explicitConfigLoadMessage, False)102 t.expect_output_lines(disabledConfigLoadMessage)103 t.expect_output_lines(testMessage % configFileNames[0], False)104 t.expect_output_lines(testMessage % configFileNames[1], False)105 t.expect_output_lines(testMessage % configFileNames[2], False)106 test(4, None, ['--user-config="%s"' % configFileNames[0]])107 t.expect_output_lines(implicitConfigLoadMessage, False)108 t.expect_output_lines(explicitConfigLoadMessage)109 t.expect_output_lines(disabledConfigLoadMessage, False)110 t.expect_output_lines(testMessage % configFileNames[0])111 t.expect_output_lines(testMessage % configFileNames[1], False)112 t.expect_output_lines(testMessage % configFileNames[2], False)113 test(5, None, ['--user-config="%s"' % configFileNames[2]])114 t.expect_output_lines(implicitConfigLoadMessage, False)115 t.expect_output_lines(explicitConfigLoadMessage)116 t.expect_output_lines(disabledConfigLoadMessage, False)117 t.expect_output_lines(testMessage % configFileNames[0], False)118 t.expect_output_lines(testMessage % configFileNames[1], False)119 t.expect_output_lines(testMessage % configFileNames[2])120 test(6, None, ['--user-config="%s"' % os.path.abspath(configFileNames[1])])121 t.expect_output_lines(implicitConfigLoadMessage, False)122 t.expect_output_lines(explicitConfigLoadMessage)123 t.expect_output_lines(disabledConfigLoadMessage, False)124 t.expect_output_lines(testMessage % configFileNames[0], False)125 t.expect_output_lines(testMessage % configFileNames[1])126 t.expect_output_lines(testMessage % configFileNames[2], False)127 test(7, None, ['--user-config="%s"' % os.path.abspath(configFileNames[2])])128 t.expect_output_lines(implicitConfigLoadMessage, False)129 t.expect_output_lines(explicitConfigLoadMessage)130 t.expect_output_lines(disabledConfigLoadMessage, False)131 t.expect_output_lines(testMessage % configFileNames[0], False)132 t.expect_output_lines(testMessage % configFileNames[1], False)133 t.expect_output_lines(testMessage % configFileNames[2])134 if canSetEmptyEnvironmentVariable:135 test(8, "")136 t.expect_output_lines(implicitConfigLoadMessage, False)137 t.expect_output_lines(explicitConfigLoadMessage, False)138 t.expect_output_lines(disabledConfigLoadMessage, True)139 t.expect_output_lines(testMessage % configFileNames[0], False)140 t.expect_output_lines(testMessage % configFileNames[1], False)141 t.expect_output_lines(testMessage % configFileNames[2], False)142 test(9, '""')143 t.expect_output_lines(implicitConfigLoadMessage, False)144 t.expect_output_lines(explicitConfigLoadMessage, False)145 t.expect_output_lines(disabledConfigLoadMessage)146 t.expect_output_lines(testMessage % configFileNames[0], False)147 t.expect_output_lines(testMessage % configFileNames[1], False)148 t.expect_output_lines(testMessage % configFileNames[2], False)149 test(10, configFileNames[1])150 t.expect_output_lines(implicitConfigLoadMessage, False)151 t.expect_output_lines(explicitConfigLoadMessage)152 t.expect_output_lines(disabledConfigLoadMessage, False)153 t.expect_output_lines(testMessage % configFileNames[0], False)154 t.expect_output_lines(testMessage % configFileNames[1])155 t.expect_output_lines(testMessage % configFileNames[2], False)156 test(11, configFileNames[1], ['--user-config=""'])157 t.expect_output_lines(implicitConfigLoadMessage, False)158 t.expect_output_lines(explicitConfigLoadMessage, False)159 t.expect_output_lines(disabledConfigLoadMessage)160 t.expect_output_lines(testMessage % configFileNames[0], False)161 t.expect_output_lines(testMessage % configFileNames[1], False)162 t.expect_output_lines(testMessage % configFileNames[2], False)163 test(12, configFileNames[1], ['--user-config="%s"' % configFileNames[0]])164 t.expect_output_lines(implicitConfigLoadMessage, False)165 t.expect_output_lines(explicitConfigLoadMessage)166 t.expect_output_lines(disabledConfigLoadMessage, False)167 t.expect_output_lines(testMessage % configFileNames[0])168 t.expect_output_lines(testMessage % configFileNames[1], False)169 t.expect_output_lines(testMessage % configFileNames[2], False)170 if canSetEmptyEnvironmentVariable:171 test(13, "", ['--user-config="%s"' % configFileNames[0]])172 t.expect_output_lines(implicitConfigLoadMessage, False)173 t.expect_output_lines(explicitConfigLoadMessage)174 t.expect_output_lines(disabledConfigLoadMessage, False)175 t.expect_output_lines(testMessage % configFileNames[0])176 t.expect_output_lines(testMessage % configFileNames[1], False)177 t.expect_output_lines(testMessage % configFileNames[2], False)178 test(14, '""', ['--user-config="%s"' % configFileNames[0]])179 t.expect_output_lines(implicitConfigLoadMessage, False)180 t.expect_output_lines(explicitConfigLoadMessage)181 t.expect_output_lines(disabledConfigLoadMessage, False)182 t.expect_output_lines(testMessage % configFileNames[0])183 t.expect_output_lines(testMessage % configFileNames[1], False)184 t.expect_output_lines(testMessage % configFileNames[2], False)185 test(15, "invalid", ['--user-config="%s"' % configFileNames[0]])186 t.expect_output_lines(implicitConfigLoadMessage, False)187 t.expect_output_lines(explicitConfigLoadMessage)188 t.expect_output_lines(disabledConfigLoadMessage, False)189 t.expect_output_lines(testMessage % configFileNames[0])190 t.expect_output_lines(testMessage % configFileNames[1], False)191 t.expect_output_lines(testMessage % configFileNames[2], False)192 t.cleanup()193###############################################################################194#195# Private interface.196#197###############################################################################198def _canSetEmptyEnvironmentVariable():199 """200 Unfortunately different OSs (and possibly Python implementations as well)201 have different interpretations of what it means to set an evironment202 variable to an empty string. Some (e.g. Windows) interpret it as unsetting203 the variable and some (e.g. AIX or Darwin) actually set it to an empty204 string.205 """206 dummyName = "UGNABUNGA_FOO_BAR_BAZ_FEE_FAE_FOU_FAM"207 original = os.environ.get(dummyName)208 _env_set(dummyName, "")209 result = _getExternalEnv(dummyName) == ""210 _env_set(dummyName, original)211 return result212def _env_del(name):213 """214 Unsets the given environment variable if it is currently set.215 Note that we can not use os.environ.pop() or os.environ.clear() here216 since prior to Python 2.6 these functions did not remove the actual217 environment variable by calling os.unsetenv().218 """219 try:220 del os.environ[name]221 except KeyError:222 pass223def _env_set(name, value):224 """225 Sets the given environment variable value or unsets it, if the value is226 None.227 """228 if value is None:229 _env_del(name)230 else:231 os.environ[name] = value232def _getExternalEnv(name):233 toolsetName = "__myDummyToolset__"234 t = BoostBuild.Tester(["toolset=%s" % toolsetName], pass_toolset=False,235 use_test_config=False)236 try:237 # Prepare a dummy toolset so we do not get errors in case the default238 # one is not found.239 t.write(toolsetName + ".jam", """\240import feature ;241feature.extend toolset : %s ;242rule init ( ) { }243""" % toolsetName)244 # Python version of the same dummy toolset.245 t.write(toolsetName + ".py", """\246from b2.build import feature247feature.extend('toolset', ['%s'])248def init(): pass249""" % toolsetName)250 t.write("jamroot.jam", """\251import os ;252local names = [ MATCH ^---var-name---=(.*) : [ modules.peek : ARGV ] ] ;253for x in $(names)254{255 value = [ os.environ $(x) ] ;256 ECHO "###" $(x): '$(value)' "###" ;257}258""")259 t.run_build_system(["---var-name---=%s" % name])260 m = re.search("^### %s: '(.*)' ###$" % name, t.stdout(), re.MULTILINE)261 if m:262 return m.group(1)263 finally:264 t.cleanup()265###############################################################################266#267# main()268# ------269#270###############################################################################271canSetEmptyEnvironmentVariable = _canSetEmptyEnvironmentVariable()...
test.py
Source:test.py
...70 def test_watch_live_view_order_by_node(self, started_cluster, node, source):71 command = " ".join(node.client.command)72 args = dict(log=log, command=command)73 with client(name="client1> ", **args) as client1, client(name="client2> ", **args) as client2:74 client1.expect(prompt)75 client2.expect(prompt)76 client1.send("SET allow_experimental_live_view = 1")77 client1.expect(prompt)78 client2.send("SET allow_experimental_live_view = 1")79 client2.expect(prompt)80 client1.send("DROP TABLE IF EXISTS lv")81 client1.expect(prompt)82 client1.send("CREATE LIVE VIEW lv AS SELECT * FROM distributed_table ORDER BY node, key")83 client1.expect(prompt)84 client1.send("WATCH lv FORMAT CSV")85 client1.expect('"node1",0,0,1')86 client1.expect('"node1",1,1,1')87 client1.expect('"node2",0,10,1')88 client1.expect('"node2",1,11,1')89 client2.send("INSERT INTO distributed_table VALUES ('node1', 2, 2)")90 client2.expect(prompt)91 client1.expect('"node1",0,0,2')92 client1.expect('"node1",1,1,2')93 client1.expect('"node1",2,2,2')94 client1.expect('"node2",0,10,2')95 client1.expect('"node2",1,11,2')96 client2.send("INSERT INTO distributed_table VALUES ('node1', 0, 3), ('node3', 3, 3)")97 client2.expect(prompt)98 client1.expect('"node1",0,0,3')99 client1.expect('"node1",0,3,3')100 client1.expect('"node1",1,1,3')101 client1.expect('"node1",2,2,3')102 client1.expect('"node2",0,10,3')103 client1.expect('"node2",1,11,3')104 client1.expect('"node3",3,3,3')105 def test_watch_live_view_order_by_key(self, started_cluster, node, source):106 command = " ".join(node.client.command)107 args = dict(log=log, command=command)108 with client(name="client1> ", **args) as client1, client(name="client2> ", **args) as client2:109 client1.expect(prompt)110 client2.expect(prompt)111 client1.send("SET allow_experimental_live_view = 1")112 client1.expect(prompt)113 client2.send("SET allow_experimental_live_view = 1")114 client2.expect(prompt)115 client1.send("DROP TABLE IF EXISTS lv")116 client1.expect(prompt)117 client1.send("CREATE LIVE VIEW lv AS SELECT * FROM distributed_table ORDER BY key, node")118 client1.expect(prompt)119 client1.send("WATCH lv FORMAT CSV")120 client1.expect('"node1",0,0,1')121 client1.expect('"node2",0,10,1')122 client1.expect('"node1",1,1,1')123 client1.expect('"node2",1,11,1')124 client2.send("INSERT INTO distributed_table VALUES ('node1', 2, 2)")125 client2.expect(prompt)126 client1.expect('"node1",0,0,2')127 client1.expect('"node2",0,10,2')128 client1.expect('"node1",1,1,2')129 client1.expect('"node2",1,11,2')130 client1.expect('"node1",2,2,2')131 client2.send("INSERT INTO distributed_table VALUES ('node1', 0, 3), ('node3', 3, 3)")132 client2.expect(prompt)133 client1.expect('"node1",0,0,3')134 client1.expect('"node1",0,3,3')135 client1.expect('"node2",0,10,3')136 client1.expect('"node1",1,1,3')137 client1.expect('"node2",1,11,3')138 client1.expect('"node1",2,2,3')139 client1.expect('"node3",3,3,3')140 def test_watch_live_view_group_by_node(self, started_cluster, node, source):141 command = " ".join(node.client.command)142 args = dict(log=log, command=command)143 with client(name="client1> ", **args) as client1, client(name="client2> ", **args) as client2:144 client1.expect(prompt)145 client2.expect(prompt)146 client1.send("SET allow_experimental_live_view = 1")147 client1.expect(prompt)148 client2.send("SET allow_experimental_live_view = 1")149 client2.expect(prompt)150 client1.send("DROP TABLE IF EXISTS lv")151 client1.expect(prompt)152 client1.send(153 "CREATE LIVE VIEW lv AS SELECT node, SUM(value) FROM distributed_table GROUP BY node ORDER BY node")154 client1.expect(prompt)155 client1.send("WATCH lv FORMAT CSV")156 client1.expect('"node1",1,1')157 client1.expect('"node2",21,1')158 client2.send("INSERT INTO distributed_table VALUES ('node1', 2, 2)")159 client2.expect(prompt)160 client1.expect('"node1",3,2')161 client1.expect('"node2",21,2')162 client2.send("INSERT INTO distributed_table VALUES ('node1', 0, 3), ('node3', 3, 3)")163 client2.expect(prompt)164 client1.expect('"node1",6,3')165 client1.expect('"node2",21,3')166 client1.expect('"node3",3,3')167 def test_watch_live_view_group_by_key(self, started_cluster, node, source):168 command = " ".join(node.client.command)169 args = dict(log=log, command=command)170 sep = ' \xe2\x94\x82'171 with client(name="client1> ", **args) as client1, client(name="client2> ", **args) as client2:172 client1.expect(prompt)173 client2.expect(prompt)174 client1.send("SET allow_experimental_live_view = 1")175 client1.expect(prompt)176 client2.send("SET allow_experimental_live_view = 1")177 client2.expect(prompt)178 client1.send("DROP TABLE IF EXISTS lv")179 client1.expect(prompt)180 client1.send(181 "CREATE LIVE VIEW lv AS SELECT key, SUM(value) FROM distributed_table GROUP BY key ORDER BY key")182 client1.expect(prompt)183 client1.send("WATCH lv FORMAT CSV")184 client1.expect('0,10,1')185 client1.expect('1,12,1')186 client2.send("INSERT INTO distributed_table VALUES ('node1', 2, 2)")187 client2.expect(prompt)188 client1.expect('0,10,2')189 client1.expect('1,12,2')190 client1.expect('2,2,2')191 client2.send("INSERT INTO distributed_table VALUES ('node1', 0, 3), ('node1', 3, 3)")192 client2.expect(prompt)193 client1.expect('0,13,3')194 client1.expect('1,12,3')195 client1.expect('2,2,3')196 client1.expect('3,3,3')197 def test_watch_live_view_sum(self, started_cluster, node, source):198 command = " ".join(node.client.command)199 args = dict(log=log, command=command)200 with client(name="client1> ", **args) as client1, client(name="client2> ", **args) as client2:201 client1.expect(prompt)202 client2.expect(prompt)203 client1.send("SET allow_experimental_live_view = 1")204 client1.expect(prompt)205 client2.send("SET allow_experimental_live_view = 1")206 client2.expect(prompt)207 client1.send("DROP TABLE IF EXISTS lv")208 client1.expect(prompt)209 client1.send("CREATE LIVE VIEW lv AS SELECT sum(value) FROM distributed_table")210 client1.expect(prompt)211 client1.send("WATCH lv")212 client1.expect(r"22.*1" + end_of_block)213 client2.send("INSERT INTO distributed_table VALUES ('node1', 2, 2)")214 client2.expect(prompt)215 client1.expect(r"24.*2" + end_of_block)216 client2.send("INSERT INTO distributed_table VALUES ('node1', 3, 3), ('node1', 4, 4)")217 client2.expect(prompt)...
057
Source:057
1#!/usr/bin/env python2#3# Tests for internal snapshot.4#5# Copyright (C) 2013 IBM, Inc.6#7# Based on 055.8#9# This program is free software; you can redistribute it and/or modify10# it under the terms of the GNU General Public License as published by11# the Free Software Foundation; either version 2 of the License, or12# (at your option) any later version.13#14# This program is distributed in the hope that it will be useful,15# but WITHOUT ANY WARRANTY; without even the implied warranty of16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17# GNU General Public License for more details.18#19# You should have received a copy of the GNU General Public License20# along with this program. If not, see <http://www.gnu.org/licenses/>.21#22import time23import os24import iotests25from iotests import qemu_img, qemu_io26test_drv_base_name = 'drive'27class ImageSnapshotTestCase(iotests.QMPTestCase):28 image_len = 120 * 1024 * 1024 # MB29 def __init__(self, *args):30 self.expect = []31 super(ImageSnapshotTestCase, self).__init__(*args)32 def _setUp(self, test_img_base_name, image_num):33 self.vm = iotests.VM()34 for i in range(0, image_num):35 filename = '%s%d' % (test_img_base_name, i)36 img = os.path.join(iotests.test_dir, filename)37 device = '%s%d' % (test_drv_base_name, i)38 qemu_img('create', '-f', iotests.imgfmt, img, str(self.image_len))39 self.vm.add_drive(img)40 self.expect.append({'image': img, 'device': device,41 'snapshots': [],42 'snapshots_name_counter': 0})43 self.vm.launch()44 def tearDown(self):45 self.vm.shutdown()46 for dev_expect in self.expect:47 os.remove(dev_expect['image'])48 def createSnapshotInTransaction(self, snapshot_num, abort = False):49 actions = []50 for dev_expect in self.expect:51 num = dev_expect['snapshots_name_counter']52 for j in range(0, snapshot_num):53 name = '%s_sn%d' % (dev_expect['device'], num)54 num = num + 155 if abort == False:56 dev_expect['snapshots'].append({'name': name})57 dev_expect['snapshots_name_counter'] = num58 actions.append({59 'type': 'blockdev-snapshot-internal-sync',60 'data': { 'device': dev_expect['device'],61 'name': name },62 })63 if abort == True:64 actions.append({65 'type': 'abort',66 'data': {},67 })68 result = self.vm.qmp('transaction', actions = actions)69 if abort == True:70 self.assert_qmp(result, 'error/class', 'GenericError')71 else:72 self.assert_qmp(result, 'return', {})73 def verifySnapshotInfo(self):74 result = self.vm.qmp('query-block')75 # Verify each expected result76 for dev_expect in self.expect:77 # 1. Find the returned image value and snapshot info78 image_result = None79 for device in result['return']:80 if device['device'] == dev_expect['device']:81 image_result = device['inserted']['image']82 break83 self.assertTrue(image_result != None)84 # Do not consider zero snapshot case now85 sn_list_result = image_result['snapshots']86 sn_list_expect = dev_expect['snapshots']87 # 2. Verify it with expect88 self.assertTrue(len(sn_list_result) == len(sn_list_expect))89 for sn_expect in sn_list_expect:90 sn_result = None91 for sn in sn_list_result:92 if sn_expect['name'] == sn['name']:93 sn_result = sn94 break95 self.assertTrue(sn_result != None)96 # Fill in the detail info97 sn_expect.update(sn_result)98 def deleteSnapshot(self, device, id = None, name = None):99 sn_list_expect = None100 sn_expect = None101 self.assertTrue(id != None or name != None)102 # Fill in the detail info include ID103 self.verifySnapshotInfo()104 #find the expected snapshot list105 for dev_expect in self.expect:106 if dev_expect['device'] == device:107 sn_list_expect = dev_expect['snapshots']108 break109 self.assertTrue(sn_list_expect != None)110 if id != None and name != None:111 for sn in sn_list_expect:112 if sn['id'] == id and sn['name'] == name:113 sn_expect = sn114 result = \115 self.vm.qmp('blockdev-snapshot-delete-internal-sync',116 device = device,117 id = id,118 name = name)119 break120 elif id != None:121 for sn in sn_list_expect:122 if sn['id'] == id:123 sn_expect = sn124 result = \125 self.vm.qmp('blockdev-snapshot-delete-internal-sync',126 device = device,127 id = id)128 break129 else:130 for sn in sn_list_expect:131 if sn['name'] == name:132 sn_expect = sn133 result = \134 self.vm.qmp('blockdev-snapshot-delete-internal-sync',135 device = device,136 name = name)137 break138 self.assertTrue(sn_expect != None)139 self.assert_qmp(result, 'return', sn_expect)140 sn_list_expect.remove(sn_expect)141class TestSingleTransaction(ImageSnapshotTestCase):142 def setUp(self):143 self._setUp('test_a.img', 1)144 def test_create(self):145 self.createSnapshotInTransaction(1)146 self.verifySnapshotInfo()147 def test_error_name_empty(self):148 actions = [{'type': 'blockdev-snapshot-internal-sync',149 'data': { 'device': self.expect[0]['device'],150 'name': '' },151 }]152 result = self.vm.qmp('transaction', actions = actions)153 self.assert_qmp(result, 'error/class', 'GenericError')154 def test_error_device(self):155 actions = [{'type': 'blockdev-snapshot-internal-sync',156 'data': { 'device': 'drive_error',157 'name': 'a' },158 }]159 result = self.vm.qmp('transaction', actions = actions)160 self.assert_qmp(result, 'error/class', 'DeviceNotFound')161 def test_error_exist(self):162 self.createSnapshotInTransaction(1)163 self.verifySnapshotInfo()164 actions = [{'type': 'blockdev-snapshot-internal-sync',165 'data': { 'device': self.expect[0]['device'],166 'name': self.expect[0]['snapshots'][0] },167 }]168 result = self.vm.qmp('transaction', actions = actions)169 self.assert_qmp(result, 'error/class', 'GenericError')170class TestMultipleTransaction(ImageSnapshotTestCase):171 def setUp(self):172 self._setUp('test_b.img', 2)173 def test_create(self):174 self.createSnapshotInTransaction(3)175 self.verifySnapshotInfo()176 def test_abort(self):177 self.createSnapshotInTransaction(2)178 self.verifySnapshotInfo()179 self.createSnapshotInTransaction(3, abort = True)180 self.verifySnapshotInfo()181class TestSnapshotDelete(ImageSnapshotTestCase):182 def setUp(self):183 self._setUp('test_c.img', 1)184 def test_delete_with_id(self):185 self.createSnapshotInTransaction(2)186 self.verifySnapshotInfo()187 self.deleteSnapshot(self.expect[0]['device'],188 id = self.expect[0]['snapshots'][0]['id'])189 self.verifySnapshotInfo()190 def test_delete_with_name(self):191 self.createSnapshotInTransaction(3)192 self.verifySnapshotInfo()193 self.deleteSnapshot(self.expect[0]['device'],194 name = self.expect[0]['snapshots'][1]['name'])195 self.verifySnapshotInfo()196 def test_delete_with_id_and_name(self):197 self.createSnapshotInTransaction(4)198 self.verifySnapshotInfo()199 self.deleteSnapshot(self.expect[0]['device'],200 id = self.expect[0]['snapshots'][2]['id'],201 name = self.expect[0]['snapshots'][2]['name'])202 self.verifySnapshotInfo()203 def test_error_device(self):204 result = self.vm.qmp('blockdev-snapshot-delete-internal-sync',205 device = 'drive_error',206 id = '0')207 self.assert_qmp(result, 'error/class', 'DeviceNotFound')208 def test_error_no_id_and_name(self):209 result = self.vm.qmp('blockdev-snapshot-delete-internal-sync',210 device = self.expect[0]['device'])211 self.assert_qmp(result, 'error/class', 'GenericError')212 def test_error_snapshot_not_exist(self):213 self.createSnapshotInTransaction(2)214 self.verifySnapshotInfo()215 result = self.vm.qmp('blockdev-snapshot-delete-internal-sync',216 device = self.expect[0]['device'],217 id = self.expect[0]['snapshots'][0]['id'],218 name = self.expect[0]['snapshots'][1]['name'])219 self.assert_qmp(result, 'error/class', 'GenericError')220if __name__ == '__main__':...
project_test3.py
Source:project_test3.py
1#!/usr/bin/python2# Copyright 2002, 2003 Dave Abrahams3# Copyright 2002, 2003, 2004, 2006 Vladimir Prus4# Distributed under the Boost Software License, Version 1.0.5# (See accompanying file LICENSE_1_0.txt or copy at6# http://www.boost.org/LICENSE_1_0.txt)7import BoostBuild8import os9t = BoostBuild.Tester(translate_suffixes=0)10# First check some startup.11t.set_tree("project-test3")12os.remove("jamroot.jam")13t.run_build_system(status=1)14t.expect_output_lines("error: Could not find parent for project at '.'\n"15 "error: Did not find Jamfile.jam or Jamroot.jam in any parent directory.")16t.set_tree("project-test3")17t.run_build_system()18t.expect_addition("bin/$toolset/debug/a.obj")19t.expect_content("bin/$toolset/debug/a.obj", """\20$toolset/debug21a.cpp22""")23t.expect_addition("bin/$toolset/debug/a.exe")24t.expect_content("bin/$toolset/debug/a.exe",25"$toolset/debug\n" +26"bin/$toolset/debug/a.obj lib/bin/$toolset/debug/b.obj " +27"lib2/bin/$toolset/debug/c.obj lib2/bin/$toolset/debug/d.obj " +28"lib2/helper/bin/$toolset/debug/e.obj " +29"lib3/bin/$toolset/debug/f.obj\n"30)31t.expect_addition("lib/bin/$toolset/debug/b.obj")32t.expect_content("lib/bin/$toolset/debug/b.obj", """\33$toolset/debug34lib/b.cpp35""")36t.expect_addition("lib/bin/$toolset/debug/m.exe")37t.expect_content("lib/bin/$toolset/debug/m.exe", """\38$toolset/debug39lib/bin/$toolset/debug/b.obj lib2/bin/$toolset/debug/c.obj40""")41t.expect_addition("lib2/bin/$toolset/debug/c.obj")42t.expect_content("lib2/bin/$toolset/debug/c.obj", """\43$toolset/debug44lib2/c.cpp45""")46t.expect_addition("lib2/bin/$toolset/debug/d.obj")47t.expect_content("lib2/bin/$toolset/debug/d.obj", """\48$toolset/debug49lib2/d.cpp50""")51t.expect_addition("lib2/bin/$toolset/debug/l.exe")52t.expect_content("lib2/bin/$toolset/debug/l.exe", """\53$toolset/debug54lib2/bin/$toolset/debug/c.obj bin/$toolset/debug/a.obj55""")56t.expect_addition("lib2/helper/bin/$toolset/debug/e.obj")57t.expect_content("lib2/helper/bin/$toolset/debug/e.obj", """\58$toolset/debug59lib2/helper/e.cpp60""")61t.expect_addition("lib3/bin/$toolset/debug/f.obj")62t.expect_content("lib3/bin/$toolset/debug/f.obj", """\63$toolset/debug64lib3/f.cpp lib2/helper/bin/$toolset/debug/e.obj65""")66t.touch("a.cpp")67t.run_build_system()68t.expect_touch(["bin/$toolset/debug/a.obj",69 "bin/$toolset/debug/a.exe",70 "lib2/bin/$toolset/debug/l.exe"])71t.run_build_system(["release", "optimization=off,speed"])72t.expect_addition(["bin/$toolset/release/a.exe",73 "bin/$toolset/release/a.obj",74 "bin/$toolset/release/optimization-off/a.exe",75 "bin/$toolset/release/optimization-off/a.obj"])76t.run_build_system(["--clean-all"])77t.expect_removal(["bin/$toolset/debug/a.obj",78 "bin/$toolset/debug/a.exe",79 "lib/bin/$toolset/debug/b.obj",80 "lib/bin/$toolset/debug/m.exe",81 "lib2/bin/$toolset/debug/c.obj",82 "lib2/bin/$toolset/debug/d.obj",83 "lib2/bin/$toolset/debug/l.exe",84 "lib3/bin/$toolset/debug/f.obj"])85# Now test target ids in command line.86t.set_tree("project-test3")87t.run_build_system(["lib//b.obj"])88t.expect_addition("lib/bin/$toolset/debug/b.obj")89t.expect_nothing_more()90t.run_build_system(["--clean", "lib//b.obj"])91t.expect_removal("lib/bin/$toolset/debug/b.obj")92t.expect_nothing_more()93t.run_build_system(["lib//b.obj"])94t.expect_addition("lib/bin/$toolset/debug/b.obj")95t.expect_nothing_more()96t.run_build_system(["release", "lib2/helper//e.obj", "/lib3//f.obj"])97t.expect_addition("lib2/helper/bin/$toolset/release/e.obj")98t.expect_addition("lib3/bin/$toolset/release/f.obj")99t.expect_nothing_more()100# Test project ids in command line work as well.101t.set_tree("project-test3")102t.run_build_system(["/lib2"])103t.expect_addition("lib2/bin/$toolset/debug/" *104 BoostBuild.List("c.obj d.obj l.exe"))105t.expect_addition("bin/$toolset/debug/a.obj")106t.expect_nothing_more()107t.run_build_system(["lib"])108t.expect_addition("lib/bin/$toolset/debug/" *109 BoostBuild.List("b.obj m.exe"))110t.expect_nothing_more()...
00979_live_view_watch_continuous_aggregates.py
Source:00979_live_view_watch_continuous_aggregates.py
...8log = None9# uncomment the line below for debugging10#log=sys.stdout11with client(name='client1>', log=log) as client1, client(name='client2>', log=log) as client2:12 client1.expect(prompt)13 client2.expect(prompt)14 client1.send('SET allow_experimental_live_view = 1')15 client1.expect(prompt)16 client2.send('SET allow_experimental_live_view = 1')17 client2.expect(prompt)18 client1.send('DROP TABLE IF EXISTS test.lv')19 client1.expect(prompt)20 client1.send('DROP TABLE IF EXISTS test.mt')21 client1.expect(prompt)22 client1.send('CREATE TABLE test.mt (time DateTime, location String, temperature UInt32) Engine=MergeTree order by tuple()')23 client1.expect(prompt)24 client1.send('CREATE LIVE VIEW test.lv AS SELECT toStartOfDay(time) AS day, location, avg(temperature) FROM test.mt GROUP BY day, location ORDER BY day, location')25 client1.expect(prompt)26 client1.send('WATCH test.lv FORMAT CSVWithNames')27 client1.expect(r'_version')28 client2.send("INSERT INTO test.mt VALUES ('2019-01-01 00:00:00','New York',60),('2019-01-01 00:10:00','New York',70)")29 client2.expect(prompt)30 client1.expect(r'"2019-01-01 00:00:00","New York",65')31 client2.send("INSERT INTO test.mt VALUES ('2019-01-01 00:00:00','Moscow',30),('2019-01-01 00:10:00', 'Moscow', 40)")32 client2.expect(prompt)33 client1.expect(r'"2019-01-01 00:00:00","Moscow",35')34 client1.expect(r'"2019-01-01 00:00:00","New York",65')35 client2.send("INSERT INTO test.mt VALUES ('2019-01-02 00:00:00','New York',50),('2019-01-02 00:10:00','New York',60)")36 client2.expect(prompt)37 client1.expect(r'"2019-01-01 00:00:00","Moscow",35')38 client1.expect(r'"2019-01-01 00:00:00","New York",65')39 client1.expect(r'"2019-01-02 00:00:00","New York",55')40 client2.send("INSERT INTO test.mt VALUES ('2019-01-02 00:00:00','Moscow',20),('2019-01-02 00:10:00', 'Moscow', 30)")41 client2.expect(prompt)42 client1.expect(r'"2019-01-01 00:00:00","Moscow",35')43 client1.expect(r'"2019-01-01 00:00:00","New York",65')44 client1.expect(r'"2019-01-02 00:00:00","Moscow",25')45 client1.expect(r'"2019-01-02 00:00:00","New York",55')46 client2.send("INSERT INTO test.mt VALUES ('2019-01-02 00:03:00','New York',40),('2019-01-02 00:06:00','New York',30)")47 client2.expect(prompt)48 client1.expect(r'"2019-01-01 00:00:00","Moscow",35')49 client1.expect(r'"2019-01-01 00:00:00","New York",65')50 client1.expect(r'"2019-01-02 00:00:00","Moscow",25')51 client1.expect(r'"2019-01-02 00:00:00","New York",45')52 # send Ctrl-C53 client1.send('\x03', eol='')54 match = client1.expect('(%s)|([#\$] )' % prompt)55 if match.groups()[1]:56 client1.send(client1.command)57 client1.expect(prompt) 58 client1.send('DROP TABLE test.lv')59 client1.expect(prompt)60 client1.send('DROP TABLE test.mt')...
01246_insert_into_watch_live_view.py
Source:01246_insert_into_watch_live_view.py
...9log = None10# uncomment the line below for debugging11#log=sys.stdout12with client(name='client1>', log=log) as client1, client(name='client2>', log=log) as client2, client(name='client3>', log=log) as client3:13 client1.expect(prompt)14 client2.expect(prompt)15 client3.expect(prompt)16 client1.send('SET allow_experimental_live_view = 1')17 client1.expect(prompt)18 client3.send('SET allow_experimental_live_view = 1')19 client3.expect(prompt)20 client1.send('DROP TABLE IF EXISTS test.lv')21 client1.expect(prompt)22 client1.send('DROP TABLE IF EXISTS test.mt')23 client1.expect(prompt)24 client1.send('DROP TABLE IF EXISTS test.sums')25 client1.expect(prompt)26 client1.send('CREATE TABLE test.mt (a Int32) Engine=MergeTree order by tuple()')27 client1.expect(prompt)28 client1.send('CREATE LIVE VIEW test.lv AS SELECT sum(a) AS s FROM test.mt')29 client1.expect(prompt)30 client1.send('CREATE TABLE test.sums (s Int32, version Int32) Engine=MergeTree ORDER BY tuple()')31 client1.expect(prompt)32 client3.send('CREATE LIVE VIEW test.lv_sums AS SELECT * FROM test.sums ORDER BY version')33 client3.expect(prompt)34 client3.send("WATCH test.lv_sums FORMAT CSVWithNames")35 client3.expect('_version')36 client1.send('INSERT INTO test.sums WATCH test.lv')37 client1.expect(r'INSERT INTO')38 client1.expect(r'Progress')39 40 client3.expect('0,1.*\r\n')41 client2.send('INSERT INTO test.mt VALUES (1),(2),(3)')42 client2.expect(prompt)43 client3.expect('6,2.*\r\n')44 client2.send('INSERT INTO test.mt VALUES (4),(5),(6)')45 client2.expect(prompt)46 client3.expect('21,3.*\r\n')47 # send Ctrl-C48 client3.send('\x03', eol='')49 match = client3.expect('(%s)|([#\$] )' % prompt)50 if match.groups()[1]:51 client3.send(client3.command)52 client3.expect(prompt)53 # send Ctrl-C54 client1.send('\x03', eol='')55 match = client1.expect('(%s)|([#\$] )' % prompt)56 if match.groups()[1]:57 client1.send(client1.command)58 client1.expect(prompt) 59 client2.send('DROP TABLE test.lv')60 client2.expect(prompt)61 client2.send('DROP TABLE test.lv_sums')62 client2.expect(prompt)63 client2.send('DROP TABLE test.sums')64 client2.expect(prompt)65 client2.send('DROP TABLE test.mt')...
Using AI Code Generation
1var expect = require('chai').expect;2describe('Array', function() {3 describe('#indexOf()', function() {4 it('should return -1 when the value is not present', function() {5 expect([1,2,3].indexOf(4)).to.equal(-1);6 });7 });8});9var should = require('chai').should();10describe('Array', function() {11 describe('#indexOf()', function() {12 it('should return -1 when the value is not present', function() {13 [1,2,3].indexOf(4).should.equal(-1);14 });15 });16});17var assert = require('chai').assert;18describe('Array', function() {19 describe('#indexOf()', function() {20 it('should return -1 when the value is not present', function() {21 assert.equal([1,2,3].indexOf(4), -1);22 });23 });24});25var expect = require('chai').expect;26describe('Array', function() {27 describe('#indexOf()', function() {28 it('should return -1 when the value is not present', function() {29 expect([1,2,3].indexOf(4)).to.equal(-1);30 });31 });32});33var should = require('chai').should();34describe('Array', function() {35 describe('#indexOf()', function() {36 it('should return -1 when the value is not present', function() {37 [1,2,3].indexOf(4).should.equal(-1);38 });39 });40});41var assert = require('chai').assert;42describe('Array', function() {43 describe('#indexOf()', function() {44 it('should return -1 when the value is not present', function() {45 assert.equal([1,2,3].indexOf(4), -1);46 });47 });48});49var expect = require('chai').expect;50describe('Array', function() {51 describe('#indexOf()', function() {52 it('should
Using AI Code Generation
1const expect = require('chai').expect;2const assert = require('chai').assert;3const should = require('chai').should();4const add = require('../src/calculator').add;5describe('calculator', () => {6 describe('add', () => {7 it('should add two numbers', () => {8 expect(add(1, 2)).to.equal(3);9 assert.equal(add(1, 2), 3);10 add(1, 2).should.equal(3);11 });12 });13});14exports.add = (a, b) => {15 return a + b;16};17{18 "scripts": {19 },20 "devDependencies": {21 }22}23{24 "dependencies": {25 "ansi-styles": {26 "requires": {27 }28 },29 "chalk": {
Using AI Code Generation
1var expect = require('chai').expect;2var assert = require('chai').assert;3var should = require('chai').should();4var should = require('chai').should();5describe('Test for Chai', function() {6 it('should return -1 when the value is not present', function() {7 assert.equal([1,2,3].indexOf(4), -1);8 });9});10describe('Test for Chai', function() {11 it('should return -1 when the value is not present', function() {12 expect([1,2,3].indexOf(4)).to.equal(-1);13 });14});15describe('Test for Chai', function() {16 it('should return -1 when the value is not present', function() {17 [1,2,3].indexOf(4).should.equal(-1);18 });19});20describe('Test for Chai', function() {21 it('should return -1 when the value is not present', function() {22 expect([1,2,3].indexOf(4)).to.equal(-1);23 });24});25describe('Test for Chai', function() {26 it('should return -1 when the value is not present', function() {27 [1,2,3].indexOf(4).should.equal(-1);28 });29});30describe('Test for Chai', function() {31 it('should return -1 when the value is not present', function() {32 [1,2,3].indexOf(4).should.equal(-1);33 });34});35describe('Test for Chai', function() {36 it('should return -1 when the value is not present', function() {37 [1,2,3].indexOf(4).should.equal(-1);38 });39});40describe('Test for Chai', function() {41 it('should return -1 when the value is not present', function() {42 [1,2,3].indexOf(4).should.equal(-1);43 });44});45describe('Test for Chai', function() {46 it('should return -1 when the value is not present', function() {47 [1,2,3].indexOf(4).should.equal(-1);48 });49});50describe('Test for Chai',
Using AI Code Generation
1const expect = require('chai').expect;2const addNumbers = require('../app').addNumbers;3describe('addNumbers()', function() {4 it('should add two numbers', function() {5 const result = addNumbers(5,5);6 expect(result).to.equal(10);7 });8});9function addNumbers(num1, num2) {10 return num1 + num2;11}12module.exports = {13};14{15 "scripts": {16 },17 "devDependencies": {18 }19}20const expect = require('chai').expect;21const addNumbers = require('../app').addNumbers;22describe('addNumbers()', function() {23 it('should add two numbers', function() {24 const result = addNumbers(5,5);25 expect(result).to.equal(10);26 });27});28function addNumbers(num1, num2) {29 return num1 + num2;30}31module.exports = {32};33{34 "scripts": {35 },36 "devDependencies": {37 }38}39const expect = require('chai').expect;40const addNumbers = require('../app').addNumbers;
Using AI Code Generation
1var expect = require('chai').expect;2var request = require('request');3it('Status', function(done) {4 expect(response.statusCode).to.equal(200);5 done();6 });7});8it('Content-Type', function(done) {9 expect(response.headers['content-type']).to.equal("text/html; charset=utf-8");10 done();11 });12});13it('Content', function(done) {14 expect(body).to.equal('Hello World');15 done();16 });17});18it('Value', function(done) {19 expect(body).to.equal('Hello World');20 done();21 });22});23it('Value', function(done) {24 expect(body).to.equal('Hello World');25 done();26 });27});28it('Value', function(done) {29 expect(body).to.equal('Hello World');30 done();31 });32});33it('Value', function(done) {34 expect(body).to.equal('Hello World');35 done();36 });37});38it('Value', function(done) {39 expect(body).to.equal('Hello World');40 done();41 });42});43it('Value', function(done) {44 expect(body).to.equal
Using AI Code Generation
1var expect = require('chai').expect;2var test = require('../test.js');3describe('test', function() {4 it('should return 5', function() {5 expect(test()).to.equal(5);6 });7});8module.exports = function() {9 return 5;10};11{12 "scripts": {13 },14 "devDependencies": {15 }16}17 1 passing (9ms)18 1 passing (9ms)19 1 passing (9ms)20 1 passing (9ms)
Using AI Code Generation
1const expect = require('chai').expect;2const app = require('../app');3describe('App', function(){4 it('app should return hello', function(){5 let result = app.sayHello();6 expect(result).to.equal('hello');7 });8 it('app should return type string', function(){9 let result = app.sayHello();10 expect(result).to.be.a('string');11 });12});13module.exports = {14 sayHello: function(){15 return 'hello';16 }17}182 passing (7ms)191 passing (5ms)202 passing (4ms)212 passing (3ms)222 passing (2ms)
Using AI Code Generation
1const {expect} = require('chai');2const {isOddOrEven} = require('./isOddOrEven');3describe('isOddOrEven', function () {4 it('should return undefined with a number parameter', function () {5 expect(isOddOrEven(13)).to.equal(undefined, 'Function did not return the correct result!');6 });7 it('should return undefined with an object parameter', function () {8 expect(isOddOrEven({name: 'pesho'})).to.equal(undefined, 'Function did not return the correct result!');9 });10 it('should return correct result with an even length', function () {11 expect(isOddOrEven('roar')).to.equal('even', 'Function did not return the correct result!');12 });13 it('should return correct result with an odd length', function () {14 expect(isOddOrEven('pesho')).to.equal('odd', 'Function did not return the correct result!');15 });16});17function isOddOrEven(string) {18 if (typeof(string) !== 'string') {19 return undefined;20 }21 if (string.length % 2 == 0) {22 return 'even';23 }24 return 'odd';25}26module.exports = {isOddOrEven};27{28 "scripts": {29 },30 "devDependencies": {31 }32}
Using AI Code Generation
1const expect = require('chai').expect;2const calculator = require('../calculator.js');3describe("Calculator App", function() {4 describe("Addition Tests", function() {5 it("should return 42", function() {6 expect(calculator.add(40, 2)).to.equal(42);7 });8 it("should return 26", function() {9 expect(calculator.add(20, 6)).to.equal(26);10 });11 it("should return an error if we don't supply two numbers", function() {12 expect(calculator.add("Hitchhikers", "Guide")).to.equal("Error!");13 });14 });15});16The expect() method is used to assert that the actual value is equal to the expected value. The first expect() method is used to assert that the actual value returned by the addition function is equal to the expected value 42. The second expect() method is used to assert that the actual value returned by the addition function is equal to the expected value 26
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!