How to use the universalmutator.mutator function in universalmutator

To help you get started, we’ve selected a few universalmutator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agroce / universalmutator / universalmutator / genmutants.py View on Github external
else:
        handler = nullHandler
        noFastCheck = True

    deadCodeLines = []
    interestingLines = []

    tmpMutantName = ".tmp_mutant." + str(os.getpid()) + ending
    mutantNo = 0
    for mutant in mutants:
        if (lineFile is not None) and mutant[0] not in lines:
            # skip if not a line to mutate
            continue
        if (not noFastCheck) and (mutant[0] not in interestingLines) and (mutant[0] not in deadCodeLines):
            fastCheckMutant = (mutant[0], toGarbage(source[mutant[0] - 1]))
            mutator.makeMutant(source, fastCheckMutant, tmpMutantName)
            if compileFile is None:
                mutantResult = handler(tmpMutantName, mutant, sourceFile, uniqueMutants)
            else:
                mutantResult = handler(tmpMutantName, mutant, sourceFile, uniqueMutants, compileFile=compileFile)
            if mutantResult in ["VALID", "REDUNDANT"]:
                deadCodeLines.append(mutant[0])
                print("LINE", str(mutant[0]) + ":", source[mutant[0] - 1][:-1], end=" ")
                print("APPEARS TO BE COMMENT OR DEAD CODE, SKIPPING...")
            else:
                interestingLines.append(mutant[0])
        if mutant[0] in deadCodeLines:
            continue
        print("PROCESSING MUTANT:",
              str(mutant[0]) + ":", source[mutant[0] - 1][:-1], " ==> ", mutant[1][:-1], end="...")
        if showRules:
            print("(FROM:", mutant[2][1], end=")...")
github agroce / universalmutator / universalmutator / genmutants.py View on Github external
if language == "vyper":
        otherRules.append("python.rules")
        otherRules.append("solidity.rules")

    rules = ["universal.rules", language + ".rules"] + otherRules
    if fuzz:
        fuzzRules = ["universal.rules", "c_like.rules", "python.rules", "vyper.rules", "solidity.rules"]
        rules = list(set(fuzzRules + rules))

    source = []

    with open(sourceFile, 'r') as file:
        for l in file:
            source.append(l)

    mutants = mutator.mutants(source, ruleFiles=rules, mutateTestCode=mutateTestCode, mutateBoth=mutateBoth,
                              ignorePatterns=ignorePatterns, ignoreStringOnly=not mutateInStrings, fuzzing=fuzz)
    if fuzz:
        mutants = [random.choice(mutants)]  # Just pick one

    print(len(mutants), "MUTANTS GENERATED BY RULES")

    validMutants = []
    invalidMutants = []
    redundantMutants = []
    uniqueMutants = {}

    if not noCheck:
        if cmd is not None:
            handler = cmdHandler
        elif language == "none":
            handler = nullHandler