Skip to content Navigation Menu Toggle navigation Sign in Appearance settings PlatformAI CODE CREATIONGitHub CopilotWrite better code with AIGitHub Copilot appDirect agents from issue to mergeMCP RegistryNewIntegrate external toolsDEVELOPER WORKFLOWSActionsAutomate any workflowCodespacesInstant dev environmentsIssuesPlan and track workCode ReviewManage code changesAPPLICATION SECURITYGitHub Advanced SecurityFind and fix vulnerabilitiesCode securitySecure your code as you buildSecret protectionStop leaks before they startEXPLOREWhy GitHubDocumentationBlogChangelogMarketplaceView all featuresSolutionsBY COMPANY SIZEEnterprisesSmall and medium teamsStartupsNonprofitsBY USE CASEApp ModernizationDevSecOpsDevOpsCI/CDView all use casesBY INDUSTRYHealthcareFinancial servicesManufacturingGovernmentView all industriesView all solutionsResourcesEXPLORE BY TOPICAISoftware DevelopmentDevOpsSecurityView all topicsEXPLORE BY TYPECustomer storiesEvents & webinarsEbooks & reportsBusiness insightsGitHub SkillsSUPPORT & SERVICESDocumentationCustomer supportCommunity forumTrust centerPartnersView all resourcesOpen SourceCOMMUNITYGitHub SponsorsFund open source developersPROGRAMSSecurity LabMaintainer CommunityAcceleratorGitHub StarsArchive ProgramREPOSITORIESTopicsTrendingCollectionsEnterpriseENTERPRISE SOLUTIONSEnterprise platformAI-powered developer platformAVAILABLE ADD-ONSGitHub Advanced SecurityEnterprise-grade security featuresCopilot for BusinessEnterprise-grade AI featuresPremium SupportEnterprise-grade 24/7 supportPricing Search or jump to... Search code, repositories, users, issues, pull requests... Search Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. Include my email address so I can be contacted Saved searches Use saved searches to filter your results more quickly Name Query To see all available qualifiers, see our documentation. Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} github / codeql Public Notifications You must be signed in to change notification settings Fork 2k Star 9.7k Code Issues 983 Pull requests 419 Discussions Actions Projects Models Security and quality 0 Insights Additional navigation options Code Issues Pull requests Discussions Actions Projects Models Security and quality Insights FilesExpand file tree codeql-cli/v2.25.0Breadcrumbscodeql/misc/codegen/generators/rusttestgen.pyCopy pathBlameMore file actionsBlameMore file actions Latest commit HistoryHistoryHistory93 lines (79 loc) · 2.69 KB codeql-cli/v2.25.0Breadcrumbscodeql/misc/codegen/generators/rusttestgen.pyCopy pathTopFile metadata and controlsCodeBlame93 lines (79 loc) · 2.69 KBRawCopy raw fileDownload raw fileOpen symbols panelEdit and raw actions123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293import dataclassesimport typingfrom collections.abc import Iterable import inflection from misc.codegen.loaders import schemaloaderfrom . import qlgen @dataclasses.dataclassclass Param: name: str type: str first: bool = False @dataclasses.dataclassclass Function: name: str signature: str @dataclasses.dataclassclass TestCode: template: typing.ClassVar[str] = "rust_test_code" code: str function: Function | None = None def _get_code(doc: list[str]) -> list[str]: adding_code = False has_code = False code = [] for line in doc: match line, adding_code: case ("```", _) | ("```rust", _): adding_code = not adding_code has_code = True case _, False: code.append(f"// {line}") case _, True: code.append(line) assert not adding_code, "Unterminated code block in docstring:\n " + "\n ".join( doc ) if has_code: return code return [] def generate(opts, renderer): assert opts.ql_test_output schema = schemaloader.load_file(opts.schema) with renderer.manage( generated=opts.ql_test_output.rglob("gen_*.rs"), stubs=(), registry=opts.ql_test_output / ".generated_tests.list", force=opts.force, ) as renderer: resolver = qlgen.Resolver(schema.classes) for cls in schema.classes.values(): if cls.imported: continue if resolver.should_skip_qltest(cls) or "rust_skip_doc_test" in cls.pragmas: continue code = _get_code(cls.doc) for p in schema.iter_properties(cls.name): if "rust_skip_doc_test" in p.pragmas: continue property_code = _get_code(p.description) if property_code: code.append(f"// # {p.name}") code += property_code if not code: continue test_name = inflection.underscore(cls.name) signature = cls.pragmas.get("rust_doc_test_signature", "() -> ()") fn = signature and Function(f"test_{test_name}", signature) if fn: indent = 4 * " " code = [indent + l for l in code] test_with_name = typing.cast(str, cls.pragmas.get("qltest_test_with")) test_with = schema.classes[test_with_name] if test_with_name else cls test = ( opts.ql_test_output / test_with.group / test_with.name / f"gen_{test_name}.rs" ) renderer.render(TestCode(code="\n".join(code), function=fn), test) You can’t perform that action at this time.