Skip to content

Commit

Permalink
Merge pull request #1 from catalyst/phpunit-fixes
Browse files Browse the repository at this point in the history
Fix PHPUnit and CI
  • Loading branch information
cameron1729 authored Mar 29, 2023
2 parents 34af646 + 1398f78 commit ef45d4f
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 21 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-18.04
runs-on: ubuntu-22.04

services:
postgres:
image: postgres:12
image: postgres:13
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
Expand All @@ -30,29 +30,45 @@ jobs:
strategy:
fail-fast: false
matrix: # I don't know why, but mariadb is much slower, so mostly use pgsql.
# We use a mix of SBCL and GCL, but mostly prefer SBCL as it is faster.
include:
- php: '7.4'
- php: '8.0'
moodle-branch: 'master'
database: 'pgsql'
maxima: 'SBCL'
- php: '7.4'
moodle-branch: 'MOODLE_401_STABLE'
database: 'pgsql'
maxima: 'SBCL'
- php: '7.4'
moodle-branch: 'MOODLE_400_STABLE'
database: 'pgsql'
maxima: 'GCL'
- php: '7.3'
moodle-branch: 'MOODLE_311_STABLE'
database: 'pgsql'
maxima: 'SBCL'
- php: '7.3'
moodle-branch: 'MOODLE_310_STABLE'
database: 'pgsql'
maxima: 'SBCL'
- php: '7.2'
moodle-branch: 'MOODLE_39_STABLE'
database: 'mariadb'
maxima: 'SBCL'

steps:
- name: Install required libraries
- name: Install Maxima (${{ matrix.maxima }})
run: |
sudo apt-get install gnuplot maxima maxima-share texinfo
maxima --list-avail
maxima="${{ (matrix.maxima == 'SBCL' && 'sbcl') || 'gcl' }}"
wget http://mirrors.kernel.org/ubuntu/pool/main/r/readline/libreadline7_7.0-3_amd64.deb \
https://sourceforge.net/projects/maxima/files/Maxima-Linux/5.42.2-Linux/maxima-common_5.42.2-1_all.deb \
https://sourceforge.net/projects/maxima/files/Maxima-Linux/5.42.2-Linux/maxima-${maxima}_5.42.2-1_amd64.deb
sudo apt-get install libtinfo5
sudo dpkg -i libreadline7_7.0-3_amd64.deb maxima-common_5.42.2-1_all.deb maxima-${maxima}_5.42.2-1_amd64.deb
echo "diff(x^2,x);" | maxima
echo "build_info();" | maxima
- name: Check out repository code
uses: actions/checkout@v2
Expand Down Expand Up @@ -83,11 +99,11 @@ jobs:
moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_MAXIMAVERSION", "5.41.0");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_MAXIMAVERSION", "5.42.2");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_MAXIMACOMMAND", "maxima");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_MAXIMACOMMANDOPT", "timeout --kill-after=10s 10s ${{ github.workspace }}/maxima_opt_auto -eval '\''(cl-user::run)'\''");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_MAXIMACOMMANDSERVER", "http://pool.home:8080/MaximaPool/MaximaPool");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_CASTIMEOUT", "10");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_CASTIMEOUT", "100");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_MAXIMALIBRARIES", "stats, distrib, descriptive, simplex");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_CASPREPARSE", "true");'
moodle-plugin-ci add-config 'define("QTYPE_STACK_TEST_CONFIG_PLATFORM", "linux-optimised");'
Expand Down
2 changes: 1 addition & 1 deletion doc/docslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function stack_docs_render_markdown($page, $preprocess = true) {
// Don't process the auto-generated answer test output.
$page = stack_maths::pre_process_docs_page($page);
}
$page = format_text($page, FORMAT_MARKDOWN, array('filter' => false, 'noclean' => true));
$page = format_text($page, FORMAT_MARKDOWN, array('filter' => false));
$page = stack_maths::post_process_docs_page($page);
return $page;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/castext_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,9 @@ public function test_numerical_display_float_scientific_small() {
// On old Maxima, you get back \(9.999999999999999e-7\).
$this->skip_if_old_maxima('5.32.1');

// For some reason 5.41.0 returns \(9.999999999999999e-7\) too.
$this->skip_if_new_maxima('5.40.0');

$st = 'Decimal number {@0.000001@}.';

$a2 = array('stackfltfmt:"~e"');
Expand Down
28 changes: 20 additions & 8 deletions tests/fixtures/test_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,28 @@ public static function prepare_actual_maths($content) {

/**
* Different versions of Maxima output floats in slighly different ways.
* Revert some of those irrelevant differences.
* We always expect the E in 3.0E8 to be upper case.
* Upper case is used to avoid a conflict with the base of the natural logarithms.
* Normalise some of those irrelevant differences.
*
* 1. Normalise E in 3.0E8 to be upper case (to avoid conflict with Euler's Number)
* 2. Normalise the coefficient to be < 10
*
* For example, the string: "Avogadro's number is 60.220e22 and the speed of light
* is about 30e7" will be normalised to "Avagardo's number is 6.022E23 and the speed
* of light is about 3E8".
*
* It also preserves the number of decimals and presence of a '+' sign.
* For example 30.0e9 becomes 3.0E10 and 3e+10 becomes 3E+11.
*/
public static function prepare_actual_maths_floats($content) {

// We don't add in a trailing zero at this point as that would break a decimal places display function test.
$content = preg_replace('~(-?\b\d+(?:\.\d*)?)e([-+]?\d+\b)~', '$1E$2', $content);

return $content;
return preg_replace_callback(
'~(-?\b\d+(?:\.\d*)?)[eE]([-+]?\d+\b)~',
function(array $matches): string {
$decimals = strlen(explode('.', $matches[1])[1] ?? '') ?: 0;
$fixedbase = sprintf("%.${decimals}E", (float)$matches[0]);
return strpos($matches[2], '+') !== false ? $fixedbase : str_replace('+', '', $fixedbase);
},
$content
);
}

/**
Expand Down
7 changes: 3 additions & 4 deletions tests/mathsoutputtex_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ public function test_tex_rendering() {
.'<a .*alt="x\^2".*</(a|script)> \.</p>\n$~',
stack_docs_render_markdown('<code>\(x^2\)</code> gives \(x^2\).'));

// Test docs - make sure maths inside <textarea> is not rendered, and <textarea> is retained.
$expectation = '<p><textarea readonly="readonly" rows="3" cols="50">' . "\n" .
'Differentiate \[x^2 + y^2\] with respect to \(x\).</textarea></p>' . "\n";
$this->assertEquals($expectation,
// Test docs - make sure maths inside <textarea> is not rendered.
$this->assertMatchesRegularExpression('~^<p>.*\n' .
'Differentiate \\\\\\\\\[x\^2 \+ y\^2\\\\\\\\\] with respect to \\\\\\\\\(x\\\\\\\\\)\..*</p>\n$~',
stack_docs_render_markdown('<textarea readonly="readonly" rows="3" cols="50">' . "\n" .
'Differentiate \[x^2 + y^2\] with respect to \(x\).</textarea>'));

Expand Down

0 comments on commit ef45d4f

Please sign in to comment.