t / t0061-run-command.shon commit run-command: use the async-signal-safe execv instead of execvp (e3a4344)
   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 !MINGW 'run_command can run a script without a #! line' '
  30        cat >hello <<-\EOF &&
  31        cat hello-script
  32        EOF
  33        chmod +x hello &&
  34        test-run-command run-command ./hello >actual 2>err &&
  35
  36        test_cmp hello-script actual &&
  37        test_cmp empty err
  38'
  39
  40test_expect_success POSIXPERM 'run_command reports EACCES' '
  41        cat hello-script >hello.sh &&
  42        chmod -x hello.sh &&
  43        test_must_fail test-run-command run-command ./hello.sh 2>err &&
  44
  45        grep "fatal: cannot exec.*hello.sh" err
  46'
  47
  48test_expect_success POSIXPERM,SANITY 'unreadable directory in PATH' '
  49        mkdir local-command &&
  50        test_when_finished "chmod u+rwx local-command && rm -fr local-command" &&
  51        git config alias.nitfol "!echo frotz" &&
  52        chmod a-rx local-command &&
  53        (
  54                PATH=./local-command:$PATH &&
  55                git nitfol >actual
  56        ) &&
  57        echo frotz >expect &&
  58        test_cmp expect actual
  59'
  60
  61cat >expect <<-EOF
  62preloaded output of a child
  63Hello
  64World
  65preloaded output of a child
  66Hello
  67World
  68preloaded output of a child
  69Hello
  70World
  71preloaded output of a child
  72Hello
  73World
  74EOF
  75
  76test_expect_success 'run_command runs in parallel with more jobs available than tasks' '
  77        test-run-command run-command-parallel 5 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
  78        test_cmp expect actual
  79'
  80
  81test_expect_success 'run_command runs in parallel with as many jobs as tasks' '
  82        test-run-command run-command-parallel 4 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
  83        test_cmp expect actual
  84'
  85
  86test_expect_success 'run_command runs in parallel with more tasks than jobs available' '
  87        test-run-command run-command-parallel 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
  88        test_cmp expect actual
  89'
  90
  91cat >expect <<-EOF
  92preloaded output of a child
  93asking for a quick stop
  94preloaded output of a child
  95asking for a quick stop
  96preloaded output of a child
  97asking for a quick stop
  98EOF
  99
 100test_expect_success 'run_command is asked to abort gracefully' '
 101        test-run-command run-command-abort 3 false 2>actual &&
 102        test_cmp expect actual
 103'
 104
 105cat >expect <<-EOF
 106no further jobs available
 107EOF
 108
 109test_expect_success 'run_command outputs ' '
 110        test-run-command run-command-no-jobs 3 sh -c "printf \"%s\n%s\n\" Hello World" 2>actual &&
 111        test_cmp expect actual
 112'
 113
 114test_done