File: rspec_check_order_dependence

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (89 lines) | stat: -rwxr-xr-x 2,360 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash

## Usage: scripts/rspec_check_order_dependence <files...>
#
# List of RSpec files to be checked for their order dependency.
#
# If the files pass the following checks it's likely they are not
# order-dependent and are removed from `spec/support/rspec_order_todo.yml`
# to make them run in random order.
#
# The following checks are available:
# * Run specs in _defined_ order
# * Run specs in _reverse_ order
# * Run specs in _random_ order, 5 times by default.
#   - Adjustable via RANDOM_ORDER_RUNS=10 scripts/rspec_check_order_dependence

if [ $# -eq 0 ]; then
  echo "Usage: $0 <files...>"
  echo "  RANDOM_ORDER_RUNS=5 $0 <files...>"
  exit
fi

TODO_YAML='./spec/support/rspec_order_todo.yml'
RSPEC_ARGS=(--fail-fast --format progress --tag ~quarantine)
RANDOM_ORDER_RUNS=${RANDOM_ORDER_RUNS:-5}

abort() {
  echo "$@"
  echo "Aborting..."
  exit 1
}

for file in "$@"
do
  # Drop potential file prefix `./`
  file=${file#./}

  # Match only the prefix so we can specify a directory to match all the files
  # under it. For example, `spec/rubocop` will match, test and remove all TODO
  # entries starting with `./spec/rubocop`.
  grep -E -- "- './$file" "$TODO_YAML" > /dev/null || abort "Could not find '$file' in '$TODO_YAML'"
done

set -xe

export RSPEC_WARN_MISSING_FEATURE_CATEGORY=0

echo "Running in defined order:"
bin/rspec --order defined "${RSPEC_ARGS[@]}" "$@"

echo "Running in reverse order:"
RSPEC_ORDER=reverse bin/rspec "${RSPEC_ARGS[@]}" "$@"

for try in $(seq "$RANDOM_ORDER_RUNS")
do
  echo "Running in random order ($try/$RANDOM_ORDER_RUNS):"
  bin/rspec --order random "${RSPEC_ARGS[@]}" "$@"
done

set +xe

green='\033[0;32m'
clear='\033[0m' # No Color

echo -e "$green"
echo "
The files passed all checks!

They are likely not order-dependent and can be run in random order and thus
are being removed from 'spec/support/rspec_order_todo.yml':
"

for file in "$@"
do
  # Drop potential file prefix `./`
  file=${file#./}

  echo "  * Removing '$file'"

  # Escape forward slashes to make it compatible with sed below
  escaped_file=${file//\//\\/}

  # We must use -i.bak to make sed work on Linux and MacOS.
  # See https://riptutorial.com/sed/topic/9436/bsd-macos-sed-vs--gnu-sed-vs--the-posix-sed-specification
  sed -i.bak "/- '.\/$escaped_file/d" "$TODO_YAML"
  rm "$TODO_YAML.bak"
done

echo -e "$clear"