Skip to content

Commit

Permalink
Fix merge output and diff color, add tests (idaholab#19001)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Oct 21, 2021
1 parent 4d81a65 commit 8eb9113
Show file tree
Hide file tree
Showing 10 changed files with 307 additions and 10 deletions.
14 changes: 9 additions & 5 deletions framework/contrib/hit/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -529,9 +529,6 @@ merge(int argc, char ** argv)
return 1;
}

std::string fname(flags.val("output"));
std::ofstream output(fname);

hit::Node * root = nullptr;
for (int i = 0; i < positional.size(); i++)
{
Expand All @@ -545,7 +542,14 @@ merge(int argc, char ** argv)
root = hit::parse(fname, input);
}

output << root->render();
std::string fname(flags.val("output"));
if (fname == "-")
std::cout << root->render();
else
{
std::ofstream output(fname);
output << root->render();
}

return 0;
}
Expand Down Expand Up @@ -580,7 +584,7 @@ diff(int argc, char ** argv)
return 1;
}

bool use_color = flags.have("C");
bool use_color = flags.have("C") || flags.have("color");

// terminal colors
std::string color_red = use_color ? "\33[31m" : "";
Expand Down
57 changes: 57 additions & 0 deletions test/tests/misc/hit_cli/gold/diff_color
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Left hand side:
input1.i

Right hand side:
input2.i

Parameters removed left -> right:

[BCs]
[left]
type = DirichletBC
value = 0
variable = u
[]
[right]
type = NeumannBC
value = 0
variable = v
[]
[]
[Kernels]
[diff_u]
type = Diffusion
variable = u
[]
[diff_v]
type = Diffusion
variable = v
[]
[]

Parameters added left -> right:

[Outputs]
[out]
type = Exodus
[]
[]
[PostProcessor]
[max]
mode = MAX
type = Calculation
value = 1
[]
[min]
mode = min
type = Calculation
value = 1
[]
[]

Parameters with differing values:

PostProcessor/min2/value (input1.i:34) has differing values
'0' -> '1'


15 changes: 15 additions & 0 deletions test/tests/misc/hit_cli/gold/diff_common
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Left hand side:
input1.i

Right hand side:
input2.i

Common parameters:

[PostProcessor]
[min2]
mode = MIN
type = Calculation
[]
[]

57 changes: 57 additions & 0 deletions test/tests/misc/hit_cli/gold/diff_vanilla
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
Left hand side:
input1.i

Right hand side:
input2.i

Parameters removed left -> right:

[BCs]
[left]
type = DirichletBC
value = 0
variable = u
[]
[right]
type = NeumannBC
value = 0
variable = v
[]
[]
[Kernels]
[diff_u]
type = Diffusion
variable = u
[]
[diff_v]
type = Diffusion
variable = v
[]
[]

Parameters added left -> right:

[Outputs]
[out]
type = Exodus
[]
[]
[PostProcessor]
[max]
mode = MAX
type = Calculation
value = 1
[]
[min]
mode = min
type = Calculation
value = 1
[]
[]

Parameters with differing values:

PostProcessor/min2/value (input1.i:34) has differing values
'0' -> '1'


33 changes: 33 additions & 0 deletions test/tests/misc/hit_cli/gold/diff_verbose
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Left hand side:
input1.i

Right hand side:
input2.i

Parameters removed left -> right:
BCs/left/type (input1.i:19) is missing on the right.
BCs/left/value (input1.i:21) is missing on the right.
BCs/left/variable (input1.i:20) is missing on the right.
BCs/right/type (input1.i:24) is missing on the right.
BCs/right/value (input1.i:26) is missing on the right.
BCs/right/variable (input1.i:25) is missing on the right.
Kernels/diff_u/type (input1.i:8) is missing on the right.
Kernels/diff_u/variable (input1.i:9) is missing on the right.
Kernels/diff_v/type (input1.i:12) is missing on the right.
Kernels/diff_v/variable (input1.i:13) is missing on the right.

Parameters added left -> right:
Outputs/out/type (input2.i:8) is missing on the left.
PostProcessor/max/mode (input2.i:15) is missing on the left.
PostProcessor/max/type (input2.i:14) is missing on the left.
PostProcessor/max/value (input2.i:16) is missing on the left.
PostProcessor/min/mode (input2.i:20) is missing on the left.
PostProcessor/min/type (input2.i:19) is missing on the left.
PostProcessor/min/value (input2.i:21) is missing on the left.

Parameters with differing values:

PostProcessor/min2/value (input1.i:34) has differing values
'0' -> '1'


33 changes: 33 additions & 0 deletions test/tests/misc/hit_cli/gold/diff_verbose_color
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Left hand side:
input1.i

Right hand side:
input2.i

