Skip to content

Commit b55a818

Browse files
committed
refactor: tests, adding more tests for loading/storing
1 parent 09d7d11 commit b55a818

13 files changed

+4104
-1252
lines changed

Diff for: Makefile

+18-13
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,25 @@ clean: FORCE
3636
## regen_parser : regenerate the CWL v1.2 parser
3737
regen_parser: cwl_v1_*.h
3838

39+
define run_test
40+
@result="$(shell eval $(1) | md5sum -b)" ; \
41+
expected="$(shell eval $(2) | md5sum -b)" ; \
42+
if [ "$$result" != "$$expected" ] ; then \
43+
echo test failed '$(1)': $$result != $$expected; exit 1; \
44+
fi;
45+
endef
46+
3947
## tests : compile and run the tests
40-
tests: FORCE cwl_output_example cwl_input_example
41-
@result_output="$(shell ./cwl_output_example | md5sum -b)" ; \
42-
result_input="$(shell ./cwl_input_example expected_cwl.cwl | md5sum -b)" ; \
43-
expected="$(shell cat expected_cwl.cwl | md5sum -b)" ; \
44-
if [ "$$result_output" = "$$expected" ] ; then \
45-
if [ "$$result_input" = "$$expected" ] ; then \
46-
echo test passed ; \
47-
else \
48-
echo test failed cwl_input_example $$result_input != $$expected; exit 1; \
49-
fi \
50-
else \
51-
echo test failed cwl_output_example $$result_output != $$expected; exit 1; \
52-
fi
48+
tests: FORCE cwl_output_example cwl_input_example cwl_input_example_store_config
49+
$(call run_test,./cwl_output_example,cat tests/expected_cwl.cwl)
50+
$(call run_test,./cwl_input_example tests/expected_cwl.cwl,cat tests/expected_cwl.cwl)
51+
$(call run_test,./cwl_input_example_store_config tests/01_types.cwl,cat tests/01_types_expected.cwl)
52+
$(call run_test,./cwl_input_example_store_config tests/01_types.cwl no_simplification,cat tests/01_types_expected_no_simplification.cwl)
53+
$(call run_test,./cwl_input_example_store_config tests/01_types.cwl no_list_to_map,cat tests/01_types_expected_no_list_to_map.cwl)
54+
$(call run_test,./cwl_input_example_store_config tests/01_types.cwl no_simplification no_list_to_map,cat tests/01_types_expected_no_simplification_and_list_to_map.cwl)
55+
$(call run_test,./cwl_input_example tests/02_expression.cwl,cat tests/02_expression_expected.cwl)
56+
57+
@echo test passed
5358
FORCE:
5459

5560
# Use this to print the value of a Makefile variable

Diff for: cwl_input_example.cpp

+2-13
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,10 @@
1010
*/
1111

1212

13-
// using shortened cwl:: namespace instead of https___w3id_org_cwl_cwl
14-
namespace cwl = https___w3id_org_cwl_cwl;
15-
1613
int main(int argc, char** argv) {
1714
if (argc != 2) return 1;
1815

19-
auto yaml = YAML::LoadFile(argv[1]);
20-
auto tool = cwl::CommandLineTool{};
21-
fromYaml(yaml, tool);
22-
23-
auto y = toYaml(tool);
24-
25-
YAML::Emitter out;
26-
out << y;
27-
std::cout << out.c_str() << "\n";
28-
16+
auto tool = cpp_gen::load_document(argv[1]);
17+
cpp_gen::store_document(tool, std::cout);
2918
return 0;
3019
}

Diff for: cwl_input_example_store_config.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#include "cwl_v1_2.h"
2+
3+
#include <iostream>
4+
5+
/**
6+
* This test program creates loads and prints a CWL description.
7+
*
8+
* It assumes that printing to stdout works (see cwl_output_example).
9+
* It loads a CWL description from a file and populates C++ classes.
10+
*/
11+
12+
13+
int main(int argc, char** argv) {
14+
if (argc < 2) return 1;
15+
16+
auto tool = cpp_gen::load_document(argv[1]);
17+
18+
// parse command line
19+
auto config = cpp_gen::store_config{};
20+
for (int i{2}; i < argc; ++i) {
21+
auto sv = std::string_view{argv[i]};
22+
if (sv == "no_simplification") {
23+
config.simplifyTypes = false;
24+
} else if (sv == "no_list_to_map") {
25+
config.transformListsToMaps = false;
26+
} else if (sv == "tags") {
27+
config.generateTags = true;
28+
}
29+
}
30+
cpp_gen::store_document(tool, std::cout, config);
31+
return 0;
32+
}

Diff for: cwl_output_example.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
// using shortened cwl:: namespace instead of https___w3id_org_cwl_cwl
12-
namespace cwl = https___w3id_org_cwl_cwl;
12+
namespace cwl = cpp_gen::https___w3id_org_cwl_cwl;
1313

1414
int main() {
1515
// declaring information about this tool in general
@@ -105,9 +105,5 @@ int main() {
105105
}
106106

107107

108-
auto y = toYaml(tool);
109-
110-
YAML::Emitter out;
111-
out << y;
112-
std::cout << out.c_str() << "\n";
108+
cpp_gen::store_document(tool, std::cout);
113109
}

0 commit comments

Comments
 (0)