From 36d1d11346ecc34d2fa1d7dc3bf2bc02e1496f03 Mon Sep 17 00:00:00 2001 From: Sean Cribbs Date: Fri, 5 Sep 2014 10:39:37 -0500 Subject: [PATCH] Add case for incomplete/syntax-error when parsing conf file. Addresses #153 --- src/cuttlefish_conf.erl | 7 +++++++ test/incomplete.conf | 3 +++ 2 files changed, 10 insertions(+) create mode 100644 test/incomplete.conf diff --git a/src/cuttlefish_conf.erl b/src/cuttlefish_conf.erl index eb4a262a..a7cb7e27 100644 --- a/src/cuttlefish_conf.erl +++ b/src/cuttlefish_conf.erl @@ -66,6 +66,8 @@ file(Filename) -> case conf_parse:file(Filename) of {error, Reason} -> {error, [{error, ?FMT("Could not open file (~s) for Reason ~s", [Filename, Reason])}]}; + {_Conf, Remainder, {{line, L}, {column, C}}} when is_binary(Remainder) -> + {error, [{error, ?FMT("Syntax error in ~s after line ~p column ~p, parsing incomplete", [Filename, L, C])}]}; Conf -> %% Conf is a proplist, check if any of the values are cuttlefish_errors {_, Values} = lists:unzip(Conf), @@ -273,6 +275,11 @@ files_one_nonent_test() -> ?assertEqual({error,[{error,"Could not open file (../test/nonent.conf) for Reason enoent"}]}, Conf), ok. +files_incomplete_parse_test() -> + Conf = file("../test/incomplete.conf"), + ?assertEqual({error, [{error,"Syntax error in ../test/incomplete.conf after line 3 column 1, parsing incomplete"}]}, Conf), + ok. + generate_element_level_advanced_test() -> cuttlefish_lager_test_backend:bounce(warning), assert_no_output({level, advanced}), diff --git a/test/incomplete.conf b/test/incomplete.conf new file mode 100644 index 00000000..522e02f0 --- /dev/null +++ b/test/incomplete.conf @@ -0,0 +1,3 @@ +a.b = c +c.d = e +f =