11module dag_test
22 use dag_m, only: dag_t
3+ use erloff, only: error_list_t
34 use vertex_m, only: vertex_t
45 use vegetables, only: &
5- result_t, test_item_t, assert_equals, describe, it, assert_that
6+ result_t, test_item_t, assert_equals, describe, it, assert_that, fail
67 use iso_varying_string, only : varying_string, var_str, assignment (= ), char
7- use jsonff, only: json_object_t
8+ use jsonff, only: fallible_json_value_t, json_object_t, parse_json
89 ! ! Test DAG construction, input, and output.
910 implicit none
1011 private
@@ -16,31 +17,31 @@ function test_dag_construction() result(tests)
1617 type (test_item_t) :: tests
1718
1819 tests = describe(" dag's module dependency graph" , &
19- [it(" can be constructed, output to .dot file, and converted to a PDF" , construct_dag_and_write_pdf) &
20- ,it(" can be constructed and converted to a JSON object" , construct_dag_and_json_object) &
21- ,it(" is topologically sorted when constructed from components" , component_constructor_sorts) &
20+ [ it(" can be constructed, output to .dot file, and converted to a PDF" , construct_dag_and_write_pdf) &
21+ , it(" can be constructed and converted to a JSON object" , construct_dag_and_json_object) &
22+ , it(" is topologically sorted when constructed from components" , component_constructor_sorts) &
23+ , it(" is topologically sorted when constructed from a JSON object" , json_constructor_sorts) &
2224 ])
23- ! ,it("is topologically sorted when constructed from a JSON object", json_constructor_sorts)])
2425
2526 end function
2627
2728 function module_tree_from_components () result(dag_modules)
2829 type (dag_t) dag_modules
29-
30+
3031 enum, bind(C)
31- enumerator :: assert_m= 1 , vertex_s, vertex_m, dag_m, dag_s
32+ enumerator :: assert_m= 1 , vertex_s, vertex_m, dag_m, dag_s
3233 end enum
33-
34+
3435 integer , parameter :: module_id(* ) = [assert_m, vertex_s, vertex_m, dag_m, dag_s]
3536 type (varying_string) :: names(size (module_id))
36-
37+
3738 names(assert_m) = " assert_m"
3839 names(vertex_m) = " vertex_m"
39- names(vertex_s) = " vertex_s"
40+ names(vertex_s) = " vertex_s"
4041 names(dag_m) = " dag_m"
4142 names(dag_s) = " dag_s"
4243
43- block
44+ block
4445 character (len=* ), parameter :: &
4546 branch = ' shape=square, fillcolor="SlateGray1", style=filled' &
4647 ,external_ = ' shape=square, fillcolor="green", style=filled' &
@@ -69,7 +70,7 @@ function construct_dag_and_write_pdf() result(result_)
6970 associate(modules = > module_tree_from_components())
7071 call modules% save_digraph(dot_file_name, ' RL' , 300 )
7172 call execute_command_line(command, wait= .true. , exitstat= exit_status, cmdstat= command_status)
72- result_ = assert_equals(success, exit_status) .and. assert_equals(success, command_status)
73+ result_ = assert_equals(success, exit_status) .and. assert_equals(success, command_status)
7374 end associate
7475
7576 end function
@@ -94,28 +95,38 @@ function construct_dag_and_json_object() result(result_)
9495
9596 function component_constructor_sorts () result(result_)
9697 type (result_t) result_
97-
98+
9899 associate(dag = > module_tree_from_components())
99100 result_ = assert_that(dag% is_sorted_and_acyclic())
100101 end associate
101- end function
102+ end function
102103
103104 function json_constructor_sorts () result(result_)
104105 type (result_t) result_
105- type (dag_t) dag
106- character (len=* ), parameter :: dag_library_module_dependencies= &
106+ type (dag_t) dag
107+ type (error_list_t) :: errors
108+ type (fallible_json_value_t) :: maybe_json
109+ character (len=* ), parameter :: json_string = &
107110 ' {"vertices":[' // &
108111 ' {"label":"assert_m","edges":[]},' // &
109112 ' {"label":"vertex_s","edges":[3,1]},' // &
110113 ' {"label":"vertex_m","edges":[]},' // &
111114 ' {"label":"dag_m","edges":[3]},' // &
112115 ' {"label":"dag_s","edges":[4,1]}]}'
113- character (len= len (dag_library_module_dependencies)) json
114-
115- json = dag_library_module_dependencies
116-
117- read (json,* ) dag
118- result_ = assert_that(dag% is_sorted_and_acyclic())
116+
117+ maybe_json = parse_json(json_string)
118+ if (.not. maybe_json% failed()) then
119+ select type (json = > maybe_json% value_())
120+ type is (json_object_t)
121+ dag = dag_t(json)
122+ result_ = assert_that(dag% is_sorted_and_acyclic())
123+ class default
124+ result_ = fail(" json wasn't an object" )
125+ end select
126+ else
127+ errors = maybe_json% errors()
128+ result_ = fail(errors% to_string())
129+ end if
119130 end function
120131
121132end module dag_test
0 commit comments