Skip to content

Commit 5ccfe1b

Browse files
authored
Merge pull request #6 from KyleKincer/codex/locate-method-to-run-unit-tests-with-tool4d
Tag Linux-incompatible test and improve cross-platform testing
2 parents be2a0ad + 6ca622a commit 5ccfe1b

File tree

3 files changed

+114
-17
lines changed

3 files changed

+114
-17
lines changed

Makefile

Lines changed: 52 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,19 @@
33
# Get current user's home directory
44
HOME_DIR := $(shell echo $$HOME)
55

6-
# 4D tool path
6+
# Determine operating system
7+
UNAME_S := $(shell uname -s)
8+
9+
# 4D tool path and default exclusion tags
10+
ifeq ($(UNAME_S),Darwin)
711
TOOL4D := /Applications/tool4d.app/Contents/MacOS/tool4d
12+
else
13+
TOOL4D := /opt/tool4d/tool4d
14+
DEFAULT_EXCLUDE_TAGS := no-linux
15+
endif
16+
17+
# URL for downloading tool4d by platform
18+
TOOL4D_URL_LINUX := https://resources-download.4d.com/release/20%20Rx/latest/latest/linux/tool4d.deb
819

920
# Project path relative to current directory
1021
PROJECT_PATH := $(PWD)/testing/Project/testing.4DProject
@@ -15,50 +26,74 @@ BASE_OPTS := --project $(PROJECT_PATH) --skip-onstartup --dataless --startup-met
1526
# Default target
1627
.DEFAULT_GOAL := test
1728

29+
# Internal helpers for tag handling
30+
empty :=
31+
space := $(empty) $(empty)
32+
comma := ,
33+
34+
EXCLUDE_TAGS_COMBINED := $(strip $(DEFAULT_EXCLUDE_TAGS) $(excludeTags))
35+
BASE_PARAMS := $(if $(EXCLUDE_TAGS_COMBINED),excludeTags=$(subst $(space),$(comma),$(EXCLUDE_TAGS_COMBINED)))
36+
1837
# Build user parameters from make variables
19-
USER_PARAMS := $(strip $(if $(format),format=$(format)) $(if $(tags),tags=$(tags)) $(if $(test),test=$(test)) $(if $(excludeTags),excludeTags=$(excludeTags)) $(if $(requireTags),requireTags=$(requireTags)))
38+
USER_PARAMS := $(strip $(BASE_PARAMS) $(if $(format),format=$(format)) $(if $(tags),tags=$(tags)) $(if $(test),test=$(test)) $(if $(requireTags),requireTags=$(requireTags)))
39+
40+
# Ensure tool4d is installed (currently implemented for Linux only)
41+
$(TOOL4D):
42+
@echo "tool4d not found at $(TOOL4D). Installing..."
43+
@if [ "$(UNAME_S)" = "Linux" ]; then \
44+
apt-get update && \
45+
apt-get install -y curl libc++1 uuid-runtime libfreeimage3 xdg-user-dirs; \
46+
curl -L -o /tmp/libtinfo5.deb http://archive.ubuntu.com/ubuntu/pool/main/n/ncurses/libtinfo5_6.1-1ubuntu1_amd64.deb; \
47+
curl -L -o /tmp/libncurses5.deb http://archive.ubuntu.com/ubuntu/pool/main/n/ncurses/libncurses5_6.1-1ubuntu1_amd64.deb; \
48+
dpkg -i /tmp/libtinfo5.deb /tmp/libncurses5.deb; \
49+
curl -L -o /tmp/tool4d.deb $(TOOL4D_URL_LINUX); \
50+
dpkg --force-depends -i /tmp/tool4d.deb; \
51+
else \
52+
echo "Automatic installation for $(UNAME_S) not implemented. Please install tool4d manually."; \
53+
exit 1; \
54+
fi
2055

21-
# Run all tests with human-readable output
56+
# Run all tests with human-readable output
2257
# Usage: make test [key=value key2=value2 ...]
2358
# Example: make test format=json tags=unit
24-
test:
59+
test: $(TOOL4D)
2560
@if [ -n "$(USER_PARAMS)" ]; then \
26-
$(TOOL4D) $(BASE_OPTS) --user-param "$(USER_PARAMS)"; \
61+
$(TOOL4D) $(BASE_OPTS) --user-param "$(USER_PARAMS)"; \
2762
else \
28-
$(TOOL4D) $(BASE_OPTS); \
63+
$(TOOL4D) $(BASE_OPTS); \
2964
fi
3065

3166
# Run all tests with JSON output
3267
test-json:
33-
$(TOOL4D) $(BASE_OPTS) --user-param "format=json"
68+
$(MAKE) test format=json
3469

3570
# Run specific test class (usage: make test-class CLASS=ExampleTest)
3671
test-class:
37-
$(TOOL4D) $(BASE_OPTS) --user-param "test=$(CLASS)"
72+
$(MAKE) test test=$(CLASS)
3873

3974
# Run tests by tags (usage: make test-tags TAGS=unit)
4075
test-tags:
41-
$(TOOL4D) $(BASE_OPTS) --user-param "tags=$(TAGS)"
76+
$(MAKE) test tags=$(TAGS)
4277

4378
# Run tests excluding tags (usage: make test-exclude-tags TAGS=slow)
4479
test-exclude-tags:
45-
$(TOOL4D) $(BASE_OPTS) --user-param "excludeTags=$(TAGS)"
80+
$(MAKE) test excludeTags=$(TAGS)
4681

