Commit Diff


commit - 620f3fe5910b9d893eab6c9f36426ce118cdde69
commit + 631b9683de1baabb6f4b61516c6ac3a926a0cde8
blob - a4221a835fb04553cbd6864b770b506ae8d9d080
blob + 639422ecc25caffdd85c7424375a8e4127b3a471
--- CHANGELOG.md
+++ CHANGELOG.md
@@ -13,6 +13,7 @@ change log follows the conventions of
 ### Fixed
 
 - Fix setting of headless mode (#50).
+- Fix exit code when history is not valid (#53).
 
 ### Changed
 
blob - ef76a10f1232772c0a7516197e06489bca4a0fec
blob + 5eea0a12126c46cf45b32c593d6ca85552dedf70
--- src/elle_cli/cli.clj
+++ src/elle_cli/cli.clj
@@ -201,12 +201,16 @@
   (let [ext (second (re-find #"\.([a-zA-Z0-9]+)$" filepath))]
     (get history-read-fn ext)))
 
+(defn lazy-contains? [coll key]
+    (boolean (some #(= % key) coll)))
+
 (defn -main
   [& args]
   (try
     (let [{:keys [options arguments summary errors]} (cli/parse-opts args opts)
           model-name (:model options)
           read-history (:format options)
+          results (atom (hash-map))
           help (:help options)]
       (when-not (empty? errors)
         (doseq [e errors]
@@ -223,13 +227,16 @@
 
         (let [read-history  (or read-history (read-fn-by-extension filepath))
               history       (read-history filepath)
-              analysis      (check-history model-name history options)]
+              analysis      (check-history model-name history options)
+              validness     (:valid? analysis)]
 
+        (swap! results assoc filepath validness)
+
         (if (true? (:verbose options))
           (json/pprint analysis)
-          (println filepath "\t" (:valid? analysis)))))
+          (println filepath "\t" validness))))
 
-      (System/exit 0))
+      (System/exit ({true 1 false 0} (lazy-contains? (vals @results) false))))
 
     (catch Throwable t
       (println)
blob - 607fac0a1c14ace2d2473872439e710603fdaadc
blob + dc3beeb59e34b3470a1fc7d577bca7b280efbeb1
--- test.sh
+++ test.sh
@@ -15,9 +15,11 @@ run_test() {
     test_status="NOT OK"
     cmd="$ELLE_CLI_BIN $elle_cli_opts"
     test_output=$($cmd)
+    rc=$?
     res=$(echo $test_output | cut -d" " -f2)
-    if { [ "X$res" = Xfalse ] && [ "$exit_code" -ne 0 ]; } ||
-       { [ "X$res" = Xtrue ] && [ "$exit_code" -eq 0 ]; }; then
+    if { { [ "X$res" = Xfalse ] && [ "$exit_code" -ne 0 ]; } ||
+         { [ "X$res" = Xtrue ] && [ "$exit_code" -eq 0 ]; }; } &&
+       [ "$exit_code" -eq $rc ]; then
         test_status="OK"
     else
         suite_status=1