How to use universalmutator - 10 common examples

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
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=")...")
        mutator.makeMutant(source, mutant, tmpMutantName)
        if compileFile is None:
            mutantResult = handler(tmpMutantName, mutant, sourceFile, uniqueMutants)
        else:
            mutantResult = handler(tmpMutantName, mutant, sourceFile, uniqueMutants, compileFile=compileFile)
        print(mutantResult, end=" ")
        mutantName = mdir + base + ".mutant." + str(mutantNo) + ending
        if (mutantResult == "VALID") or (mutantResult == "REDUNDANT" and redundantOK):
            print("[written to", mutantName + "]", end=" ")
            shutil.copy(tmpMutantName, mutantName)
            validMutants.append(mutant)
            mutantNo += 1
        elif mutantResult == "INVALID":
            invalidMutants.append(mutant)
        elif mutantResult == "REDUNDANT":
            redundantMutants.append(mutant)
        print()
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
github agroce / universalmutator / universalmutator / genmutants.py View on Github external
compilepos = -1

    if compilepos != -1:
        compileFile = args[compilepos + 1]
        args.remove("--compile")
        args.remove(compileFile)

    ignorePatterns = []
    if ignoreFile is not None:
        print("IGNORING PATTERNS DEFINED IN", ignoreFile)
        with open(ignoreFile, 'r') as ignoref:
            for l in ignoref:
                ignorePatterns.append(l[:-1])

    handlers = {"python": python_handler,
                "c": c_handler,
                "c++": cpp_handler,
                "cpp": cpp_handler,
                "java": java_handler,
                "swift": swift_handler,
                "rust": rust_handler,
                "go": go_handler,
                "solidity": solidity_handler,
                "vyper": vyper_handler}

    cLikeLanguages = [
        "c",
        "java",
        "swift",
        "cpp",
        "c++",
        "rust",
github agroce / universalmutator / universalmutator / genmutants.py View on Github external
if compilepos != -1:
        compileFile = args[compilepos + 1]
        args.remove("--compile")
        args.remove(compileFile)

    ignorePatterns = []
    if ignoreFile is not None:
        print("IGNORING PATTERNS DEFINED IN", ignoreFile)
        with open(ignoreFile, 'r') as ignoref:
            for l in ignoref:
                ignorePatterns.append(l[:-1])

    handlers = {"python": python_handler,
                "c": c_handler,
                "c++": cpp_handler,
                "cpp": cpp_handler,
                "java": java_handler,
                "swift": swift_handler,
                "rust": rust_handler,
                "go": go_handler,
                "solidity": solidity_handler,
                "vyper": vyper_handler}

    cLikeLanguages = [
        "c",
        "java",
        "swift",
        "cpp",
        "c++",
        "rust",
        "solidity",
        "go"]
github agroce / universalmutator / universalmutator / genmutants.py View on Github external
ignorePatterns = []
    if ignoreFile is not None:
        print("IGNORING PATTERNS DEFINED IN", ignoreFile)
        with open(ignoreFile, 'r') as ignoref:
            for l in ignoref:
                ignorePatterns.append(l[:-1])

    handlers = {"python": python_handler,
                "c": c_handler,
                "c++": cpp_handler,
                "cpp": cpp_handler,
                "java": java_handler,
                "swift": swift_handler,
                "rust": rust_handler,
                "go": go_handler,
                "solidity": solidity_handler,
                "vyper": vyper_handler}

    cLikeLanguages = [
        "c",
        "java",
        "swift",
        "cpp",
        "c++",
        "rust",
        "solidity",
        "go"]

    try:
        handlers["custom"] == custom_handler
    except BaseException:
github agroce / universalmutator / universalmutator / genmutants.py View on Github external
compileFile = args[compilepos + 1]
        args.remove("--compile")
        args.remove(compileFile)

    ignorePatterns = []
    if ignoreFile is not None:
        print("IGNORING PATTERNS DEFINED IN", ignoreFile)
        with open(ignoreFile, 'r') as ignoref:
            for l in ignoref:
                ignorePatterns.append(l[:-1])

    handlers = {"python": python_handler,
                "c": c_handler,
                "c++": cpp_handler,
                "cpp": cpp_handler,
                "java": java_handler,
                "swift": swift_handler,
                "rust": rust_handler,
                "go": go_handler,
                "solidity": solidity_handler,
                "vyper": vyper_handler}

    cLikeLanguages = [
        "c",
        "java",
        "swift",
        "cpp",
        "c++",
        "rust",
        "solidity",
        "go"]
github agroce / universalmutator / universalmutator / genmutants.py View on Github external
except ValueError:
        compilepos = -1

    if compilepos != -1:
        compileFile = args[compilepos + 1]
        args.remove("--compile")
        args.remove(compileFile)

    ignorePatterns = []
    if ignoreFile is not None:
        print("IGNORING PATTERNS DEFINED IN", ignoreFile)
        with open(ignoreFile, 'r') as ignoref:
            for l in ignoref:
                ignorePatterns.append(l[:-1])

    handlers = {"python": python_handler,
                "c": c_handler,
                "c++": cpp_handler,
                "cpp": cpp_handler,
                "java": java_handler,
                "swift": swift_handler,
                "rust": rust_handler,
                "go": go_handler,
                "solidity": solidity_handler,
                "vyper": vyper_handler}

    cLikeLanguages = [
        "c",
        "java",
        "swift",
        "cpp",
        "c++",
github agroce / universalmutator / universalmutator / genmutants.py View on Github external
args.remove(compileFile)

    ignorePatterns = []
    if ignoreFile is not None:
        print("IGNORING PATTERNS DEFINED IN", ignoreFile)
        with open(ignoreFile, 'r') as ignoref:
            for l in ignoref:
                ignorePatterns.append(l[:-1])

    handlers = {"python": python_handler,
                "c": c_handler,
                "c++": cpp_handler,
                "cpp": cpp_handler,
                "java": java_handler,
                "swift": swift_handler,
                "rust": rust_handler,
                "go": go_handler,
                "solidity": solidity_handler,
                "vyper": vyper_handler}

    cLikeLanguages = [
        "c",
        "java",
        "swift",
        "cpp",
        "c++",
        "rust",
        "solidity",
        "go"]

    try:
        handlers["custom"] == custom_handler
github agroce / universalmutator / universalmutator / genmutants.py View on Github external
ignorePatterns = []
    if ignoreFile is not None:
        print("IGNORING PATTERNS DEFINED IN", ignoreFile)
        with open(ignoreFile, 'r') as ignoref:
            for l in ignoref:
                ignorePatterns.append(l[:-1])

    handlers = {"python": python_handler,
                "c": c_handler,
                "c++": cpp_handler,
                "cpp": cpp_handler,
                "java": java_handler,
                "swift": swift_handler,
                "rust": rust_handler,
                "go": go_handler,
                "solidity": solidity_handler,
                "vyper": vyper_handler}

    cLikeLanguages = [
        "c",
        "java",
        "swift",
        "cpp",
        "c++",
        "rust",
        "solidity",
        "go"]

    try:
        handlers["custom"] == custom_handler
    except BaseException:
        pass