Skip to content

Commit

Permalink
chore: add plugin test
Browse files Browse the repository at this point in the history
  • Loading branch information
tydeu committed Nov 20, 2024
1 parent 8f74f0e commit 1cc0f53
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/pkg/user_plugin/UserPlugin.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
builtin_initialize IO.println "Ran builtin initializer"
2 changes: 2 additions & 0 deletions tests/pkg/user_plugin/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
rm -rf .lake/build
rm -f lake-manifest.json
6 changes: 6 additions & 0 deletions tests/pkg/user_plugin/lakefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "user_plugin"
defaultTargets = ["UserPlugin"]

[[lean_lib]]
name = "UserPlugin"
defaultFacets = ["shared"]
8 changes: 8 additions & 0 deletions tests/pkg/user_plugin/test.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Lean.LoadDynlib

def main (args : List String) : IO UInt32 := do
let plugin :: [] := args
| IO.println "Usage: lean --run test.lean <plugin>"
return 1
Lean.loadPlugin plugin
return 0
42 changes: 42 additions & 0 deletions tests/pkg/user_plugin/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env bash
set -euo pipefail

# Deermine shared library extension
if [ "${OS:-}" = Windows_NT ]; then
LIB_PREFIX=
SHLIB_EXT=dll
elif [ "`uname`" = Darwin ]; then
LIB_PREFIX=lib
SHLIB_EXT=dylib
else
LIB_PREFIX=lib
SHLIB_EXT=so
fi

# Reset test
./clean.sh
lake update -q

# Build plugin
lake build
LIB_DIR=.lake/build/lib
SHLIB=$LIB_DIR/${LIB_PREFIX}UserPlugin.$SHLIB_EXT
test -f $SHLIB || {
echo "Plugin library not found; $LIB_DIR contains:"
ls $LIB_DIR
exit 1
}
PLUGIN=$LIB_DIR/UserPlugin.$SHLIB_EXT
mv $SHLIB $PLUGIN

# Expected test output
EXPECTED_OUT="Ran builtin initializer"

# Test plugin via `lean`
echo | lean --plugin=$PLUGIN --stdin | diff <(echo "$EXPECTED_OUT") -

# Test plugin via `Lean.loadPlugin`
lean --run test.lean $PLUGIN | diff <(echo "$EXPECTED_OUT") -

# Print success
echo "Tests completed successfully."

0 comments on commit 1cc0f53

Please sign in to comment.