Parameters removed left -> right:
BCs/left/type (input1.i:19) is missing on the right.
BCs/left/value (input1.i:21) is missing on the right.
BCs/left/variable (input1.i:20) is missing on the right.
BCs/right/type (input1.i:24) is missing on the right.
BCs/right/value (input1.i:26) is missing on the right.
BCs/right/variable (input1.i:25) is missing on the right.
Kernels/diff_u/type (input1.i:8) is missing on the right.
Kernels/diff_u/variable (input1.i:9) is missing on the right.
Kernels/diff_v/type (input1.i:12) is missing on the right.
Kernels/diff_v/variable (input1.i:13) is missing on the right.

Parameters added left -> right:
Outputs/out/type (input2.i:8) is missing on the left.
PostProcessor/max/mode (input2.i:15) is missing on the left.
PostProcessor/max/type (input2.i:14) is missing on the left.
PostProcessor/max/value (input2.i:16) is missing on the left.
PostProcessor/min/mode (input2.i:20) is missing on the left.
PostProcessor/min/type (input2.i:19) is missing on the left.
PostProcessor/min/value (input2.i:21) is missing on the left.

Parameters with differing values:

PostProcessor/min2/value (input1.i:34) has differing values
'0' -> '1'


51 changes: 51 additions & 0 deletions test/tests/misc/hit_cli/gold/merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#
# This is not a valid MOOSE input, it is only used for testing the HIT command
# line utility.
#

[Kernels]
[diff_u]
type = Diffusion
variable = u
[]
[diff_v]
type = Diffusion
variable = v
[]
[]

[BCs]
[left]
type = DirichletBC
variable = u
value = 0
[]
[right]
type = NeumannBC
variable = v
value = 0
[]
[]

[PostProcessor]
[min2]
type = Calculation
mode = MIN
value = 1
[]
[max]
type = Calculation
mode = MAX
value = 1
[]
[min]
type = Calculation
mode = min
value = 1
[]
[]
[Outputs]
[out]
type = Exodus
[]
[]
3 changes: 2 additions & 1 deletion test/tests/misc/hit_cli/hit_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
with open(gold_file, 'rb') as f:
gold = f.read()

out = subprocess.check_output([hit] + hit_args)
result = subprocess.run([hit] + hit_args, capture_output=True)
out = result.stdout

if out == gold:
sys.exit(0)
Expand Down
8 changes: 8 additions & 0 deletions test/tests/misc/hit_cli/input1.i
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@
value = 0
[]
[]

[PostProcessor]
[min2]
type = Calculation
mode = MIN
value = 0
[]
[]
46 changes: 42 additions & 4 deletions test/tests/misc/hit_cli/tests
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
design = 'hit.md'

[find]
requirement = 'The hit find command shall be able to find'
requirement = 'The `hit find` command shall be able to find'
[parameter_exists]
type = RunCommand
command = './hit_wrapper.py gold/parameter_exists find Kernels/\*/variable input1.i input2.i'
Expand All @@ -29,13 +29,51 @@

[additional_pattern]
type = RunCommand
command = './hit_wrapper.py gold/additional_pattern find -p type=DirichletBC -- \*/value input1.i input2.i'
command = './hit_wrapper.py gold/additional_pattern find -p type=DirichletBC -- \*/value '
'input1.i input2.i'
detail = 'parameters with additional pattern constraints,'
[]
[additional_pattern_negative]
type = RunCommand
command = './hit_wrapper.py gold/additional_pattern_negative find -p type!=DirichletBC -- \*/value input1.i input2.i'
detail = 'parameters with additional pattern constraints,'
command = './hit_wrapper.py gold/additional_pattern_negative find -p type!=DirichletBC -- '
'\*/value input1.i input2.i'
detail = 'parameters with additional pattern constraints.'
[]
[]

[merge]
type = RunCommand
command = './hit_wrapper.py gold/merge merge -output - input1.i input2.i'
requirement = 'The `hit merge` command shall be able to combine input files.'
[]

[diff]
requirement = 'The `hit diff` command shall be able to'
[vanilla]
type = RunCommand
command = './hit_wrapper.py gold/diff_vanilla diff input1.i input2.i'
detail = 'show differences between input files,'
[]
[color]
type = RunCommand
command = './hit_wrapper.py gold/diff_color diff -color input1.i input2.i'
detail = 'show differences between input files marked up using terminal colors,'
[]
[verbose]
type = RunCommand
command = './hit_wrapper.py gold/diff_verbose diff -v input1.i input2.i'
detail = 'show differences between input files with verbose explanations,'
[]
[verbose_color]
type = RunCommand
command = './hit_wrapper.py gold/diff_verbose_color diff -v -color input1.i input2.i'
detail = 'show differences between input files with verbose explanations marked up using '
'terminal colors,'
[]
[common]
type = RunCommand
command = './hit_wrapper.py gold/diff_common diff -common input1.i input2.i'
detail = 'show common parameters/value pairs between input files,'
[]
[]
[]

0 comments on commit 8eb9113

Please sign in to comment.