Skip to content

Commit f0d0075

Browse files
jasaltChemaclassJesusValeraDev
committed
Support running against Phel
Clojure-like Lisp compiling to PHP For non-squashed commit history see archived branch at: https://github.com/phel-lang/clojure-test-suite/tree/phel-integration Co-authored-by: Chemaclass <chemaclass@outlook.es> Co-authored-by: Jesus Valera Reales <github@jesusvalera.dev>
1 parent eb8daa1 commit f0d0075

46 files changed

Lines changed: 333 additions & 102 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,35 @@ jobs:
162162
BASILISP_TEST_PATH="$(pwd)/test" \
163163
BASILISP_TEST_FILE_PATTERN='.*\.(lpy|cljc)' \
164164
basilisp test -p test -- -n auto
165+
166+
test-phel:
167+
runs-on: ubuntu-latest
168+
strategy:
169+
fail-fast: false
170+
matrix:
171+
php: ['8.4', '8.5']
172+
steps:
173+
- uses: actions/checkout@v4
174+
175+
- uses: shivammathur/setup-php@v2
176+
with:
177+
php-version: ${{ matrix.php }}
178+
coverage: none
179+
tools: composer
180+
181+
- name: Get composer cache directory
182+
id: composer-cache
183+
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
184+
185+
- name: Cache dependencies
186+
uses: actions/cache@v4
187+
with:
188+
path: ${{ steps.composer-cache.outputs.dir }}
189+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
190+
restore-keys: ${{ runner.os }}-composer-
191+
192+
- name: Install dependencies
193+
run: composer install --no-interaction --no-ansi --no-progress
194+
195+
- name: Run tests
196+
run: php -d memory_limit=256M ./vendor/bin/phel test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ __pycache__/
2828
poetry.lock
2929
*.egg-info/
3030
.DS_Store
31+
/vendor/

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ See these documents for how to set up individual dialect-specific environments a
2222
3. [Babashka](doc/babashka.md)
2323
4. [Clojure CLR](doc/clojureclr.md)
2424
5. [Basilisp](doc/basilisp.md)
25+
6. [Phel](doc/phel.md)

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"require": {
3+
"phel-lang/phel-lang": "dev-main"
4+
},
5+
"minimum-stability": "dev"
6+
}

