All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.openapiprocessor.test.Diff.groovy Maven / Gradle / Ivy

There is a newer version: 2024.6.1
Show newest version
/*
 * Copyright 2024 https://github.com/openapi-processor/openapi-processor-base
 * PDX-License-Identifier: Apache-2.0
 */

package io.openapiprocessor.test

import com.github.difflib.DiffUtils
import com.github.difflib.UnifiedDiffUtils

import java.nio.file.Path

class Diff {

    /**
     * unified diff file path <=> file path
     *
     * @param expected file path
     * @param generated file path
     *
     * @return true if there is a difference
     */
    static boolean printUnifiedDiff (Path expected, Path generated) {
        def patch = DiffUtils.diff (
            expected.readLines (),
            generated.readLines ())

        def diff = UnifiedDiffUtils.generateUnifiedDiff (
            expected.toString (),
            generated.toString (),
            expected.readLines (),
            patch,
            4
        )

        if (!patch.deltas.isEmpty()) {
            println "$expected"
        }
        diff.each {
            println it
        }

        return !patch.deltas.isEmpty ()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy