view diff.xml @ 4:10ef1bf99074 draft default tip

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/diff commit 1a6c4a793ef68a43de93316523c1cd9196d80b73
author bgruening
date Mon, 09 Dec 2024 14:36:40 +0000
parents 156d0908e232
children
line wrap: on
line source

<tool id="diff" name="diff" version="@TOOL_VERSION@+galaxy@GALAXY_VERSION@" profile="23.0">
    <description>analyzes two files and generates an unidiff text file with information about the differences and an optional Html report</description>
    <macros>
        <token name="@TOOL_VERSION@">3.10</token>
        <token name="@GALAXY_VERSION@">0</token>
    </macros>
    <requirements>
        <requirement type="package" version="@TOOL_VERSION@">diffutils</requirement>
        <requirement type="package" version="4.8">sed</requirement>
    </requirements>
    <stdio>
        <exit_code range="2:" level="fatal" description="Something went wrong trying to check differences in files. Please check output log for more details."/>
        <regex match="diff: memory exhausted" source="stdout" level="fatal_oom" description="Out of memory error occurred"/>
    </stdio>
    <command><![CDATA[
        diff
        #if $report_format.report_format_select == 'txt_lines' or $report_format.report_format_select == 'html'
            ## the -u option is needed to convert the output later to HTML
            --unified=$report_format.unified
        #else if $report_format.report_format_select == 'txt_columns'
            -y
        #end if
        ## If the compared input files differ the diff command returns exit-code 1
        '$input1' '$input2' > '$diff_file' || [ \$? -eq 1 ];
        #if $report_format.report_format_select == 'html'
            sed -e 's/@@title@@/Diff report for "$input1.element_identifier" and "$input2.element_identifier"/g'
                -e 's/@@outputformat@@/'$report_format.output_format'/g'
                -e '/@@diffoutput@@/{r'$diff_file'' -e ';d}'
                '$__tool_directory__/template.html' > '$html_file'
        #end if
    ]]>
    </command>
    <inputs>
        <param name="input1" type="data" format="txt" label="First input file"/>
        <param name="input2" type="data" format="txt" label="Second input file"/>
        <conditional name="report_format">
            <param name="report_format_select" type="select" label="Choose a report format">
                <option value="txt_lines">Text file, line-by-line (-u)</option>
                <option value="txt_columns">Text file, side-by-side (-y)</option>
                <option value="html">Generates an HTML report to visualize the differences</option>
            </param>
            <when value="txt_lines">
                <param argument="--unified" type="integer" min="0" value="3" label="Output this amount of lines of unified context"/>
            </when>
            <when value="txt_columns"/>
            <when value="html">
                <param argument="--unified" type="integer" min="0" value="3" label="Output this amount of lines of unified context"/>
                <param name="output_format" type="select" label="Choose report output format" help="Displays the differences in the report using the selected format. Either line by line or side by side.">
                    <option value="side-by-side">Side by side</option>
                    <option value="line-by-line">Line by line</option>
                </param>
            </when>
        </conditional>
    </inputs>
    <outputs>
        <data format="txt" name="diff_file" from_work_dir="output.txt" label="${tool.name} on ${on_string}: Raw Output"/>
        <data format="html" name="html_file" from_work_dir="output.html" label="${tool.name} on ${on_string}: Html Report">
            <filter>report_format['report_format_select'] == 'html'</filter>
        </data>
    </outputs>
    <tests>
        <test expect_exit_code="0" expect_failure="false" expect_num_outputs="1">
            <param name="input1" value="file1.txt"/>
            <param name="input2" value="file1.txt"/>
            <conditional name="report_format">
                <param name="report_format_select" value="txt_lines"/>
            </conditional>
            <output name="diff_file">
                <assert_contents>
                    <has_n_lines n="0"/>
                </assert_contents>
            </output>
        </test>
        <test expect_exit_code="0" expect_failure="false" expect_num_outputs="1">
            <param name="input1" value="file1.txt"/>
            <param name="input2" value="file2.txt"/>
            <conditional name="report_format">
                <param name="report_format_select" value="txt_lines"/>
            </conditional>
            <output name="diff_file">
                <assert_contents>
                    <has_n_lines n="5"/>
                    <has_line line=" a"/>
                    <has_line line="+b"/>
                </assert_contents>
            </output>
        </test>
        <test expect_exit_code="0" expect_failure="false" expect_num_outputs="2">
            <param name="input1" value="file1.txt"/>
            <param name="input2" value="file2.txt"/>
            <conditional name="report_format">
                <param name="report_format_select" value="html"/>
            </conditional>
            <output name="html_file">
                <assert_contents>
                    <has_text text="!DOCTYPE html"/>
                </assert_contents>
            </output>
        </test>
        <test expect_exit_code="0" expect_failure="false" expect_num_outputs="2">
            <param name="input1" value="file1.txt"/>
            <param name="input2" value="file2.txt"/>
            <conditional name="report_format">
                <param name="report_format_select" value="html"/>
                <param name="output_format" value="side-by-side"/>
            </conditional>
            <output name="html_file">
                <assert_contents>
                    <has_text text="!DOCTYPE html"/>
                    <has_text text="side-by-side"/>
                </assert_contents>
            </output>
        </test>
        <test expect_exit_code="0" expect_failure="false" expect_num_outputs="2">
            <param name="input1" value="file1.txt"/>
            <param name="input2" value="file2.txt"/>
            <conditional name="report_format">
                <param name="report_format_select" value="html"/>
                <param name="output_format" value="line-by-line"/>
            </conditional>
            <output name="html_file">
                <assert_contents>
                    <has_text text="!DOCTYPE html"/>
                    <has_text text="line-by-line"/>
                </assert_contents>
            </output>
        </test>
        <test expect_exit_code="0" expect_failure="false" expect_num_outputs="2">
            <param name="input1" value="file3.txt"/>
            <param name="input2" value="file3.txt"/>
            <conditional name="report_format">
                <param name="report_format_select" value="html"/>
                <param name="output_format" value="side-by-side"/>
            </conditional>
            <output name="diff_file">
                <assert_contents>
                    <has_n_lines n="0"/>
                </assert_contents>
            </output>
            <output name="html_file">
                <assert_contents>
                    <has_text text="!DOCTYPE html"/>
                </assert_contents>
            </output>
        </test>
    </tests>
    <help><![CDATA[
.. class:: infomark

**Purpose**

The **diff** utility is a data comparison tool that calculates and displays the differences between two files.

Unlike edit distance notions used for other purposes, diff is line-oriented rather than character-oriented, but it is like Levenshtein distance in that it tries to determine the smallest set of deletions and insertions to create one file from the other.

The diff command displays the changes made in a standard format, such that both humans and machines can understand the changes and apply them: given one file and the changes, the other file can be created.

.. class:: infomark

**Input**

Two text files to be checked for differences line by line.

.. class:: infomark

**Output**

A *text file*, either:

- containing the lines differences in **unified format** (*unidiff*),

- or an **empty** file if the two input files are the same.

An **optional** *HTML report* with a friendlier visual representation of the differences.
    ]]>
    </help>
    <citations>
        <citation type="bibtex">
            @misc{gnudiffutils,
            author = {The Free Software Foundation (FSF), Inc},
            year = {2017},
            title = {diff (GNU diffutils)},
            publisher = {The Free Software Foundation (FSF), Inc},
            url = {http://www.gnu.org/software/diffutils/},
            }
        </citation>
        <citation type="bibtex">
            @misc{diff2html,
            author = {Rodrigo Fernandes},
            year = {2014},
            title = {Pretty diff to html javascript library (diff2html)},
            publisher = {Github},
            url = {https://github.com/rtfpessoa/diff2html},
            }
        </citation>
        <citation type="bibtex">
            @misc{sed,
            author = {The Free Software Foundation (FSF), Inc},
            year = {2017},
            title = {sed (GNU sed)},
            publisher = {The Free Software Foundation (FSF), Inc},
            url = {http://www.gnu.org/software/sed/},
            }
        </citation>
    </citations>
</tool>