@@ -29,8 +29,11 @@ def assertAssemblesTo(self, source, expected):
2929 f"Assembling { source !r} : Expected { expected_bin } , got { actual_bin } " ,
3030 )
3131
32- def assertAssemblyFails (self , source ):
33- self .assertRaises (RuntimeError , adafruit_pioasm .assemble , source )
32+ def assertAssemblyFails (self , source , match = None , errtype = RuntimeError ):
33+ if match :
34+ self .assertRaisesRegex (errtype , match , adafruit_pioasm .assemble , source )
35+ else :
36+ self .assertRaises (errtype , adafruit_pioasm .assemble , source )
3437
3538 def testNonsense (self ):
3639 self .assertAssemblyFails ("nope" )
@@ -52,6 +55,18 @@ def testSidesetOpt(self):
5255 )
5356 self .assertAssemblesTo (".side_set 1 opt\n nop [1]" , [0b101_00001_010_00_010 ])
5457
58+ def testMov (self ):
59+ # non happy path
60+ self .assertAssemblyFails (
61+ "mov x, blah" , match = "Invalid mov source 'blah'" , errtype = ValueError
62+ )
63+
64+ def testSet (self ):
65+ # non happy path
66+ self .assertAssemblyFails (
67+ "set isr, 1" , match = "Invalid set destination 'isr'" , errtype = ValueError
68+ )
69+
5570 def testJmp (self ):
5671 self .assertAssemblesTo ("l:\n jmp l" , [0b000_00000_000_00000 ])
5772 self .assertAssemblesTo ("l:\n jmp 7" , [0b000_00000_000_00111 ])
@@ -63,6 +78,10 @@ def testJmp(self):
6378 self .assertAssemblesTo ("jmp x!=y, l\n l:" , [0b000_00000_101_00001 ])
6479 self .assertAssemblesTo ("jmp pin, l\n l:" , [0b000_00000_110_00001 ])
6580 self .assertAssemblesTo ("jmp !osre, l\n l:" , [0b000_00000_111_00001 ])
81+ # non happy path
82+ self .assertAssemblyFails (
83+ "jmp x--., l\n l:" , match = "Invalid jmp condition 'x--.'" , errtype = ValueError
84+ )
6685
6786 def testWait (self ):
6887 self .assertAssemblesTo ("wait 0 gpio 0" , [0b001_00000_0_00_00000 ])
0 commit comments