User:Bugman/subsystems: Difference between revisions

From FlightGear wiki
Jump to navigation Jump to search
(→‎Script: Newest version of the script.)
(Added another script.)
Line 2,632: Line 2,632:
if __name__ == "__main__":
if __name__ == "__main__":
     ToUpdate()
     ToUpdate()
}}
== Automated test suite test creation ==
This script was used to generate the instanced and non-instanced subsystem system tests:
{{collapsible script
| type  = Python script
| title  = Python script for generating the code for the system tests
| lang  = python
| script =
#! /usr/bin/env python3
# Other module imports.
from find_subsystems import FindSubsystems
class TestSuite:
    """Class for generating the code for the system tests."""
    def __init__(self):
        """Auto-generate the C++ code."""
        # First find all subsystems.
        sub = FindSubsystems(output=False)
        # The test name and test code.
        name = []
        code = []
        # Loop over all derived class declarations.
        max_width = 0
        for subsystem in sub.subsystems[0] + sub.subsystems[1] + sub.subsystems[2] + sub.subsystems[3] + sub.groups[0] + sub.groups[1] + sub.groups[2] + sub.groups[3]:
            # Skip non-instantiated base classes.
            if not subsystem.staticSubsystemClassId:
                continue
            # Add the test suite text.
            name.append("test%s" % (subsystem.name))
            code.append("{ create(\"%s\"); }" % (subsystem.staticSubsystemClassId))
            # Formatting.
            max_width = max(len(name[-1]), max_width)
        # Test setup printout.
        print("\n")
        print("    CPPUNIT_TEST_SUITE(NonInstancedSubsystemTests);")
        for i in range(len(name)):
            print("    CPPUNIT_TEST(%s);" % name[i])
        print("    CPPUNIT_TEST_SUITE_END();")
        # Test declaration printout.
        print("\n")
        print("    // The subsystem tests.")
        for i in range(len(name)):
            print("    void %s();" % name[i])
        # Test implementation printout.
        print("\n")
        format_str = "void NonInstancedSubsystemTests::%%-%is() %%-s" % max_width
        for i in range(len(name)):
            print(format_str % (name[i], code[i]))
# Instantiate the class if run as a script.
if __name__ == "__main__":
    TestSuite()
}}
}}

Revision as of 08:02, 8 May 2018

Tracking down subsystems

Script

The following script is for finding all FlightGear dependencies:

All subsystems

The result is:

Refactoring

To check that all subsystems on a branch have been updated or refactored:

Automated test suite test creation

This script was used to generate the instanced and non-instanced subsystem system tests: