Skip to content

Commit

Permalink
refactor: tests, adding more tests for loading/storing
Browse files Browse the repository at this point in the history
  • Loading branch information
SGSSGene committed Dec 16, 2024
1 parent 09d7d11 commit b55a818
Show file tree
Hide file tree
Showing 13 changed files with 4,104 additions and 1,252 deletions.
31 changes: 18 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,25 @@ clean: FORCE
## regen_parser : regenerate the CWL v1.2 parser
regen_parser: cwl_v1_*.h

define run_test
@result="$(shell eval $(1) | md5sum -b)" ; \
expected="$(shell eval $(2) | md5sum -b)" ; \
if [ "$$result" != "$$expected" ] ; then \
echo test failed '$(1)': $$result != $$expected; exit 1; \
fi;
endef

## tests : compile and run the tests
tests: FORCE cwl_output_example cwl_input_example
@result_output="$(shell ./cwl_output_example | md5sum -b)" ; \
result_input="$(shell ./cwl_input_example expected_cwl.cwl | md5sum -b)" ; \
expected="$(shell cat expected_cwl.cwl | md5sum -b)" ; \
if [ "$$result_output" = "$$expected" ] ; then \
if [ "$$result_input" = "$$expected" ] ; then \
echo test passed ; \
else \
echo test failed cwl_input_example $$result_input != $$expected; exit 1; \
fi \
else \
echo test failed cwl_output_example $$result_output != $$expected; exit 1; \
fi
tests: FORCE cwl_output_example cwl_input_example cwl_input_example_store_config
$(call run_test,./cwl_output_example,cat tests/expected_cwl.cwl)
$(call run_test,./cwl_input_example tests/expected_cwl.cwl,cat tests/expected_cwl.cwl)
$(call run_test,./cwl_input_example_store_config tests/01_types.cwl,cat tests/01_types_expected.cwl)
$(call run_test,./cwl_input_example_store_config tests/01_types.cwl no_simplification,cat tests/01_types_expected_no_simplification.cwl)
$(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)
$(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)
$(call run_test,./cwl_input_example tests/02_expression.cwl,cat tests/02_expression_expected.cwl)

@echo test passed
FORCE:

# Use this to print the value of a Makefile variable
Expand Down
15 changes: 2 additions & 13 deletions cwl_input_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,10 @@
*/


// using shortened cwl:: namespace instead of https___w3id_org_cwl_cwl
namespace cwl = https___w3id_org_cwl_cwl;

int main(int argc, char** argv) {
if (argc != 2) return 1;

auto yaml = YAML::LoadFile(argv[1]);
auto tool = cwl::CommandLineTool{};
fromYaml(yaml, tool);

auto y = toYaml(tool);

YAML::Emitter out;
out << y;
std::cout << out.c_str() << "\n";

auto tool = cpp_gen::load_document(argv[1]);
cpp_gen::store_document(tool, std::cout);
return 0;
}
32 changes: 32 additions & 0 deletions cwl_input_example_store_config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "cwl_v1_2.h"

#include <iostream>

/**
* This test program creates loads and prints a CWL description.
*
* It assumes that printing to stdout works (see cwl_output_example).
* It loads a CWL description from a file and populates C++ classes.
*/


int main(int argc, char** argv) {
if (argc < 2) return 1;

auto tool = cpp_gen::load_document(argv[1]);

// parse command line
auto config = cpp_gen::store_config{};
for (int i{2}; i < argc; ++i) {
auto sv = std::string_view{argv[i]};
if (sv == "no_simplification") {
config.simplifyTypes = false;
} else if (sv == "no_list_to_map") {
config.transformListsToMaps = false;
} else if (sv == "tags") {
config.generateTags = true;
}
}
cpp_gen::store_document(tool, std::cout, config);
return 0;
}
8 changes: 2 additions & 6 deletions cwl_output_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

// using shortened cwl:: namespace instead of https___w3id_org_cwl_cwl
namespace cwl = https___w3id_org_cwl_cwl;
namespace cwl = cpp_gen::https___w3id_org_cwl_cwl;

int main() {
// declaring information about this tool in general
Expand Down Expand Up @@ -105,9 +105,5 @@ int main() {
}


auto y = toYaml(tool);

YAML::Emitter out;
out << y;
std::cout << out.c_str() << "\n";
cpp_gen::store_document(tool, std::cout);
}
Loading

0 comments on commit b55a818

Please sign in to comment.