-
-
Notifications
You must be signed in to change notification settings - Fork 2
Bootstrap lean #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,22 @@ | ||
| FROM alpine:3.18 | ||
| FROM debian:bookworm-slim | ||
|
|
||
| # install packages required to run the tests | ||
| RUN apk add --no-cache jq coreutils | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| curl \ | ||
| ca-certificates \ | ||
| git \ | ||
| jq \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| ENV ELAN_HOME=/usr/local/elan | ||
| ENV PATH="${ELAN_HOME}/bin:${PATH}" | ||
|
|
||
| RUN curl -sSf https://raw.githubusercontent.com/leanprover/elan/master/elan-init.sh | sh -s -- -y --no-modify-path --default-toolchain leanprover/lean4:v4.25.2 \ | ||
| && elan default leanprover/lean4:v4.25.2 \ | ||
| && lean --version \ | ||
| && rm -rf ${ELAN_HOME}/downloads/* /tmp/* /var/tmp/* | ||
|
|
||
| WORKDIR /opt/test-runner | ||
| COPY . . | ||
|
|
||
| COPY bin/ bin/ | ||
|
|
||
| ENTRYPOINT ["/opt/test-runner/bin/run.sh"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace HelloWorld | ||
|
|
||
| def hello : String := | ||
| "Goodbye, World!" | ||
|
|
||
| end HelloWorld |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import LeanTest | ||
| import HelloWorld | ||
|
|
||
| open LeanTest | ||
|
|
||
| def helloWorldTests : TestSuite := | ||
| (TestSuite.empty "HelloWorld") | ||
| |>.addTest "Say Hi!" (do | ||
| return assertEqual "Hello, World!" HelloWorld.hello) | ||
|
|
||
| def main : IO UInt32 := do | ||
| runTestSuitesWithExitCode [helloWorldTests] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| { | ||
| "version": 1, | ||
| "status": "fail", | ||
| "message": "TODO: replace with correct output" | ||
| "status": "fail" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| {"version": "1.1.0", | ||
| "packagesDir": ".lake/packages", | ||
| "packages": [], | ||
| "name": "«hello-world»", | ||
| "lakeDir": ".lake"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| name = "hello-world" | ||
| version = "0.1.0" | ||
| defaultTargets = ["HelloWorldTest"] | ||
| testDriver = "HelloWorldTest" | ||
|
|
||
| [[lean_lib]] | ||
| name = "LeanTest" | ||
| srcDir = "vendor/LeanTest" | ||
|
|
||
| [[lean_lib]] | ||
| name = "HelloWorld" | ||
|
|
||
| [[lean_exe]] | ||
| name = "HelloWorldTest" | ||
| root = "HelloWorldTest" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| leanprover/lean4:v4.25.2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- This module serves as the root of the `LeanTest` library. | ||
| -- Import modules here that should be built as part of the library. | ||
| import LeanTest.Assertions | ||
| import LeanTest.Test | ||
| import LeanTest.Basic |
166 changes: 166 additions & 0 deletions
166
tests/all-fail/vendor/LeanTest/LeanTest/Assertions.lean
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| /- | ||
| Assertion functions for unit testing. | ||
| -/ | ||
|
|
||
| namespace LeanTest | ||
|
|
||
| /-- Result of a test assertion -/ | ||
| inductive AssertionResult where | ||
| | success : AssertionResult | ||
| | failure (message : String) : AssertionResult | ||
| deriving Repr, BEq | ||
|
|
||
| namespace AssertionResult | ||
|
|
||
| def isSuccess : AssertionResult → Bool | ||
| | success => true | ||
| | failure _ => false | ||
|
|
||
| def getMessage : AssertionResult → String | ||
| | success => "Assertion passed" | ||
| | failure msg => msg | ||
|
|
||
| end AssertionResult | ||
|
|
||
| /-- Assert that a boolean condition is true -/ | ||
| def assert (condition : Bool) (message : String := "Assertion failed") : AssertionResult := | ||
| if condition then | ||
| .success | ||
| else | ||
| .failure message | ||
|
|
||
| /-- Assert that two values are equal -/ | ||
| def assertEqual [BEq α] [Repr α] (expected : α) (actual : α) (message : String := "") : AssertionResult := | ||
| if expected == actual then | ||
| .success | ||
| else | ||
| let msg := if message.isEmpty then | ||
| s!"Expected: {repr expected}\nActual: {repr actual}" | ||
| else | ||
| s!"{message}\nExpected: {repr expected}\nActual: {repr actual}" | ||
| .failure msg | ||
|
|
||
| /-- Assert that two values are not equal -/ | ||
| def assertNotEqual [BEq α] [Repr α] (expected : α) (actual : α) (message : String := "") : AssertionResult := | ||
| if expected != actual then | ||
| .success | ||
| else | ||
| let msg := if message.isEmpty then | ||
| s!"Expected values to be different, but both were: {repr expected}" | ||
| else | ||
| s!"{message}\nExpected values to be different, but both were: {repr expected}" | ||
| .failure msg | ||
|
|
||
| /-- Refute that a boolean condition is true (assert it's false) -/ | ||
| def refute (condition : Bool) (message : String := "Refute failed - condition was true") : AssertionResult := | ||
| if !condition then | ||
| .success | ||
| else | ||
| .failure message | ||
|
|
||
| /-- Assert that a value is true -/ | ||
| def assertTrue (value : Bool) (message : String := "Expected true but got false") : AssertionResult := | ||
| assert value message | ||
|
|
||
| /-- Assert that a value is false -/ | ||
| def assertFalse (value : Bool) (message : String := "Expected false but got true") : AssertionResult := | ||
| refute value message | ||
|
|
||
| /-- Assert that an Option is some -/ | ||
| def assertSome [Repr α] (opt : Option α) (message : String := "Expected Some but got None") : AssertionResult := | ||
| match opt with | ||
| | some _ => .success | ||
| | none => .failure message | ||
|
|
||
| /-- Assert that an Option is none -/ | ||
| def assertNone [Repr α] (opt : Option α) (message : String := "") : AssertionResult := | ||
| match opt with | ||
| | none => .success | ||
| | some val => | ||
| let msg := if message.isEmpty then | ||
| s!"Expected None but got Some: {repr val}" | ||
| else | ||
| s!"{message}\nExpected None but got Some: {repr val}" | ||
| .failure msg | ||
|
|
||
| /-- Assert that a list is empty -/ | ||
| def assertEmpty [Repr α] (list : List α) (message : String := "") : AssertionResult := | ||
| match list with | ||
| | [] => .success | ||
| | _ => | ||
| let msg := if message.isEmpty then | ||
| s!"Expected empty list but got: {repr list}" | ||
| else | ||
| s!"{message}\nExpected empty list but got: {repr list}" | ||
| .failure msg | ||
|
|
||
| /-- Assert that a list contains an element -/ | ||
| def assertContains [BEq α] [Repr α] (list : List α) (element : α) (message : String := "") : AssertionResult := | ||
| if list.contains element then | ||
| .success | ||
| else | ||
| let msg := if message.isEmpty then | ||
| s!"Expected list to contain {repr element}\nList: {repr list}" | ||
| else | ||
| s!"{message}\nExpected list to contain {repr element}\nList: {repr list}" | ||
| .failure msg | ||
|
|
||
| /-- Assert that a value is within a range (inclusive) -/ | ||
| def assertInRange [LE α] [DecidableRel (· ≤ · : α → α → Prop)] [Repr α] | ||
| (value : α) (min : α) (max : α) (message : String := "") : AssertionResult := | ||
| if min ≤ value ∧ value ≤ max then | ||
| .success | ||
| else | ||
| let msg := if message.isEmpty then | ||
| s!"Expected {repr value} to be in range [{repr min}, {repr max}]" | ||
| else | ||
| s!"{message}\nExpected {repr value} to be in range [{repr min}, {repr max}]" | ||
| .failure msg | ||
|
|
||
| /-- Assert that an Except value is an error -/ | ||
| def assertError [Repr ε] [Repr α] (result : Except ε α) (message : String := "") : AssertionResult := | ||
| match result with | ||
| | .error _ => .success | ||
| | .ok val => | ||
| let msg := if message.isEmpty then | ||
| s!"Expected error but got Ok: {repr val}" | ||
| else | ||
| s!"{message}\nExpected error but got Ok: {repr val}" | ||
| .failure msg | ||
|
|
||
| /-- Assert that an Except value is ok -/ | ||
| def assertOk [Repr ε] [Repr α] (result : Except ε α) (message : String := "") : AssertionResult := | ||
| match result with | ||
| | .ok _ => .success | ||
| | .error err => | ||
| let msg := if message.isEmpty then | ||
| s!"Expected Ok but got error: {repr err}" | ||
| else | ||
| s!"{message}\nExpected Ok but got error: {repr err}" | ||
| .failure msg | ||
|
|
||
| /-- Assert that an IO action throws an error -/ | ||
| def assertThrows (action : IO α) (message : String := "") : IO AssertionResult := do | ||
| try | ||
| let _ ← action | ||
| let msg := if message.isEmpty then | ||
| "Expected IO action to throw an error, but it succeeded" | ||
| else | ||
| s!"{message}\nExpected IO action to throw an error, but it succeeded" | ||
| return .failure msg | ||
| catch _ => | ||
| return .success | ||
|
|
||
| /-- Assert that an IO action succeeds (doesn't throw) -/ | ||
| def assertSucceeds (action : IO α) (message : String := "") : IO AssertionResult := do | ||
| try | ||
| let _ ← action | ||
| return .success | ||
| catch e => | ||
| let msg := if message.isEmpty then | ||
| s!"Expected IO action to succeed, but it threw: {e}" | ||
| else | ||
| s!"{message}\nExpected IO action to succeed, but it threw: {e}" | ||
| return .failure msg | ||
|
|
||
| end LeanTest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| def hello := "world" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be exec?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe so:
Lean compiles to C, then to native code - this toolchain may write intermediate executables to temp locations
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I think it will be fine