Parcourir la source

Merge branch 'dev'

Sniperovitch il y a 8 ans
Parent
commit
a113cba940
6 fichiers modifiés avec 177 ajouts et 18 suppressions
  1. 1 1
      .travis.yml
  2. 42 15
      cocktail
  3. 0 2
      test_cocktail
  4. 2 0
      test_cocktail_01
  5. 62 0
      test_cocktail_02
  6. 70 0
      test_cocktail_03

+ 1 - 1
.travis.yml

@@ -14,5 +14,5 @@ notifications:
   irc: "chat.freenode.net#pressecitron"
   irc: "chat.freenode.net#pressecitron"
 script:
 script:
   - ./build.sh
   - ./build.sh
-  - ./test_cocktail
+  - ./test_cocktail_01 && ./test_cocktail_02 && ./test_cocktail_03
 
 

+ 42 - 15
cocktail

@@ -1,10 +1,17 @@
 #!/bin/bash
 #!/bin/bash
 
 
+RC_OK=0
+RC_ERROR=1
+RC_LOCK=2
+RC_CONFIG_MISSED=3
+RC_PANDOC_FILES=4
+RC_ARGS=5
+
 end_with_code() {
 end_with_code() {
   local rc=$1
   local rc=$1
   if test -z "$rc";
   if test -z "$rc";
   then
   then
-    rc=1
+    rc=$RC_ERROR
   fi
   fi
 
 
   if test "$rc" -eq 0;
   if test "$rc" -eq 0;
@@ -17,8 +24,21 @@ end_with_code() {
 }
 }
 
 
 die() {
 die() {
-  echo -e "$$ $@" >&2
-  end_with_code 1
+  verbose "[$FUNCNAME] 1:[$1] 2:[$2]"
+  local message
+  local rc
+
+  if test $# == 2;
+  then
+    message=$1
+    rc=$2
+  else
+    message=$1
+    rc=$RC_ERROR
+  fi
+
+  echo -e "$$ $message" >&2
+  end_with_code $rc
 }
 }
 
 
 verbose() {
 verbose() {
@@ -38,19 +58,19 @@ debug() {
 init_check() {
 init_check() {
   if test -e $LOCK_FILE;
   if test -e $LOCK_FILE;
   then
   then
-    die "[$FUNCNAME] lock=$LOCK_FILE exists. Wait compilation or erase it"
+    die "[$FUNCNAME] lock=$LOCK_FILE exists. Wait compilation or erase it" $RC_LOCK
   fi
   fi
 
 
   # PANDOC_FILTER_BASE should exists
   # PANDOC_FILTER_BASE should exists
   if test ! -d "$PANDOC_FILTER_BASE";
   if test ! -d "$PANDOC_FILTER_BASE";
   then
   then
-    die "[$FUNCNAME]: PANDOC_FILTER_BASE=$PANDOC_FILTER_BASE unavailable"
+    die "[$FUNCNAME]: PANDOC_FILTER_BASE=$PANDOC_FILTER_BASE unavailable" $RC_PANDOC_FILES
   fi
   fi
 
 
   # PANDOC_INCLUDE_BASE should exists
   # PANDOC_INCLUDE_BASE should exists
   if test ! -d "$PANDOC_INCLUDE_BASE";
   if test ! -d "$PANDOC_INCLUDE_BASE";
   then
   then
-    die "[$FUNCNAME]: PANDOC_INCLUDE_BASE=$PANDOC_INCLUDE_BASE unavailable"
+    die "[$FUNCNAME]: PANDOC_INCLUDE_BASE=$PANDOC_INCLUDE_BASE unavailable" $RC_PANDOC_FILES
   fi
   fi
 
 
   # STORE should exists
   # STORE should exists
@@ -272,7 +292,7 @@ lock_project() {
   then
   then
     echo "$$" > "$LOCK_FILE"
     echo "$$" > "$LOCK_FILE"
   else
   else
-    die "lockfile $LOCK_FILE already exists"
+    die "lockfile $LOCK_FILE already exists" $RC_LOCK
   fi
   fi
 }
 }
 
 
@@ -290,10 +310,10 @@ unlock_project() {
       then
       then
         verbose "[$FUNCNAME] $PROJET unlocked, $LOCK_FILE removed."
         verbose "[$FUNCNAME] $PROJET unlocked, $LOCK_FILE removed."
       else
       else
-        die"[$FUNCNAME] we can not unlock $PROJET, $LOCK_FILE still on disk."
+        die"[$FUNCNAME] we can not unlock $PROJET, $LOCK_FILE still on disk." $RC_LOCK
       fi
       fi
     else
     else
-      die "[$FUNCNAME] we can not delete lockfile owned by another process"
+      die "[$FUNCNAME] we can not delete lockfile owned by another process" $RC_LOCK
     fi
     fi
 
 
   fi
   fi
@@ -313,7 +333,6 @@ cleanup_working_folder() {
     then
     then
       verbose "[$FUNCNAME] $WORKING_FOLDER removed"
       verbose "[$FUNCNAME] $WORKING_FOLDER removed"
     fi
     fi
-    # rmdir "$WORKING_FOLDER"
   fi
   fi
 }
 }
 
 
@@ -325,7 +344,15 @@ usage() {
       -g : url du pad de page de garde (optionnel)
       -g : url du pad de page de garde (optionnel)
       -h : cette page d'aide
       -h : cette page d'aide
       -p : nom du projet
       -p : nom du projet
-      -v : force le mode verbeux"
+      -v : force le mode verbeux
+
+    return codes:
+      0 : OK
+      1 : GENERIC ERROR
+      2 : LOCK ERROR
+      3 : CONFIG FILE IS MISSING
+      4 : PANDOC FILTER IS MISSING OR NOT EXECUTABLE
+      5 : ARGUMENTS ERRORS"
 }
 }
 
 
 publish() {
 publish() {
@@ -344,7 +371,7 @@ if test -r "$base/cocktail.conf";
 then
 then
   source "$base/cocktail.conf"
   source "$base/cocktail.conf"
 else
 else
-  die "cocktail.conf is missing, see config.conf.smp for example"
+  die "cocktail.conf is missing, see config.conf.smp for example" $RC_CONFIG_MISSED
 fi
 fi
 
 
 OPTERR=1
 OPTERR=1
@@ -384,7 +411,7 @@ verbose "ARGS=$@"
 
 
 if test -z "$DOSSIER";
 if test -z "$DOSSIER";
 then
 then
-  die "getopts: -d DOSSIER is mandatory"
+  die "getopts: -d DOSSIER is mandatory" $RC_ARGS
 fi
 fi
 
 
 verbose "DOSSIER=$DOSSIER"
 verbose "DOSSIER=$DOSSIER"
@@ -402,7 +429,7 @@ verbose "LOCK_FILE=$LOCK_FILE"
 
 
 if test -z "$URL_BASE";
 if test -z "$URL_BASE";
 then
 then
-  die "getopts: -b URL_BASE is mandatory"
+  die "getopts: -b URL_BASE is mandatory" $RC_ARGS
 fi
 fi
 
 
 init_check
 init_check
@@ -426,5 +453,5 @@ pad2tex "$WORKING_FOLDER/$PROJET.txt" "$WORKING_FOLDER/$PROJET.tex"
 tex2pdf "$WORKING_FOLDER/$PROJET.tex" "$WORKING_FOLDER/$PROJET.pdf"
 tex2pdf "$WORKING_FOLDER/$PROJET.tex" "$WORKING_FOLDER/$PROJET.pdf"
 publish
 publish
 unlock_project
 unlock_project
-end_with_code 0
+end_with_code $RC_OK
 
 

+ 0 - 2
test_cocktail

@@ -1,2 +0,0 @@
-#!/bin/bash
-./cocktail -v -d MonDossier$RANDOM -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt'

+ 2 - 0
test_cocktail_01

@@ -0,0 +1,2 @@
+#!/bin/bash
+./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt'

+ 62 - 0
test_cocktail_02

@@ -0,0 +1,62 @@
+#!/bin/bash
+
+echo "Test 02: 2 compilations dans le même dossier, projets différents."
+echo "Les deux compilations doivent réussir"
+
+RC1=99
+RC2=99
+
+handle_child() {
+  local tmp=()
+  for((i=0;i<${#pids[@]};++i));
+  do
+    if test ! -d /proc/${pids[i]};
+    then
+      wait ${pids[i]}
+      RC0=$?
+      echo "Stopped ${pids[i]}; exit code: $RC0"
+      if test "$RC1" -eq 99;
+      then
+        RC1="$RC0"
+      else
+        if test "$RC2" -eq 99;
+        then
+          RC2="$RC0"
+        fi
+      fi
+    else
+      tmp+=(${pids[i]})
+    fi
+  done
+  pids=(${tmp[@]})
+}
+
+set -o monitor
+trap "handle_child" CHLD
+
+
+# Start background processes
+./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+pids+=($!)
+
+./cocktail -v -d MonDossier -p Abro3 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+pids+=($!)
+
+# Wait until all background processes are stopped
+while [ ${#pids[@]} -gt 0 ];
+do
+  echo "WAITING FOR: ${pids[@]}";
+  sleep 2;
+done
+echo STOPPED
+echo "RC1=$RC1 RC2=$RC2"
+
+if test "$RC1" -eq 0 -a "$RC2" -eq 0;
+then
+  echo "Test réussi"
+  exit 0
+fi
+
+echo "Test échoué"
+exit 1
+

+ 70 - 0
test_cocktail_03

@@ -0,0 +1,70 @@
+#!/bin/bash
+
+echo "Test 03: 2 compilations dans le même dossier, même projet."
+echo "Un des deux doit tomber en erreur"
+
+RC1=99
+RC2=99
+
+handle_child() {
+  local tmp=()
+  for((i=0;i<${#pids[@]};++i));
+  do
+    if test ! -d /proc/${pids[i]};
+    then
+      wait ${pids[i]}
+      RC0=$?
+      echo "Stopped ${pids[i]}; exit code: $RC0"
+      if test "$RC1" -eq 99;
+      then
+        RC1="$RC0"
+      else
+        if test "$RC2" -eq 99;
+        then
+          RC2="$RC0"
+        fi
+      fi
+    else
+      tmp+=(${pids[i]})
+    fi
+  done
+  pids=(${tmp[@]})
+}
+
+set -o monitor
+trap "handle_child" CHLD
+
+
+# Start background processes
+./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+pids+=($!)
+
+./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+pids+=($!)
+
+# Wait until all background processes are stopped
+while [ ${#pids[@]} -gt 0 ];
+do
+  echo "WAITING FOR: ${pids[@]}";
+  sleep 2;
+done
+echo STOPPED
+echo "RC1=$RC1 RC2=$RC2"
+
+# cocktail exits with rc 2 if error lock
+if test "$RC1" -eq 0 -a "$RC2" -eq 2;
+then
+  echo "Test réussi"
+  exit 0
+fi
+
+# cocktail exits with rc 2 if error lock
+if test "$RC2" -eq 0 -a "$RC1" -eq 2;
+then
+  echo "Test réussi"
+  exit 0
+fi
+
+echo "Test échoué"
+exit 1
+