Skip to content

Commit

Permalink
Improve library tests (#1332)
Browse files Browse the repository at this point in the history
  • Loading branch information
raviqqe authored Jul 13, 2024
1 parent 998f399 commit f7dec91
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
features: [gc_always]
tags: not @long
- name: chibi
tags: not @stak or @chibi
tags: (not @stak or @chibi) and not @library
- name: gauche
tags: not @stak or @gauche
- name: guile
Expand Down
2 changes: 1 addition & 1 deletion aa-tree.scm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
aa-tree->list
list->aa-tree)

(import (stak base))
(import (scheme base))

(begin
(define-record-type aa-tree
Expand Down
134 changes: 85 additions & 49 deletions features/library.feature
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@gauche @library @stak
@library
Feature: Library system
Scenario: Define a library
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo)
Expand All @@ -12,26 +12,31 @@ Feature: Library system
(define (foo x)
(write-u8 x))))
"""
When I successfully run `scheme main.scm`
And a file named "main.scm" with:
"""scheme
"""
When I successfully run `scheme -l foo.scm main.scm`
Then the exit status should be 0

Scenario: Import a library twice
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(import (scheme base) (scheme write))
(begin
(write-u8 65)))
"""
And a file named "main.scm" with:
"""scheme
(import (foo))
(import (foo))
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "A"

Scenario: Import a procedure
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo)
Expand All @@ -41,16 +46,18 @@ Feature: Library system
(begin
(define (foo x)
(write-u8 x))))
"""
And a file named "main.scm" with:
"""scheme
(import (foo))
(foo 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "A"

Scenario: Import a macro
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo)
Expand All @@ -62,16 +69,18 @@ Feature: Library system
(syntax-rules ()
((_ x)
(write-u8 x))))))
"""
And a file named "main.scm" with:
"""scheme
(import (foo))
(foo 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "A"

Scenario: Import procedures
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo bar)
Expand All @@ -84,17 +93,19 @@ Feature: Library system
(define (bar x)
(write-u8 (+ x 1)))))
"""
And a file named "main.scm" with:
"""scheme
(import (foo))
(foo 65)
(bar 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "AB"

Scenario: Import a procedure with a prefix
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo)
Expand All @@ -104,16 +115,18 @@ Feature: Library system
(begin
(define (foo x)
(write-u8 x))))
"""
And a file named "main.scm" with:
"""scheme
(import (prefix (foo) bar-))
(bar-foo 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "A"

Scenario: Import only a symbol
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo)
Expand All @@ -123,16 +136,18 @@ Feature: Library system
(begin
(define (foo x)
(write-u8 x))))
"""
And a file named "main.scm" with:
"""scheme
(import (only (foo) foo))
(foo 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "A"

Scenario: Import only a symbol and use one of the others
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo bar)
Expand All @@ -145,16 +160,18 @@ Feature: Library system
(define (bar)
#f)))
"""
And a file named "main.scm" with:
"""scheme
(import (only (foo) foo))
(bar)
"""
When I run `scheme main.scm`
When I run `scheme -l foo.scm main.scm`
Then the exit status should not be 0

Scenario: Import symbols except one
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo bar)
Expand All @@ -167,16 +184,18 @@ Feature: Library system
(define (bar x)
(write-u8 (+ x 1)))))
"""
And a file named "main.scm" with:
"""scheme
(import (except (foo) foo))
(bar 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "B"

Scenario: Import symbols except one and use it
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo bar)
Expand All @@ -189,16 +208,18 @@ Feature: Library system
(define (bar)
#f)))
"""
And a file named "main.scm" with:
"""scheme
(import (except (foo) foo))
(foo)
"""
When I run `scheme main.scm`
When I run `scheme -l foo.scm main.scm`
Then the exit status should not be 0

Scenario: Import a renamed procedure
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo)
Expand All @@ -208,16 +229,18 @@ Feature: Library system
(begin
(define (foo x)
(write-u8 x))))
"""
And a file named "main.scm" with:
"""scheme
(import (rename (foo) (foo bar)))
(bar 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "A"

Scenario Outline: Nest import qualifiers
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo bar)
Expand All @@ -230,12 +253,14 @@ Feature: Library system
(define (bar x)
(write-u8 (+ x 1)))))
"""
And a file named "main.scm" with:
"""scheme
(import <import set>)
(<symbol> 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "<output>"

Examples:
Expand All @@ -245,7 +270,7 @@ Feature: Library system
| (except (prefix (rename (foo) (bar baz)) my-) my-foo) | my-baz | B |

Scenario: Export an imported procedure
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo)
Expand All @@ -255,21 +280,26 @@ Feature: Library system
(begin
(define (foo x)
(write-u8 x))))
"""
And a file named "bar.scm" with:
"""scheme
(define-library (bar)
(export foo)
(import (foo)))
"""
And a file named "main.scm" with:
"""scheme
(import (bar))
(foo 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm -l bar.scm main.scm`
Then the stdout should contain exactly "A"

@chibi @gauche @stak
Scenario: Export a renamed procedure
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export (rename foo bar))
Expand All @@ -279,16 +309,18 @@ Feature: Library system
(begin
(define (foo x)
(write-u8 x))))
"""
And a file named "main.scm" with:
"""scheme
(import (foo))
(bar 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "A"

Scenario: Do not modify a library environment
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export bar)
Expand All @@ -301,7 +333,9 @@ Feature: Library system
(define (bar x)
(foo x))))
"""
And a file named "main.scm" with:
"""scheme
(import (scheme base) (scheme write) (foo))
(define (foo x)
Expand All @@ -310,11 +344,11 @@ Feature: Library system
(foo 65)
(bar 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
Then the stdout should contain exactly "BA"

Scenario: Modify a library environment
Given a file named "main.scm" with:
Given a file named "foo.scm" with:
"""scheme
(define-library (foo)
(export foo bar)
Expand All @@ -327,7 +361,9 @@ Feature: Library system
(define (bar x)
(foo x))))
"""
And a file named "main.scm" with:
"""scheme
(import (scheme base) (scheme write) (foo))
(foo 65)
Expand All @@ -338,6 +374,6 @@ Feature: Library system
(foo 65)
(bar 65)
"""
When I successfully run `scheme main.scm`
When I successfully run `scheme -l foo.scm main.scm`
# spell-checker: disable-next-line
Then the stdout should contain exactly "AABB"
Loading

0 comments on commit f7dec91

Please sign in to comment.