4782
# Run tests requiring specific tags (usage: make test-require-tags TAGS=unit,fast)
4883
test-require-tags:
49-
$(TOOL4D) $(BASE_OPTS) --user-param "requireTags=$(TAGS)"
84+
$(MAKE) test requireTags=$(TAGS)
5085

5186
# Run unit tests only
5287
test-unit:
53-
$(TOOL4D) $(BASE_OPTS) --user-param "tags=unit"
88+
$(MAKE) test tags=unit
5489

5590
# Run integration tests only
5691
test-integration:
57-
$(TOOL4D) $(BASE_OPTS) --user-param "tags=integration"
92+
$(MAKE) test tags=integration
5893

5994
# Run tests with JSON output and unit tag
6095
test-unit-json:
61-
$(TOOL4D) $(BASE_OPTS) --user-param "format=json tags=unit"
96+
$(MAKE) test format=json tags=unit
6297

6398
# Show help
6499
help:
@@ -84,5 +119,7 @@ help:
84119
@echo " make test-class CLASS=TaggingSystemTest"
85120
@echo " make test-tags TAGS=unit,fast"
86121
@echo " make test-exclude-tags TAGS=slow"
122+
tool4d: $(TOOL4D)
123+
@echo "tool4d ready at $(TOOL4D)"
87124

88-
.PHONY: test test-json test-class test-tags test-exclude-tags test-require-tags test-unit test-integration test-unit-json help
125+
.PHONY: test test-json test-class test-tags test-exclude-tags test-require-tags test-unit test-integration test-unit-json help tool4d

docs/running-tests-linux.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Running 4D Unit Tests on Linux
2+
3+
The repository now includes automated tooling to fetch and install the experimental Linux build of **tool4d** and its required dependencies. The `Makefile` handles everything for you.
4+
5+
## Quick start
6+
7+
```bash
8+
make test
9+
```
10+
11+
On the first run this will:
12+
13+
1. Install the libraries `libc++1`, `uuid-runtime`, `libfreeimage3`, `xdg-user-dirs`, `libtinfo5`, and `libncurses5` if they are missing.
14+
2. Download and install the latest Linux `tool4d` package to `/opt/tool4d`.
15+
3. Execute the project's test suite, automatically skipping tests tagged `no-linux`.
16+
17+
You can also bootstrap the environment without running the tests:
18+
19+
```bash
20+
make tool4d
21+
```
22+
23+
Once the setup has completed, subsequent invocations of `make test` reuse the installed tooling and run quickly.
24+
25+
## Manual installation
26+
27+
The steps above are sufficient for most scenarios. If you need to perform the setup manually (for example, in a container without `make`), the commands executed by the `Makefile` are:
28+
29+
```bash
30+
apt-get update
31+
apt-get install -y curl libc++1 uuid-runtime libfreeimage3 xdg-user-dirs
32+
curl -L -o /tmp/libtinfo5.deb http://archive.ubuntu.com/ubuntu/pool/main/n/ncurses/libtinfo5_6.1-1ubuntu1_amd64.deb
33+
curl -L -o /tmp/libncurses5.deb http://archive.ubuntu.com/ubuntu/pool/main/n/ncurses/libncurses5_6.1-1ubuntu1_amd64.deb
34+
dpkg -i /tmp/libtinfo5.deb /tmp/libncurses5.deb
35+
curl -L -o /tmp/tool4d.deb https://resources-download.4d.com/release/20%20Rx/latest/latest/linux/tool4d.deb
36+
dpkg --force-depends -i /tmp/tool4d.deb
37+
```
38+
39+
After installation, run the tests manually:
40+
41+
```bash
42+
/opt/tool4d/tool4d --project /workspace/testing/testing/Project/testing.4DProject \
43+
--skip-onstartup --dataless --startup-method test \
44+
--user-param "excludeTags=no-linux"
45+
```
46+
47+
The output should end with a summary similar to:
48+
49+
```
50+
=== Test Results Summary ===
51+
Total Tests: 131
52+
Passed: 131
53+
Failed: 0
54+
Pass Rate: 100.0%
55+
```
56+
57+
## Notes
58+
- Tests tagged `no-linux` are excluded by default on Linux (for example, `_TaggingExampleTest.test_file_system_access`).
59+
- The Linux build runs headlessly and does **not** require Wine or a graphical environment.
60+
- Previous attempts to run the Windows build via Wine were unstable and are not recommended.

testing/Project/Sources/Classes/_TaggingExampleTest.4dm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ Function test_parameter_validation($t : cs:C1710.Testing)
3535
$result:=(Null:C1517=Null:C1517)
3636
$t.assert.isTrue($t; $result; "Null comparison should work")
3737

38-
// #tags: integration, external
38+
// #tags: integration, external, no-linux
3939
Function test_file_system_access($t : cs:C1710.Testing)
4040
// Test file system access
4141
var $folder : 4D:C1709.Folder
4242
$folder:=Folder:C1567(fk desktop folder:K87:19)
4343
$t.assert.isNotNull($t; $folder; "Should be able to access desktop folder")
44-
$t.assert.isTrue($t; $folder.exists; "Desktop folder should exist")
44+
$t.assert.isTrue($t; $folder.exists; "Desktop folder should exist")

0 commit comments

Comments
 (0)