Renumber the jobs file so that it can be reloaded in native code.
[whenjobs.git] / tests / jobs / t300_reload.ml
diff --git a/tests/jobs/t300_reload.ml b/tests/jobs/t300_reload.ml
new file mode 100644 (file)
index 0000000..f7c6532
--- /dev/null
@@ -0,0 +1,49 @@
+(* whenjobs
+ * Copyright (C) 2012 Red Hat Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+(* Test reloading the script. *)
+
+let () =
+  Whentools.set_variable_int "counter" 1;
+  Whentools.set_variable "state" "A"
+
+every 2 seconds :
+<<
+  echo $JOBSERIAL $JOBNAME $counter >\> $HOME/test_output
+  whenjobs --set --type int counter=$(($counter+1))
+>>
+
+when counter == 2 :
+<<
+  echo $JOBSERIAL $JOBNAME $counter $state >\> $HOME/test_output
+
+  # Actually modify the 'set_variable' lines above in the jobs script.
+  mv $HOME/.whenjobs/jobs.ml $HOME/.whenjobs/jobs.ml.old
+  sed \
+      -e 's/"counter" 1/"counter" 3/' \
+      -e 's/"state" "A"/"state" "B"/' \
+       < $HOME/.whenjobs/jobs.ml.old > $HOME/.whenjobs/jobs.ml
+
+  whenjobs --upload --lib "$libdir"
+>>
+
+when counter == 4 :
+<<
+  echo $JOBSERIAL $JOBNAME $counter $state >\> $HOME/test_output
+  whenjobs --daemon-stop
+>>