Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cdo
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpim-sw
cdo
Commits
d0a8b37a
Commit
d0a8b37a
authored
2 years ago
by
Oliver Heidmann
Browse files
Options
Downloads
Patches
Plain Diff
cleanup, reorganization, added tests, fixed tests
parent
3681d894
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!26
parser cleanup and fixes
Pipeline
#33233
passed
2 years ago
Stage: build
Stage: check
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/bandit_tests/parser.cc
+221
-93
221 additions, 93 deletions
test/bandit_tests/parser.cc
with
221 additions
and
93 deletions
test/bandit_tests/parser.cc
+
221
−
93
View file @
d0a8b37a
#include
"bandit/bandit/bandit.h"
// BANDIT NEEDS TO BE INCLUDED FIRST!!!
#include
<iostream>
#include
<vector>
#include
<memory>
#include
<string>
#include
<iterator>
#include
"../../src/parser.h"
#include
"../../src/node.h"
#include
"../../src/modules.h"
#include
"../../src/process_int.h"
#include
"../../src/cdo_options.h"
#include
"test_module_list.h"
#include
<iostream>
#include
<vector>
#include
<memory>
#include
<string>
#include
"../../src/cdo_node_attach_exception.h"
#include
"../../src/cdo_exception.h"
// Util stuff tests start at marker: TESTS
using
namespace
snowhouse
;
...
...
@@ -27,6 +31,12 @@ process_inq_prompt(void)
return
context
;
}
const
char
*
process_inq_err_prompt
(
void
)
{
return
"cdo (Abort): "
;
}
unsigned
int
getRequiredElements
(
std
::
vector
<
std
::
string
>
input
)
{
...
...
@@ -57,52 +67,66 @@ void
check
(
std
::
string
description
,
std
::
vector
<
std
::
string
>
in
,
std
::
string
out
)
{
bandit
::
it
(
description
,
[
&
]()
{
auto
res
=
Parser
::
parse
(
in
,
process_inq_prompt
)
;
std
::
string
node_structure
;
unsigned
numChildrenExpected
;
if
(
res
.
size
()
>
0
)
std
::
string
err_location
=
" "
;
std
::
string
node_structure
=
""
;
unsigned
numChildrenExpected
=
-
1337
;
try
{
auto
res
=
Parser
::
parse
(
in
,
process_inq_prompt
);
node_structure
=
res
[
0
]
->
to_string
();
numChildrenExpected
=
getNumChildren
(
res
[
0
]);
AssertThat
(
node_structure
,
Equals
(
out
));
AssertThat
(
res
,
Is
().
OfLength
(
1
));
AssertThat
(
numChildrenExpected
,
Equals
(
getRequiredElements
(
in
)));
}
else
catch
(
CdoException
&
exp
)
{
node_structur
e
=
"
"
;
numChildrenExpected
=
-
1337
;
err_location
=
"thrown from: "
+
exp
.
fil
e
+
"
:"
+
exp
.
line
;
AssertionException
(
exp
.
what
()
+
std
::
string
(
"
\n
"
)
+
err_location
)
;
}
AssertThat
(
node_structure
,
Equals
(
out
));
AssertThat
(
res
,
Is
().
OfLength
(
1
));
AssertThat
(
numChildrenExpected
,
Equals
(
getRequiredElements
(
in
)));
});
}
template
<
typename
exp_type
>
void
checkNegative
(
std
::
string
description
,
std
::
vector
<
std
::
string
>
in
)
checkNegative
(
std
::
string
description
,
std
::
vector
<
std
::
string
>
in
,
std
::
string
expected_err_msg
)
{
bandit
::
it
(
description
,
[
&
]()
{
AssertThrows
(
exp_type
,
Parser
::
run
(
in
));
});
bandit
::
it
(
description
,
[
&
,
in
]()
{
AssertThrows
(
CdoSyntaxError
,
Parser
::
_parse
(
in
,
process_inq_prompt
));
AssertThat
(
LastException
<
CdoSyntaxError
>
().
what
(),
Contains
(
expected_err_msg
));
});
}
void
checkApply
(
std
::
string
description
,
std
::
vector
<
std
::
string
>
in
,
std
::
string
out
,
unsigned
int
numChildren
)
{
bandit
::
it
(
description
,
[
&
]()
{
auto
res
=
Parser
::
parse
(
in
,
process_inq_prompt
);
std
::
string
node_structure
;
std
::
string
err_location
=
""
;
unsigned
numChildrenExpected
;
if
(
res
.
size
()
>
0
)
try
{
node_structure
=
res
[
0
]
->
to_string
();
numChildrenExpected
=
getNumChildren
(
res
[
0
]);
auto
res
=
Parser
::
parse
(
in
,
process_inq_prompt
);
if
(
res
.
size
()
>
0
)
{
node_structure
=
res
[
0
]
->
to_string
();
numChildrenExpected
=
getNumChildren
(
res
[
0
]);
}
else
{
node_structure
=
""
;
numChildrenExpected
=
-
1337
;
}
AssertThat
(
numChildrenExpected
,
Equals
(
numChildren
));
AssertThat
(
node_structure
,
Equals
(
out
));
AssertThat
(
res
,
Is
().
OfLength
(
1
));
}
else
catch
(
CdoException
&
exp
)
{
node_structur
e
=
"
"
;
numChildrenExpected
=
-
1337
;
err_location
=
"thrown from: "
+
exp
.
fil
e
+
"
:"
+
exp
.
line
;
AssertionException
(
exp
.
what
()
+
std
::
string
(
"
\n
"
)
+
err_location
)
;
}
AssertThat
(
numChildrenExpected
,
Equals
(
numChildren
));
AssertThat
(
node_structure
,
Equals
(
out
));
AssertThat
(
res
,
Is
().
OfLength
(
1
));
});
}
...
...
@@ -121,10 +145,10 @@ go_bandit([]() {
bandit
::
describe
(
"The Core Functionality"
,
[
&
]()
{
check
(
"handles a single operator with in and output files"
,
{
"-in1_out1"
,
"in"
,
"out"
},
"out [ in1_out1 [ in ] ]"
);
check
(
"handles a single operator with 2 in files and a single output
file"
,
{
"-in2_out1"
,
"infile1"
,
"infile2"
,
"out"
},
"out [ in2_out1 [ infile1 infile2 ] ]"
);
check
(
"handles a single operator with 2 in files and a single output "
"
file"
,
{
"-in2_out1"
,
"infile1"
,
"infile2"
,
"out"
},
"out [ in2_out1 [ infile1 infile2 ] ]"
);
check
(
"handles a single operator with 0 input and a single output"
,
{
"-in0_out1"
,
"out"
},
"out [ in0_out1 ]"
);
...
...
@@ -162,6 +186,11 @@ go_bandit([]() {
"outfile"
,
{
"-inVariable_out1"
,
"infile1"
,
"infile2"
,
"infile3"
,
"out"
},
"out [ inVariable_out1 [ infile1 infile2 infile3 ] ]"
);
check
(
"handles nested subgroups in subgrups"
,
{
"-inVariable_out1"
,
"["
,
"["
,
"infile1"
,
"infile2"
,
"]"
,
"["
,
"infile3"
,
"infile4"
,
"]"
,
"]"
,
"out"
},
"out [ inVariable_out1 [ infile1 infile2 infile3 infile4 ] ]"
);
});
bandit
::
describe
(
"Subgroup Functionality"
,
[
&
]()
{
...
...
@@ -234,86 +263,185 @@ go_bandit([]() {
});
});
bandit
::
describe
(
"Error handling"
,
[
&
]()
{
bandit
::
describe
(
"handling for Syntax Errors"
,
[
&
]()
{
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"fails on file at pos 1"
,
{
"in"
,
"infile2"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"fails on file at pos 1 with other operators follwing"
,
{
"in"
,
"in1_out1"
,
"infile2"
,
"out"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"aborts with an unattached file after subgroup"
,
{
"in2_out1"
,
"["
,
"infile1"
,
"infile2"
,
"]"
,
"file_too_much"
,
"out"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"aborts detects too much inputs"
,
{
"-in2_out1"
,
"-in0_out1"
,
"-in0_out1"
,
"-in0_out1"
,
"out"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"aborts when no in- and output are present"
,
{
"files_only"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"aborts when apply is used as first operator"
,
{
"-apply,-in0_out1"
,
"["
,
"-in0out1"
,
"]"
,
"out"
});
bandit
::
describe
(
"Error handling:"
,
[
&
]()
{
bandit
::
describe
(
"Syntax Errors:"
,
[
&
]()
{
std
::
vector
<
std
::
string
>
argv
=
{
"in"
,
"infile2"
};
checkNegative
(
"fails on file at pos 1"
,
argv
,
Parser
::
err_msg_oper_not_found
(
argv
[
0
]));
argv
=
{
"in"
,
"in1_out1"
,
"infile2"
,
"out"
};
checkNegative
(
"fails on file at pos 1 with other operators follwing"
,
argv
,
Parser
::
err_msg_oper_not_found
(
argv
[
0
]));
argv
=
{
"in2_out1"
,
"["
,
"infile1"
,
"infile2"
,
"]"
,
"file_too_much"
,
"out"
};
checkNegative
(
"aborts with an unattached file after subgroup"
,
argv
,
Parser
::
errmsg_unprocessed_inputs
);
checkNegative
<
Parser
::
CdoSyntaxError
>
(
checkNegative
(
"aborts detects too much inputs"
,
{
"-in2_out1"
,
"-in0_out1"
,
"-in0_out1"
,
"-in0_out1"
,
"out"
},
Parser
::
errmsg_unprocessed_inputs
);
argv
=
{
"only_a_file"
};
checkNegative
(
"aborts when no in- and output are present (file)"
,
argv
,
Parser
::
err_msg_oper_not_found
(
argv
[
0
]));
argv
=
{
"-in1_out1"
};
checkNegative
(
"aborts when no in- and output are present (in1 out1)"
,
argv
,
Parser
::
errmsg_missing_outputs
);
argv
=
{
"-in1_out0"
};
checkNegative
(
"aborts when no in- and output are present (in1 out0)"
,
argv
,
Parser
::
errmsg_missing_inputs
);
argv
=
{
"-in0_out1"
};
checkNegative
(
"aborts when no in- and output are present (in0 out1)"
,
argv
,
Parser
::
errmsg_missing_outputs
);
checkNegative
(
"error on a single operator with variable inputs (0) and a single "
"outfile"
,
{
"-inVariable_out1"
,
"out"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"multiple variable input operators are not allowed without grouping "
{
"-inVariable_out1"
,
"out"
},
Parser
::
errmsg_missing_inputs
);
checkNegative
(
"multiple variable input operators are not allowed without "
"grouping "
"feature "
,
{
"-inVariable_out1"
,
"-inVariable_out1"
,
"infile1"
,
"infile2"
,
"out"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"too many files"
,
{
"in2_out1"
,
"infile1"
,
"infile2"
,
"infile3"
,
"out"
});
"out"
},
Parser
::
errmsg_multiple_variable
);
});
bandit
::
describe
(
"Apply Error Handling"
,
[
&
]()
{
checkNegative
<
Parser
::
CdoApplySyntaxError
>
(
"apply handles 2 in 1 out "
,
{
"inVariable_out1"
,
"["
,
"in2_out1"
,
":"
,
"infile1"
,
"infile2"
,
"infile3"
,
"]"
,
"out"
});
checkNegative
<
Parser
::
CdoApplySyntaxError
>
(
"apply finds error with missing bracket "
,
{
"inVariable_out1"
,
"WRONG"
,
"["
,
"in1_out1"
,
":"
,
"infile1"
,
"infile2"
,
"infile3"
,
"]"
,
"out"
});
bandit
::
describe
(
"Apply Errors:"
,
[
&
]()
{
checkNegative
(
"detects arguments with multiple inputs "
,
{
"inVariable_out1"
,
"["
,
"in2_out1"
,
":"
,
"infile1"
,
"infile2"
,
"infile3"
,
"]"
,
"out"
},
Parser
::
errmsg_only_1_to_1_operators
);
checkNegative
(
"apply detects if a file is in front"
,
{
"inVariable_out1"
,
"WRONG"
,
"["
,
"-in1_out1"
,
":"
,
"infile1"
,
"infile2"
,
"infile3"
,
"]"
,
"out"
},
Parser
::
errmsg_mixed_input
);
checkNegative
(
"apply detects if a operator is in front"
,
{
"inVariable_out1"
,
"-in0_out1"
,
"["
,
"-in1_out1"
,
":"
,
"infile1"
,
"infile2"
,
"]"
,
"out"
},
Parser
::
errmsg_mixed_input
);
checkNegative
(
"apply detects if a subgroup returns to many for the target"
,
{
"inVariable_out1"
,
"-in1_out1"
,
"["
,
"-in1_out1"
,
":"
,
"infile1"
,
"infile2"
,
"]"
,
"out"
},
errmsg_node_to_many_inputs
);
checkNegative
(
"aborts when apply is used as first operator"
,
{
"-apply,-in1_out1"
,
"["
,
"-in0out1"
,
"]"
,
"out"
},
Parser
::
errmsg_apply_in_first_pos
);
checkNegative
(
"aborts when old apply argument contains unkown operator"
,
{
"-inVariable_out1"
,
"-apply,NOOPER"
,
"["
,
"f1"
,
"f2"
,
"]"
,
"out"
},
Parser
::
err_msg_oper_not_found
(
"NOOPER"
));
checkNegative
(
"aborts when old apply has no inputs"
,
{
"-inVariable_out1"
,
"-apply,-in1_out1"
,
"out"
},
Parser
::
errmsg_apply_requires_bracket
);
checkNegative
(
"aborts when old apply has no inputs but '[ ]'"
,
{
"-inVariable_out1"
,
"-apply,-in1_out1"
,
"["
,
"]"
,
"out"
},
Parser
::
errmsg_apply_missing_argument
);
checkNegative
(
"aborts when new apply has no inputs"
,
{
"-inVariable_out1"
,
"["
,
"-in1_out1"
,
":"
,
"]"
,
"out"
},
Parser
::
errmsg_apply_missing_argument
);
checkNegative
(
"aborts when old apply has no inputs and "
"variable input has no output"
,
{
"-inVariable_out0"
,
"-apply,-in1_out1"
},
Parser
::
errmsg_apply_requires_bracket
);
checkNegative
(
"aborts when old apply has the '[' but nothing else"
,
{
"-inVariable_out0"
,
"-apply,-in1_out1"
,
"["
},
Parser
::
errmsg_bracket_not_closed
);
checkNegative
(
"detects a missing duplicate bracket"
,
{
"inVariable_out1"
,
"["
,
"in2_out1"
,
":"
,
"infile1"
,
"infile2"
,
"infile3"
,
"out"
},
Parser
::
errmsg_bracket_not_closed
);
checkNegative
(
"apply only allows chains with single in and output"
,
{
"inVariable_out1"
,
"["
,
"-in2_out0"
,
"-in0_out1"
,
"-in1_out1"
,
":"
,
"infile1"
,
"infile2"
,
"]"
,
"out"
},
Parser
::
errmsg_only_1_to_1_operators
);
});
bandit
::
describe
(
"handling for SubGroups Errors"
,
[
&
]()
{
checkNegative
<
Parser
::
CdoSubGroupSyntaxError
>
(
bandit
::
describe
(
"SubGroups Errors:"
,
[
&
]()
{
checkNegative
(
"handles nested subgroups in subgrups with too many brackets"
,
{
"-inVariable_out1"
,
"["
,
"["
,
"infile1"
,
"infile2"
,
"]"
,
"["
,
"["
,
"infile3"
,
"infile4"
,
"]"
,
"]"
,
"out"
},
Parser
::
errmsg_bracket_not_closed
);
checkNegative
(
"empty [ ] are not ignored"
,
{
"-in2_out0"
,
"infile1"
,
"["
,
"]"
,
"infile2"
,
"["
,
"]"
});
checkNegative
<
Parser
::
CdoSubGroupSyntaxError
>
(
"detects a missing bracket"
,
{
"inVariable_out1"
,
"["
,
"in2_out1"
,
":"
,
"infile1"
,
"infile2"
,
"infile3"
,
"out"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"missing bracket detected"
,
{
"inVariable_out1"
,
"["
,
"in2_out1"
,
":"
,
"infile1"
,
"infile2"
,
"infile3"
,
"out"
});
checkNegative
<
Parser
::
CdoSyntaxError
>
(
"apply only allows operators with single in and output"
,
{
"inVariable_out1"
,
"["
,
"in1_out1 -topo -in1_out1"
,
":"
,
"infile1"
,
"infile2"
,
"out"
});
{
"-in2_out0"
,
"infile1"
,
"["
,
"]"
,
"infile2"
,
"["
,
"]"
},
Parser
::
errmsg_empty_subgroup
);
checkNegative
(
"missing ']' bracket detected"
,
{
"inVariable_out1"
,
"["
,
"infile1"
,
"infile2"
,
"infile3"
,
"out"
},
Parser
::
errmsg_bracket_not_closed
);
checkNegative
(
"missing '[' bracket detected"
,
{
"inVariable_out1"
,
"infile1"
,
"infile2"
,
"infile3"
,
"]"
,
"out"
},
Parser
::
errmsg_missing_sub_group
);
checkNegative
(
"handles nested subgroups in subgrups with too many '[' brackets"
,
{
"-inVariable_out1"
,
"["
,
"["
,
"infile1"
,
"infile2"
,
"]"
,
"["
,
"["
,
"infile3"
,
"infile4"
,
"]"
,
"]"
,
"out"
},
Parser
::
errmsg_bracket_not_closed
);
checkNegative
(
"handles nested subgroups in subgrups with too many ']' brackets"
,
{
"-inVariable_out1"
,
"["
,
"["
,
"infile1"
,
"infile2"
,
"]"
,
"]"
,
"["
,
"infile3"
,
"infile4"
,
"]"
,
"]"
,
"out"
},
Parser
::
errmsg_missing_sub_group
);
});
bandit
::
describe
(
"
e
rrors handled by Node instead of Parser"
,
[
&
]()
{
checkNegative
<
NodeAttachException
>
(
"abort when only_file operator has pipe"
,
{
"files_only"
,
"-in0_out1"
,
"out"
}
);
checkNegative
<
NodeAttachException
>
(
bandit
::
describe
(
"
E
rrors handled by Node instead of Parser"
,
[
&
]()
{
checkNegative
(
"abort when only_file operator has pipe"
,
{
"files_only"
,
"-in0_out1"
,
"out"
}
,
errmsg_node_only_accepts_files
);
checkNegative
(
"using 0 output operators as input for other node is caught"
,
{
"-in1_out1"
,
"-in1_out0"
,
"out"
});
{
"-in1_out1"
,
"-in1_out0"
,
"out"
}
,
errmsg_node_no_output
);
checkNegative
<
NodeAttachException
>
(
checkNegative
(
"sub groups cannot overflow"
,
{
"-in2_out1"
,
"["
,
"infile1"
,
"infile2"
,
"infile3"
,
"]"
,
"out"
});
{
"-in2_out1"
,
"["
,
"infile1"
,
"infile2"
,
"infile3"
,
"]"
,
"out"
},
errmsg_node_to_many_inputs
);
checkNegative
(
"detects malformed e.g. subgroup operators without inptu"
,
{
"-inVariable_out1"
,
"["
,
"["
,
"-in2_out1"
,
"]"
,
"["
,
"infile2"
,
"infile3"
,
"]"
,
"]"
,
"out"
},
Parser
::
errmsg_malformed_subgroup
);
});
});
});
//==============================================================================
#define EXCEPTION_EXTRA_INFO = 1;
int
main
(
int
argc
,
char
**
argv
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment