ocaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

More comprehensive testing of config parser

authored by

Kento Okura and committed by
Jon Sterling
bf59a73d 33190be0

+173 -2
+173 -2
test/Test_config.ml
··· 5 5 *) 6 6 7 7 open Testables 8 + open Forester_core 8 9 open Forester_compiler 9 10 open Forester_frontend 10 11 ··· 17 18 home = Some "index"; 18 19 prefixes = ["foo"; "bar"; "baz"]; 19 20 assets = []; 20 - foreign = []; 21 + foreign = ["foreign/forest.json"]; 21 22 theme = "theme"; 22 23 } 23 24 ( ··· 30 31 trees = ["trees"] 31 32 home = "index" 32 33 prefixes = ["foo", "bar", "baz"] 34 + foreign = ["foreign/forest.json"] 35 + |} 36 + ) 37 + 38 + let test_missing_fields () = 39 + Alcotest.(check config) 40 + "is the same" 41 + Config.{ 42 + host = "test"; 43 + trees = ["trees"]; 44 + home = Some "index"; 45 + theme = "theme"; 46 + assets = []; 47 + foreign = []; 48 + prefixes = []; 49 + } 50 + ( 51 + Forester_core.Reporter.easy_run @@ 52 + fun () -> 53 + Config_parser.parse_forest_config_string 54 + {| 55 + [forest] 56 + host = "test" 57 + trees = ["trees"] 58 + home = "index" 59 + |} 60 + ) 61 + 62 + let test_missing_host () = 63 + Alcotest.(check unit) 64 + "is the same" 65 + () 66 + ( 67 + Forester_core.Reporter.run 68 + ~fatal: ( 69 + function 70 + | { message; explanation; _ } -> 71 + Alcotest.(check Testables.message) 72 + "" 73 + Configuration_error 74 + message; 75 + Alcotest.(check string) 76 + "" 77 + (Asai.Diagnostic.string_of_text explanation.value) 78 + "You need to set the `host' key in your configuration file; this is a global identifier that will be used to distinguish your forest from other forests (you can use your name, e.g. `johnqpublic')"; 79 + ) 80 + ~emit: ( 81 + function 82 + | { message; explanation; _ } -> 83 + Alcotest.(check Testables.message) 84 + "" 85 + Configuration_error 86 + message 87 + ) @@ 88 + fun () -> 89 + let _ = 90 + Config_parser.parse_forest_config_string 91 + {| 92 + [forest] 93 + trees = ["trees"] 94 + home = "index" 95 + |} 96 + in 97 + assert false 98 + ) 99 + 100 + let test_parse_error () = 101 + Alcotest.(check unit) 102 + "is the same" 103 + () 104 + ( 105 + Forester_core.Reporter.run 106 + ~fatal: ( 107 + function 108 + | { explanation; _ } -> 109 + Alcotest.(check string) 110 + "" 111 + (Asai.Diagnostic.string_of_text explanation.value) 112 + "Error in <anonymous> at line 2 at column 11 (position 12)"; 113 + ) 114 + ~emit: (fun _ -> ()) @@ 115 + fun () -> 116 + let _ = 117 + Config_parser.parse_forest_config_string 118 + {| 119 + ]]] 120 + |} 121 + in 122 + assert false 123 + ) 124 + 125 + let test_stylesheet_warning () = 126 + Alcotest.(check config) 127 + "is the same" 128 + Config.{ 129 + host = "test"; 130 + trees = ["trees"]; 131 + home = Some "index"; 132 + theme = "theme"; 133 + assets = []; 134 + foreign = []; 135 + prefixes = []; 136 + } 137 + ( 138 + Forester_core.Reporter.run 139 + ~fatal: (fun _ -> assert false) 140 + ~emit: ( 141 + function 142 + | { explanation; _ } -> 143 + ( 144 + Alcotest.(check string) 145 + "" 146 + "Custom XSL stylesheet injection is no longer supported; please remove the `stylesheet' key from the [forest] group." 147 + (Asai.Diagnostic.string_of_text explanation.value) 148 + ) 149 + ) @@ 150 + fun () -> 151 + Config_parser.parse_forest_config_string 152 + {|[forest] 153 + host = "test" 154 + trees = ["trees"] 155 + home = "index" 156 + stylesheet = "custom.xsl" 157 + |} 158 + ) 159 + 160 + let test_root_warning () = 161 + Alcotest.(check config) 162 + "is the same" 163 + Config.{ 164 + host = "test"; 165 + trees = ["trees"]; 166 + home = None; 167 + theme = "theme"; 168 + assets = []; 169 + foreign = []; 170 + prefixes = []; 171 + } 172 + ( 173 + Forester_core.Reporter.run 174 + ~fatal: (fun _ -> assert false) 175 + ~emit: ( 176 + function 177 + | { explanation; _ } -> 178 + ( 179 + Alcotest.(check string) 180 + "" 181 + "In your configuration file, change `root' key to `home' in the [forest] group." 182 + (Asai.Diagnostic.string_of_text explanation.value) 183 + ) 184 + ) @@ 185 + fun () -> 186 + Config_parser.parse_forest_config_string 187 + {|[forest] 188 + host = "test" 189 + trees = ["trees"] 190 + root = "index" 33 191 |} 34 192 ) 35 193 ··· 39 197 "Config parsing" 40 198 [ 41 199 "example config works", 42 - [test_case "" `Quick test_parsing]; 200 + [ 201 + test_case "it parses correctly" `Quick test_parsing; 202 + ]; 203 + "can parse config with missing fields", 204 + [ 205 + test_case "" `Quick test_missing_fields; 206 + ]; 207 + "handles errors correctly", 208 + [ 209 + test_case "" `Quick test_missing_host; 210 + test_case "" `Quick test_parse_error; 211 + test_case "" `Quick test_stylesheet_warning; 212 + test_case "" `Quick test_root_warning; 213 + ]; 43 214 ]