|
11 | 11 | branches: [ master ] |
12 | 12 |
|
13 | 13 | jobs: |
14 | | - # Job: Unit test suite |
15 | | - unit-tests: |
16 | | - name: "Unit Tests" |
17 | | - runs-on: ubuntu-latest |
| 14 | + # Job: Ruby unit tests across all supported Ruby versions and OSes. |
| 15 | + # These are fast (no C compilation) and verify the generator logic is Ruby-version-portable. |
| 16 | + ruby-tests: |
| 17 | + name: "Ruby Tests (${{ matrix.os }}, Ruby ${{ matrix.ruby }})" |
| 18 | + runs-on: ${{ matrix.os }} |
18 | 19 | strategy: |
| 20 | + fail-fast: false |
19 | 21 | matrix: |
| 22 | + os: [ubuntu-latest, windows-latest, macos-latest] |
20 | 23 | ruby: ['3.0', '3.1', '3.2', '3.3'] |
| 24 | + exclude: |
| 25 | + # create sparse matrix to avoid pointless duplication |
| 26 | + - os: macos-latest |
| 27 | + ruby: '3.0' |
| 28 | + - os: macos-latest |
| 29 | + ruby: '3.1' |
| 30 | + - os: macos-latest |
| 31 | + ruby: '3.2' |
| 32 | + - os: windows-latest |
| 33 | + ruby: '3.0' |
| 34 | + - os: windows-latest |
| 35 | + ruby: '3.1' |
| 36 | + - os: windows-latest |
| 37 | + ruby: '3.2' |
21 | 38 | steps: |
22 | | - # Install Multilib |
| 39 | + - name: Checkout Latest Repo |
| 40 | + uses: actions/checkout@v4 |
| 41 | + with: |
| 42 | + submodules: recursive |
| 43 | + |
| 44 | + - name: Setup Ruby |
| 45 | + uses: ruby/setup-ruby@v1 |
| 46 | + with: |
| 47 | + ruby-version: ${{ matrix.ruby }} |
| 48 | + |
| 49 | + - name: Install Ruby Dependencies |
| 50 | + run: | |
| 51 | + gem install bundler |
| 52 | + bundle install |
| 53 | +
|
| 54 | + - name: Run Ruby Unit Tests |
| 55 | + env: |
| 56 | + NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} |
| 57 | + run: | |
| 58 | + cd test && rake test:unit |
| 59 | +
|
| 60 | + - name: Run Style Check |
| 61 | + env: |
| 62 | + NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} |
| 63 | + run: | |
| 64 | + cd test && rake style:check |
| 65 | +
|
| 66 | + # Job: C compilation and system tests — only needs to run on one Ruby version per OS, |
| 67 | + # since the generated C code and runtime behavior don't vary with the Ruby version. |
| 68 | + c-tests: |
| 69 | + name: "C Tests (${{ matrix.os }})" |
| 70 | + runs-on: ${{ matrix.os }} |
| 71 | + strategy: |
| 72 | + fail-fast: false |
| 73 | + matrix: |
| 74 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 75 | + steps: |
| 76 | + # Install Multilib (Linux only) |
23 | 77 | - name: Install Multilib |
| 78 | + if: matrix.os == 'ubuntu-latest' |
24 | 79 | run: | |
25 | 80 | sudo apt-get update -qq |
26 | 81 | sudo apt-get install --assume-yes --quiet gcc-multilib |
27 | 82 |
|
28 | | - # Checks out repository under $GITHUB_WORKSPACE |
| 83 | + # Add MinGW GCC to PATH (Windows only — MSYS2 is pre-installed on the runner) |
| 84 | + - name: Add GCC to PATH |
| 85 | + if: matrix.os == 'windows-latest' |
| 86 | + run: echo "C:\msys64\mingw64\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append |
| 87 | + |
29 | 88 | - name: Checkout Latest Repo |
30 | | - uses: actions/checkout@v2 |
31 | | - with: |
| 89 | + uses: actions/checkout@v4 |
| 90 | + with: |
32 | 91 | submodules: recursive |
33 | 92 |
|
34 | | - # Setup Ruby Testing Tools to do tests on multiple ruby version |
35 | | - - name: Setup Ruby Testing Tools |
| 93 | + - name: Setup Ruby |
36 | 94 | uses: ruby/setup-ruby@v1 |
37 | 95 | with: |
38 | | - ruby-version: ${{ matrix.ruby }} |
| 96 | + ruby-version: '3.3' |
39 | 97 |
|
40 | | - # Install Ruby Testing Tools |
41 | | - - name: Setup Ruby Testing Tools |
| 98 | + - name: Install Ruby Dependencies |
42 | 99 | run: | |
43 | | - sudo gem install rspec |
44 | | - sudo gem install rubocop -v 1.57.2 |
45 | | - sudo gem install bundler |
46 | | - bundle update |
47 | | - bundle install |
| 100 | + gem install bundler |
| 101 | + bundle install |
| 102 | +
|
| 103 | + - name: Run C Unit Tests |
| 104 | + env: |
| 105 | + NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} |
| 106 | + run: cd test && rake test:c |
| 107 | + |
| 108 | + - name: Run System Tests |
| 109 | + env: |
| 110 | + NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} |
| 111 | + run: cd test && rake test:system |
| 112 | + |
| 113 | + - name: Run Examples |
| 114 | + env: |
| 115 | + NO_COLOR: ${{ matrix.os == 'windows-latest' && '1' || '' }} |
| 116 | + run: cd test && rake test:examples |
| 117 | + |
| 118 | + # Job: Valgrind memory-leak check (Linux/gcc_64 only, latest Ruby) |
| 119 | + valgrind: |
| 120 | + name: "Valgrind Memory Check" |
| 121 | + runs-on: ubuntu-latest |
| 122 | + steps: |
| 123 | + - name: Install Dependencies |
| 124 | + run: | |
| 125 | + sudo apt-get update -qq |
| 126 | + sudo apt-get install --assume-yes --quiet gcc-multilib valgrind |
| 127 | +
|
| 128 | + - name: Checkout Latest Repo |
| 129 | + uses: actions/checkout@v4 |
| 130 | + with: |
| 131 | + submodules: recursive |
| 132 | + |
| 133 | + - name: Setup Ruby |
| 134 | + uses: ruby/setup-ruby@v1 |
| 135 | + with: |
| 136 | + ruby-version: '3.3' |
| 137 | + |
| 138 | + - name: Install Ruby Dependencies |
| 139 | + run: | |
| 140 | + gem install bundler |
| 141 | + bundle install |
| 142 | +
|
| 143 | + # Build and run C unit tests, then re-run the executable under valgrind. |
| 144 | + # test:system clobbers the build directory, so check TestCMockC before that happens. |
| 145 | + - name: Build and Run C Unit Tests |
| 146 | + run: cd test && rake config[gcc_64_valgrind] test:c |
| 147 | + |
| 148 | + - name: Valgrind Check - C Unit Tests |
| 149 | + run: | |
| 150 | + valgrind --leak-check=full --track-origins=yes --error-exitcode=1 \ |
| 151 | + test/system/build/TestCMockC.exe |
| 152 | +
|
| 153 | + # Build and run system tests, then re-run each executable under valgrind. |
| 154 | + - name: Build and Run System Tests |
| 155 | + run: cd test && rake config[gcc_64_valgrind] test:system |
48 | 156 |
|
49 | | - # Run Tests |
50 | | - - name: Run All Unit Tests |
| 157 | + - name: Valgrind Check - System Tests |
51 | 158 | run: | |
52 | | - cd test && rake ci |
| 159 | + failed=0 |
| 160 | + for exe in test/system/build/test_*.exe; do |
| 161 | + echo "Checking: $exe" |
| 162 | + # Use exit code 42 to distinguish valgrind errors from Unity test failures. |
| 163 | + # Some executables intentionally contain tests expected to fail (testing CMock's |
| 164 | + # error-handling), so Unity exits non-zero. The `|| exit_code=$?` prevents bash's |
| 165 | + # set -e from aborting the script on Unity's non-zero exit, while still capturing |
| 166 | + # valgrind's own error exit code (42) separately. |
| 167 | + exit_code=0 |
| 168 | + valgrind --leak-check=full --track-origins=yes --error-exitcode=42 "$exe" || exit_code=$? |
| 169 | + [ $exit_code -eq 42 ] && failed=1 |
| 170 | + done |
| 171 | + exit $failed |
0 commit comments