t / t0061-run-command.shon commit Merge branch 'jk/diff-compact-heuristic' (e5f7675)
   1#!/bin/sh
   2#
   3# Copyright (c) 2009 Ilari Liusvaara
   4#
   5
   6test_description='Test run command'
   7
   8. ./test-lib.sh
   9
  10cat >hello-script <<-EOF
  11        #!$SHELL_PATH
  12        cat hello-script
  13EOF
  14>empty
  15
  16test_expect_success 'start_command reports ENOENT' '
  17        test-run-command start-command-ENOENT ./does-not-exist
  18'
  19
  20test_expect_success 'run_command can run a command' '
  21        cat hello-script >hello.sh &&
  22        chmod +x hello.sh &&
  23        test-run-command run-command ./hello.sh >actual 2>err &&
  24
  25        test_cmp hello-script actual &&
  26        test_cmp empty err
  27'
  28
  29test_expect_success POSIXPERM 'run_command reports EACCES' '
  30        cat hello-script >hello.sh &&
  31        chmod -x hello.sh &&
  32        test_must_fail test-run-command run-command ./hello.sh 2>err &&
  33
  34        grep "fatal: cannot exec.*hello.sh" err
  35'
  36
  37test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' '
  38        mkdir local-command &&
  39        test_when_finished "chmod u+rwx local-command && rm -fr local-command" &&
  40        git config alias.nitfol "!echo frotz" &&
  41        chmod a-rx local-command &&
  42        (
  43                PATH=./local-command:$PATH &&
  44                git nitfol >actual
  45        ) &&
  46        echo frotz >expect &&
  47        test_cmp expect actual
  48'
  49
  50cat >expect <<-EOF
  51preloaded output of a child
  52Hello
  53World
  54preloaded output of a child
  55Hello
  56World
  57preloaded output of a child
  58Hello
  59World
  60preloaded output of a child
  61Hello
  62World
  63EOF
  64
  65test_expect_success 'run_command runs in parallel with more jobs available than tasks' '
  66        test-run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
  67        test_cmp expect actual
  68'
  69
  70test_expect_success 'run_command runs in parallel with as many jobs as tasks' '
  71        test-run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
  72        test_cmp expect actual
  73'
  74
  75test_expect_success 'run_command runs in parallel with more tasks than jobs available' '
  76        test-run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
  77        test_cmp expect actual
  78'
  79
  80cat >expect <<-EOF
  81preloaded output of a child
  82asking for a quick stop
  83preloaded output of a child
  84asking for a quick stop
  85preloaded output of a child
  86asking for a quick stop
  87EOF
  88
  89test_expect_success 'run_command is asked to abort gracefully' '
  90        test-run-command run-command-abort 3 false 2>actual &&
  91        test_cmp expect actual
  92'
  93
  94cat >expect <<-EOF
  95no further jobs available
  96EOF
  97
  98test_expect_success 'run_command outputs ' '
  99        test-run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
 100        test_cmp expect actual
 101'
 102
 103test_done