|  | 
|  | 1 | +name: Test | 
|  | 2 | + | 
|  | 3 | +on: pull_request | 
|  | 4 | + | 
|  | 5 | +jobs: | 
|  | 6 | +  test: | 
|  | 7 | +    strategy: | 
|  | 8 | +      matrix: | 
|  | 9 | +        os: [ubuntu-latest] # TODO Add macos-latest and windows-latest | 
|  | 10 | +        shell: [bash, busybox, dash, ksh, mksh, yash, zsh] # TODO Add ksh88, osh, pbosh, posh | 
|  | 11 | +    runs-on: ${{ matrix.os }} | 
|  | 12 | +    steps: | 
|  | 13 | +      - uses: actions/checkout@v4 | 
|  | 14 | +      - name: Install esoteric shell | 
|  | 15 | +        if: ${{ contains(fromJSON('["busybox", "ksh", "mksh", "yash", "zsh"]'), matrix.shell) }} | 
|  | 16 | +        run: | | 
|  | 17 | +          sudo apt update -y | 
|  | 18 | +          sudo apt install ${{ matrix.shell }} -y | 
|  | 19 | +      - name: Set shell | 
|  | 20 | +        if: ${{ matrix.os == 'ubuntu-latest' }} | 
|  | 21 | +        run: sudo ln -sf /usr/bin/${{ matrix.shell }} /bin/sh | 
|  | 22 | +      - name: Check exit status definitions | 
|  | 23 | +        run: | | 
|  | 24 | +          . ./updater.sh 2>/dev/null | 
|  | 25 | +
 | 
|  | 26 | +          while IFS='=' read -r name code; do | 
|  | 27 | +              # "When reporting the exit status with the special parameter '?', | 
|  | 28 | +              # the shell shall report the full eight bits of exit status available." | 
|  | 29 | +              # ―https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_08_02 | 
|  | 30 | +              # "exit [n]: If n is specified, but its value is not between 0 and 255 | 
|  | 31 | +              # inclusively, the exit status is undefined." | 
|  | 32 | +              # ―https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_21 | 
|  | 33 | +              [ "$code" -ge 0 ] && [ "$code" -le 255 ] || { | 
|  | 34 | +                  printf '%s %s\n' 'Undefined exit status in the definition:' \ | 
|  | 35 | +                      "$name=$code." >&2 | 
|  | 36 | +                  exit 70 # Internal software error. | 
|  | 37 | +              } | 
|  | 38 | +          done <<EOF | 
|  | 39 | +          $(exit_status_definitions) | 
|  | 40 | +          EOF | 
|  | 41 | +      - name: Tests setup | 
|  | 42 | +        run: | | 
|  | 43 | +          set +e | 
|  | 44 | +          . ./updater.sh && exit_status_definitions >> $GITHUB_ENV | 
|  | 45 | +      - name: Check that running as root returns EX_USAGE | 
|  | 46 | +        run: sudo ./updater.sh -x 2>/dev/null || { [ "$?" -eq $_EX_USAGE ] && exit 0; } | 
|  | 47 | +      - name: Check that passing a wrong option returns EX_USAGE | 
|  | 48 | +        run: ./updater.sh -x 2>/dev/null || { [ "$?" -eq $_EX_USAGE ] && exit 0; } | 
|  | 49 | +      - name: Check that --help returns EX_OK and not EX__BASE | 
|  | 50 | +        run: ./updater.sh -h > /dev/null | 
|  | 51 | +      - name: Check that if the profile doesn't have at least d-wx permissions, returns EX_UNAVAILABLE | 
|  | 52 | +        run: | | 
|  | 53 | +          unxable_temp_dir=$(mktemp -d) | 
|  | 54 | +          chmod 444 $unxable_temp_dir | 
|  | 55 | +          ./updater.sh -p $unxable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_UNAVAILABLE ] && exit 1; } | 
|  | 56 | +          unwable_temp_dir=$(mktemp -d) | 
|  | 57 | +          chmod 111 $unwable_temp_dir | 
|  | 58 | +          ./updater.sh -p $unwable_temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_UNAVAILABLE ] && exit 1; } | 
|  | 59 | +          exit 0 | 
|  | 60 | +      - name: Check that if the profiles.ini doesn't exist, returns EX_NOINPUT | 
|  | 61 | +        run: | | 
|  | 62 | +          temp_dir=$(mktemp -d) | 
|  | 63 | +          chmod 777 $temp_dir | 
|  | 64 | +          ./updater.sh -l > /dev/null 2>&1 || { [ "$?" -ne $_EX_NOINPUT ] && exit 1; } | 
|  | 65 | +          exit 0 | 
|  | 66 | +      - name: Check that if the profile requires root privileges, returns EX_CONFIG | 
|  | 67 | +        run: | | 
|  | 68 | +          temp_dir=$(mktemp -d) | 
|  | 69 | +          sudo chmod 777 $temp_dir | 
|  | 70 | +          sudo touch $temp_dir/user.js | 
|  | 71 | +          ./updater.sh -p $temp_dir > /dev/null 2>&1 || { [ "$?" -ne $_EX_CONFIG ] && exit 1; } | 
|  | 72 | +          exit 0 | 
|  | 73 | +      - name: Check that the profile contains something after execution | 
|  | 74 | +        run: | | 
|  | 75 | +          temp_dir=$(mktemp -d) | 
|  | 76 | +          echo "temp_dir=$temp_dir" >> $GITHUB_ENV | 
|  | 77 | +          touch $temp_dir/user.js | 
|  | 78 | +          yes | ./updater.sh -p $temp_dir | 
|  | 79 | +          [ -s $temp_dir/user.js ] || exit 1 | 
|  | 80 | +      - name: Check that the profile contains the most recent user.js after execution | 
|  | 81 | +        run: | | 
|  | 82 | +          wget -qO user.js https://raw.githubusercontent.com/arkenfox/user.js/refs/heads/master/user.js | 
|  | 83 | +          diff user.js $temp_dir/user.js | 
0 commit comments