doc/phel.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Running the Phel tests
2+
3+
## Prerequisites
4+
5+
- PHP 8.4+ & [Composer](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos)
6+
7+
Install:
8+
```
9+
composer install
10+
```
11+
12+
Tests live in `test/` (override via `phel-config.php`).
13+
14+
See also [Getting Started guide](https://phel-lang.org/documentation/getting-started/).
15+
16+
## Running the test suite
17+
18+
Full suite:
19+
```
20+
./vendor/bin/phel test
21+
```
22+
Specific test:
23+
```
24+
./vendor/bin/phel test test/clojure/core_test/abs.cljc
25+
```
26+
27+
If runner crashes before report, re-run with `--testdox` or `-v` to locate failing test.
28+
29+
See [Phel testing docs](https://phel-lang.org/documentation/testing/#running-tests).
30+
31+
## Updating Phel version
32+
33+
`composer.json` tracks `dev-main` (latest [phel-lang](https://github.com/phel-lang/phel-lang/) HEAD):
34+
```json
35+
{
36+
"require": {
37+
"phel-lang/phel-lang": "dev-main"
38+
},
39+
"minimum-stability": "dev"
40+
}
41+
```
42+
43+
Pull latest:
44+
```
45+
composer update phel-lang/phel-lang
46+
```
47+
48+
Pin specific commit (optional):
49+
```
50+
composer require "phel-lang/phel-lang:dev-main#<commit-hash>"
51+
```

phel-config.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
// Override Phel's default 'tests' TestDirs path
3+
// Reference: https://phel-lang.org/documentation/configuration/
4+
return (new \Phel\Config\PhelConfig())
5+
->setSrcDirs(['src'])
6+
->setTestDirs(['test']);

test/clojure/core_test/aclone.cljc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@
1313
(is (= 3 (alength a')))
1414
(is (every? identity (map #(= (aget a %) (aget a' %)) (range 3))))
1515
(is (zero? (alength b')))
16-
(is (not (identical? a a')))
17-
(is (not (identical? b b')))
16+
;; Phel PHP arrays are value types without reference-identity concept
17+
;; https://github.com/phel-lang/phel-lang/issues/1735
18+
#?@(:phel
19+
[(is (identical? a a'))
20+
(is (identical? b b'))]
21+
:default
22+
[(is (not (identical? a a')))
23+
(is (not (identical? b b')))])
1824
(aset a 1 11)
1925
(is (= 11 (aget a 1)))
2026
(is (= 2 (aget a' 1)))

test/clojure/core_test/add_watch.cljc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
(catch #?(:cljs :default
2121
:clj clojure.lang.ExceptionInfo
2222
:cljr clojure.lang.ExceptionInfo
23-
:lpy basilisp.lang.exception/ExceptionInfo) e
23+
:lpy basilisp.lang.exception/ExceptionInfo
24+
:phel Phel.Lang.ExInfoException) e
2425
(let [data (ex-data e)]
2526
(vswap! state conj data)))))]
2627
(do-update a)
@@ -73,6 +74,7 @@
7374
{:key :e :ref r :old 14 :new 15 :tester :err})))))
7475

7576
#?@(:cljs []
77+
:phel []
7678
:default
7779
[(def testvar-a 0)
7880
(def testvar-b 10)
@@ -145,6 +147,7 @@
145147

146148
#?(:cljs nil
147149
:lpy nil
150+
:phel nil
148151
:default
149152
(testing "watch ref"
150153
(let [state (volatile! [])
@@ -217,6 +220,7 @@
217220

218221
#?@(:cljs []
219222
:lpy []
223+
:phel []
220224
:default
221225
[(testing "watch agent"
222226
(let [state (volatile! [])

test/clojure/core_test/ancestors.cljc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
(when-var-exists ancestors
66

77
; Some classes for testing ancestors by type inheritance
8-
(def AncestorT #?(:cljs js/Object :lpy python/object :default Object))
9-
(def ChildT #?(:cljs :default :lpy basilisp.lang.set/PersistentSet :default clojure.lang.PersistentHashSet))
8+
(def AncestorT #?(:cljs js/Object :lpy python/object :phel ArrayIterator :default Object))
9+
(def ChildT #?(:cljs :default :lpy basilisp.lang.set/PersistentSet :phel RecursiveArrayIterator :default clojure.lang.PersistentHashSet))
1010

1111
; Some custom types for testing ancestors by type inheritance
1212
(defprotocol TestAncestorsProtocol)
@@ -73,14 +73,15 @@
7373

7474
(testing "returns ancestors by type inheritance when tag is a class"
7575
#?(:cljs "cljs doesn't report ancestors by type inheritance yet (CLJS-3464)"
76+
:phel (is (contains? (ancestors ChildT) AncestorT))
7677
:clj (is (contains? (ancestors ChildT) AncestorT))))
7778

7879
#?(:bb "bb doesn't report ancestors by type inheritance for custom types"
7980
:cljs "cljs doesn't report ancestors by type inheritance yet (CLJS-3464)"
8081
:default (testing "returns ancestors by type inheritance when tag is a custom type"
81-
(is (contains? (ancestors TestAncestorsType) #?(:lpy (:interface TestAncestorsProtocol) :default clojure.core_test.ancestors.TestAncestorsProtocol)))
82-
(is (contains? (ancestors TestAncestorsRecord) #?(:lpy (:interface TestAncestorsProtocol) :default clojure.core_test.ancestors.TestAncestorsProtocol)))
83-
(is (contains? (ancestors TestAncestorsRecord) #?(:lpy basilisp.lang.interfaces/IAssociative :default clojure.lang.Associative)))
82+
(is (contains? (ancestors TestAncestorsType) #?(:lpy (:interface TestAncestorsProtocol) :phel TestAncestorsProtocol :default clojure.core_test.ancestors.TestAncestorsProtocol)))
83+
(is (contains? (ancestors TestAncestorsRecord) #?(:lpy (:interface TestAncestorsProtocol) :phel TestAncestorsProtocol :default clojure.core_test.ancestors.TestAncestorsProtocol)))
84+
(is (contains? (ancestors TestAncestorsRecord) #?(:lpy basilisp.lang.interfaces/IAssociative :phel Phel.Lang.Collections.Map.PersistentMapInterface :default clojure.lang.Associative)))
8485
(is (nil? (ancestors TestAncestorsProtocol)))))
8586

8687
(testing "does not throw on invalid tag"
@@ -142,8 +143,8 @@
142143
:cljs "cljs doesn't report ancestors by type inheritance yet (CLJS-3464)"
143144
:default (testing "returns ancestors by type inheritance when tag is a custom type, whether the tag is in h or not"
144145
(are [h tag] (let [actual-ancestors (ancestors h tag)]
145-
(and (contains? actual-ancestors #?(:lpy (:interface TestAncestorsProtocol) :default clojure.core_test.ancestors.TestAncestorsProtocol))
146-
(contains? actual-ancestors #?(:lpy basilisp.lang.interfaces/IAssociative :default clojure.lang.Associative))))
146+
(and (contains? actual-ancestors #?(:lpy (:interface TestAncestorsProtocol) :phel TestAncestorsProtocol :default clojure.core_test.ancestors.TestAncestorsProtocol))
147+
(contains? actual-ancestors #?(:lpy basilisp.lang.interfaces/IAssociative :phel Phel.Lang.Collections.Map.PersistentMapInterface :default clojure.lang.Associative))))
147148
; tag in h
148149
datatypes TestAncestorsRecord
149150
; tag not in h

test/clojure/core_test/associative_qmark.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@
1919
false #{}
2020
false #{:a :b}
2121
false "ab"
22-
false (seq "ab") ; seq
23-
false (to-array [1 2 3])
22+
23+
#?@(:phel [true (seq "ab") ; PHP arrays are associative
24+
true (to-array [1 2 3])]
25+
:default
26+
[false (seq "ab") ; seq
27+
false (to-array [1 2 3])])
2428
false :a
2529
false 'a
2630
false 1

0 commit comments

Comments
 (0)