Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: CI

on:
push:
branches: [master]
tags: ['v*']
pull_request:
workflow_dispatch:

jobs:
unit-tests:
name: Host unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: make test
run: make test

lint:
name: arduino-lint (Library Manager rules)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: arduino/arduino-lint-action@v3
with:
# `submit` = the rules for a library not yet in the Library Manager
# index. `update` asserts the library is ALREADY indexed and fails with
# LP018 ("name not found in the index") if it isn't — NewPingPlus has
# not been submitted yet.
#
# Switch this to `update` once the registry PR is merged and the
# library appears in the index; `update` then enforces the rules that
# apply to released versions (notably that the name can never change).
library-manager: submit
compliance: strict

compile:
name: Compile ${{ matrix.board.name }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# `platforms` is the whole YAML block, not name+url assembled in the step.
# arduino:avr ships with arduino-cli and takes no source-url; rendering an
# empty one emits `source-url:` as null, and the action dereferences it
# unconditionally (AttributeError: 'NoneType' object has no attribute
# 'rstrip'). Omitting the key entirely is the only way to express that.
board:
- name: Arduino Uno
fqbn: arduino:avr:uno
platforms: |
- name: arduino:avr
- name: ESP8266 NodeMCU
fqbn: esp8266:esp8266:nodemcuv2
platforms: |
- name: esp8266:esp8266
source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
- name: ESP32 Dev Module
fqbn: esp32:esp32:esp32
platforms: |
- name: esp32:esp32
source-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
- name: Teensy 3.2
fqbn: teensy:avr:teensy31
platforms: |
- name: teensy:avr
source-url: https://www.pjrc.com/teensy/package_teensy_index.json
# Teensy 4.x uses 32-bit port registers and must stay on the
# digitalWrite path — these entries catch a regression there.
- name: Teensy 4.0
fqbn: teensy:avr:teensy40
platforms: |
- name: teensy:avr
source-url: https://www.pjrc.com/teensy/package_teensy_index.json
- name: Teensy 4.1
fqbn: teensy:avr:teensy41
platforms: |
- name: teensy:avr
source-url: https://www.pjrc.com/teensy/package_teensy_index.json
steps:
- uses: actions/checkout@v5
- uses: arduino/compile-sketches@v1
with:
fqbn: ${{ matrix.board.fqbn }}
platforms: ${{ matrix.board.platforms }}
libraries: |
- source-path: ./
# The async example is guarded with #error off ESP, so only compile it there.
sketch-paths: |
- examples/NewPingPlusExample
enable-warnings-report: true

compile-async:
name: Compile async example (${{ matrix.board.name }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
board:
- name: ESP8266 NodeMCU
fqbn: esp8266:esp8266:nodemcuv2
platforms: |
- name: esp8266:esp8266
source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
- name: ESP32 Dev Module
fqbn: esp32:esp32:esp32
platforms: |
- name: esp32:esp32
source-url: https://espressif.github.io/arduino-esp32/package_esp32_index.json
steps:
- uses: actions/checkout@v5
- uses: arduino/compile-sketches@v1
with:
fqbn: ${{ matrix.board.fqbn }}
platforms: ${{ matrix.board.platforms }}
libraries: |
- source-path: ./
sketch-paths: |
- examples/NewPingAsyncExample
enable-warnings-report: true
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Compiled host test binaries (built by `make test`)
test/run_tests*

# macOS
.DS_Store

# Claude Code local working files
.claude/
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# NewPingPlus — native unit tests
#
# Usage:
# make test compile and run all tests
# make clean remove compiled binary
#
# Requirements: a C++14-capable compiler (g++ or clang++) on macOS or Linux.
# No Arduino IDE, ESP toolchain, or hardware required.
#
# The test build defines ARDUINO=100 (so NewPingPlus.h takes the <Arduino.h>
# branch) and provides a mock Arduino.h under test/mock/. None of
# ESP8266/ESP32/__AVR__/__arm__ are defined, so the library compiles with
# DO_BITWISE=false and PING_OVERHEAD=1 — the same code path as all ESP targets.

CXX ?= g++
CXXFLAGS = -std=c++14 -Wall -Wextra \
-I. -Itest/mock \
-DARDUINO=100

SRCS = NewPingPlus.cpp \
test/mock_arduino.cpp \
test/test_main.cpp

BIN = test/run_tests

.PHONY: test clean

# NOTE: these tests assert the default configuration (ROUNDING_ENABLED=false,
# URM37_ENABLED=false). They compile but do not pass with ROUNDING_ENABLED=true,
# because the expected values are hardcoded for truncation.
test: $(BIN)
@echo ""
./$(BIN)

$(BIN): $(SRCS) NewPingPlus.h test/mock/Arduino.h test/mock_arduino.h
$(CXX) $(CXXFLAGS) -o $@ $(SRCS)

clean:
rm -f $(BIN)
214 changes: 0 additions & 214 deletions NewPingESP8266.cpp

This file was deleted.

Loading