(jbuild_version 1)

(executables
 ((names (run))
  (libraries (unix))))

(alias
 ((name runtest)
  (deps ((files_recursively_in workspaces/redirections)))
  (action
   (chdir workspaces/redirections
    (run ${exe:run.exe} -- ${bin:jbuilder} runtest -j1 --root .)))))

(alias
 ((name runtest)
  (deps ((files_recursively_in workspaces/misc)))
  (action
   (chdir workspaces/misc
    (run ${exe:run.exe} -- ${bin:jbuilder} runtest -j1 --root .)))))

(alias
 ((name runtest)
  (deps ((files_recursively_in workspaces/github20)))
  (action
   (chdir workspaces/github20
    (run ${exe:run.exe} -- ${bin:jbuilder} build -j1 .merlin --root .)))))

(alias
 ((name runtest-js)
  (deps ((files_recursively_in workspaces/js_of_ocaml)))
  (action
   (chdir workspaces/js_of_ocaml
    (progn
     (run ${exe:run.exe} -log log.build1 -- ${bin:jbuilder} build --verbose -j1 --root . --dev
      bin/technologic.bc.js @install lib/x.cma.js lib/x__Y.cmo.js bin/z.cmo.js)
     (run ${exe:run.exe} -log log.run1 -- ${bin:node} ./_build/default/bin/technologic.bc.js)
     (run ${exe:run.exe} -log log.build2 -- ${bin:jbuilder} build --verbose -j1 --root .
      bin/technologic.bc.js @install)
     (run ${exe:run.exe} -log log.run2 -- ${bin:node} ./_build/default/bin/technologic.bc.js)
     )))))

(alias
 ((name runtest)
  (deps ((files_recursively_in workspaces/github24)))
  (action
   (chdir workspaces/github24
    (run ${exe:run.exe} --
     ${bin:jbuilder} build -j1 @install --root . --debug-dependency-path)))))

(alias
 ((name runtest)
  (deps ((files_recursively_in workspaces/menhir)))
  (action
   (chdir workspaces/menhir
    (run ${exe:run.exe} --
     ${bin:jbuilder} build -j1 test.exe --root . --debug-dependency-path)))))

;; This test define an installed "plop" with a "plop.ca-marche-pas"
;; sub-package which depend on a library that doesn't exist.
;;
;; The build itself uses only "plop.ca-marche", which doesn't have this
;; problem. So jbuilder shouldn't crash because of "plop.ca-marche-pas"
;;
;; We need ocamlfind to run this test
(alias
 ((name runtest)
  (deps ((files_recursively_in workspaces/github25)))
  (action
   (chdir workspaces/github25/root
    (setenv OCAMLPATH ../findlib-packages
     (progn
      (run ${exe:run.exe} -log log1 --
       ${bin:jbuilder} build -j1 @install --root . --only hello)
      (run ${exe:run.exe} -log log2 -inverse --
       ${bin:jbuilder} build -j1 @install --root . --only pas-de-bol
       )))))))

(alias
 ((name runtest)
  (deps ((files_recursively_in workspaces/lib-available)))
  (action
   (chdir workspaces/lib-available
    (run ${exe:run.exe} --
     ${bin:jbuilder} build -j1 @runtest --root . --debug-dependency-path)))))

;; execute this to check the behavior when background jobs take time to finish:
;;
;; $ ./_build/default/bin/main.exe build @test/fail-with-background-jobs-running
;;
(alias
 ((name   sleep5)
  (action (system "sleep 5"))))

(alias
 ((name   sleep1-and-fail)
  (action (system "sleep 1; exit 1"))))

(alias
 ((name   sleep4-and-fail)
  (action (system "sleep 4; exit 1"))))

(alias
 ((name fail-with-background-jobs-running)
  (deps ((alias sleep5)
         (alias sleep4-and-fail)
         (alias sleep1-and-fail)))))
