Skip to content

Add tests for preprocessor plugins #266

@JackTheWilliams

Description

@JackTheWilliams

SublimeKSP uses unittest for testing.
The documentation can be found here with instructions on how to run tests

We need tests to check if code if compiled correctly
We need tests to check if errors are identified correctly
Look at other tests for examples.

This is a good first issue if you are looking to contribute!
If you need any more guidance, feel free to contact me :))

Tests needed:

  • Additional Macro Tests
  • Const Blocks
  • Structs
  • UI Arrays
  • Multidimensional Arrays
  • Lists
  • Open Size Arrays
  • Persistence Handling
  • UI Functions (set_button_properties etc.)
  • String Array Initialisation
  • Array Concat

If you find any tests that are needed then please add!


Examples

Example for comparing outputs

class ForLoop(unittest.TestCase):
    def testForLoopBasic(self):
        code = '''
            on init
                declare i
                for i := 0 to 10
                  message(i)
                end for
            end on'''
        expected_output = '''
            on init
                declare $i
                $i := 0
                while ($i<=10)
                    message($i)
                    inc($i)
                end while
            end on'''
        output = do_compile(code, remove_preprocessor_vars=True)
        output = [l.strip() for l in output.split('\n') if l]
        expected_output = [l.strip() for l in expected_output.split('\n') if l]
        self.assertEqual(output, expected_output)

Example to check if a line is in the output

class PropertyTests(unittest.TestCase):
    def testAlias1(self):
        code = '''
        on init
          declare a
          property b -> a
          message(b)
        end on
        '''
        output = do_compile(code)
        self.assertTrue('message($a)' in output)

Example to check if an error raised

class TypeChecks(unittest.TestCase):
    def testAssignStringToIntVar1(self):
        code = '''
            on init
                declare x := 'test'
            end on'''
        self.assertRaises(ParseException, do_compile, code, extra_syntax_checks=True)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions