Skip to content

Commit

Permalink
adjust command and input/output sections and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RZ9082 committed Dec 4, 2024
1 parent c4f6fed commit 6cc4955
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 50 deletions.
121 changes: 71 additions & 50 deletions tools/diff/diff.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<tool id="diff" name="diff" version="@TOOL_VERSION@+galaxy@GALAXY_VERSION@" profile="23.0">
<tool id="diff" name="diff" version="@TOOL_VERSION@+galaxy@GALAXY_VERSION@">
<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>
Expand All @@ -14,17 +14,20 @@
</stdio>
<command><![CDATA[
diff
#if $report_format.report_format_select in ['txt_lines', '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
#if $HTML_report.HTML_report_select == 'yes'
## the --unified option is needed to convert the output later to HTML
--unified=$HTML_report.unified
#else
#if $HTML_report.output_format_raw.output_format_raw_select == 'txt_lines'
--unified=$HTML_report.output_format_raw.unified
#elif $HTML_report.output_format_raw.output_format_raw_select == 'txt_columns'
-y
#end if
#end if
'$input1' '$input2' > '$diff_file'
#if $report_format.report_format_select == 'html':
&&
'$input1' '$input2' > '$diff_file';
#if $HTML_report.HTML_report_select == 'yes'
sed -e 's/@@title@@/Diff report for "$input1.element_identifier" and "$input2.element_identifier"/g'
-e 's/@@outputformat@@/'$report_format_select.output_format'/g'
-e 's/@@outputformat@@/'$HTML_report.output_format_html_select'/g'
-e '/@@diffoutput@@/{r'$diff_file'' -e ';d}'
'$__tool_directory__/template.html' > '$html_file'
#end if
Expand All @@ -33,37 +36,45 @@
<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>
<conditional name="HTML_report">
<param name="HTML_report_select" type="select" label="Generate an HTML report?" help="Generates an HTML report to visualize the differences">
<option value="yes">Yes</option>
<option value="no">No</option>
</param>
<when value="txt_lines">
<when value="yes">
<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 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.">
<param name="output_format_html_select" type="select" label="Choose HTML report output format" help="Displays the differences in the HTML 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>
<when value="no">
<conditional name="output_format_raw">
<param name="output_format_raw_select" type="select" label="Choose report output format" help="Displays the differences in the raw output using the selected format. Either line by line or side by side.">
<option value="">None</option>
<option value="txt_lines">Text file, line-by-line (-u)</option>
<option value="txt_columns">Text file, side-by-side (-y)</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="" />
</conditional>
</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 format="txt" name="diff_file" label="${tool.name} on ${on_string}: Raw Output"/>
<data format="html" name="html_file" label="${tool.name} on ${on_string}: Html Report">
<filter>HTML_report['HTML_report_select'] == 'yes'</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>
<param name="HTML_report_select" value="no"/>
<output name="diff_file">
<assert_contents>
<has_n_lines n="0"/>
Expand All @@ -73,23 +84,40 @@
<test expect_exit_code="1" 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>
<param name="HTML_report_select" value="no"/>
<output name="diff_file">
<assert_contents>
<has_n_lines n="2"/>
<has_line line="1a2"/>
<has_line line="> b"/>
</assert_contents>
</output>
</test>
<test expect_exit_code="1" expect_failure="false" expect_num_outputs="1">
<param name="input1" value="file1.txt"/>
<param name="input2" value="file2.txt"/>
<param name="HTML_report_select" value="no"/>
<param name="output_format_raw_select" value="txt_lines"/>
<param name="unified" value="4"/>
<output name="diff_file">
<assert_contents>
<has_n_lines n="5"/>
<has_line line=" a"/>
<has_line line="+b"/>
<has_n_lines n="5" />
<has_line line=" a" />
<has_line line="+b" />
</assert_contents>
</output>
</test>
<test expect_exit_code="1" expect_failure="false" expect_num_outputs="1">
<param name="input1" value="file1.txt"/>
<param name="input2" value="file2.txt"/>
<param name="HTML_report_select" value="no"/>
<param name="output_format_raw_select" value="txt_columns"/>
<output name="diff_file" file="output_test4.txt" />
</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>
<param name="HTML_report_select" value="yes"/>
<output name="html_file">
<assert_contents>
<has_text text="!DOCTYPE html"/>
Expand All @@ -99,10 +127,8 @@
<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>
<param name="HTML_report_select" value="yes"/>
<param name="output_format_html_select" value="side-by-side"/>
<output name="html_file">
<assert_contents>
<has_text text="!DOCTYPE html"/>
Expand All @@ -113,10 +139,8 @@
<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>
<param name="HTML_report_select" value="yes"/>
<param name="output_format_html_select" value="line-by-line"/>
<output name="html_file">
<assert_contents>
<has_text text="!DOCTYPE html"/>
Expand All @@ -125,12 +149,9 @@
</output>
</test>
<test expect_exit_code="0" expect_failure="false" expect_num_outputs="2">
<param name="input1" value="file 3.txt"/>
<param name="input2" value="file 3.txt"/>
<conditional name="report_format">
<param name="report_format_select" value="html"/>
<param name="output_format" value="side-by-side"/>
</conditional>
<param name="input1" value="file3.txt"/>
<param name="input2" value="file3.txt"/>
<param name="HTML_report_select" value="yes"/>
<output name="diff_file">
<assert_contents>
<has_n_lines n="0"/>
Expand Down Expand Up @@ -202,4 +223,4 @@ An **optional** *HTML report* with a friendlier visual representation of the dif
}
</citation>
</citations>
</tool>
</tool>
File renamed without changes.
2 changes: 2 additions & 0 deletions tools/diff/test-data/output_test4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
a a
> b

0 comments on commit 6cc4955

Please sign in to comment.