Skip to content

Commit 3184f8a

Browse files
authored
Test ignored-result-values with DSL (#553)
Also, improve the check failure messages a bit with more info and logs.
1 parent c56f86e commit 3184f8a

File tree

4 files changed

+113
-32
lines changed

4 files changed

+113
-32
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#lang resyntax/test
2+
require: resyntax/default-recommendations default-recommendations
3+
header: - #lang racket/base
4+
5+
6+
analysis-test: "non-terminal function bodies are ignored"
7+
--------------------
8+
(define (f)
9+
(displayln "hi")
10+
(void))
11+
--------------------
12+
@inspect - (displayln "hi")
13+
@property expression-result
14+
@assert ignored
15+
16+
17+
analysis-test: "terminal function bodies are used"
18+
--------------------
19+
(define (f)
20+
(displayln "hi")
21+
(void))
22+
--------------------
23+
@inspect - (void)
24+
@property expression-result
25+
@assert used
26+
27+
28+
analysis-test: "function arguments are used"
29+
- (list (void))
30+
@inspect - (void)
31+
@property expression-result
32+
@assert used
33+
34+
35+
analysis-test: "applied functions are used"
36+
- (list (void))
37+
@inspect - list
38+
@property expression-result
39+
@assert used
40+
41+
42+
analysis-test: "variable definitions use their right hand side"
43+
- (define a (void))
44+
@inspect - (void)
45+
@property expression-result
46+
@assert used
47+
48+
49+
analysis-test: "syntax definitions use their right hand side"
50+
--------------------
51+
(require (for-syntax racket/base))
52+
(define-syntax a (void))
53+
--------------------
54+
@inspect - (void)
55+
@property expression-result
56+
@assert used
57+
58+
59+
analysis-test: "begin0 forms use their initial expression"
60+
--------------------
61+
(begin0 (void)
62+
(displayln "after"))
63+
--------------------
64+
@inspect - (void)
65+
@property expression-result
66+
@assert used
67+
68+
69+
analysis-test: "begin0 forms ignore their trailing body"
70+
--------------------
71+
(begin0 (void)
72+
(displayln "after"))
73+
--------------------
74+
@inspect - (displayln "after")
75+
@property expression-result
76+
@assert ignored
77+
78+
79+
analysis-test: "let expressions ignore their non-terminal body forms"
80+
--------------------
81+
(let ()
82+
(displayln "hi")
83+
(void))
84+
--------------------
85+
@inspect - (displayln "hi")
86+
@property expression-result
87+
@assert ignored
88+
89+
90+
analysis-test: "let expressions use their terminal body form"
91+
--------------------
92+
(let ()
93+
(displayln "hi")
94+
(void))
95+
--------------------
96+
@inspect - (void)
97+
@property expression-result
98+
@assert used

default-recommendations/analyzers/ignored-result-values.rkt

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -96,34 +96,3 @@
9696

9797
(define (stream-append-all streams)
9898
(apply stream-append streams))
99-
100-
101-
(module+ test
102-
(test-case "ignored-result-values-analyzer"
103-
(define test-stx
104-
#'(define (f x)
105-
(displayln "hi")
106-
x))
107-
(define expanded (expand test-stx))
108-
(define lambda-path (syntax-path (list 2)))
109-
(define displayln-path (syntax-path (list 2 2)))
110-
(define displayln-id-path (syntax-path (list 2 2 (tail-syntax 1) 0)))
111-
(define hi-path (syntax-path (list 2 2 (tail-syntax 1) 1)))
112-
(define x-path (syntax-path (list 2 3)))
113-
(check-equal? (syntax->datum (syntax-ref expanded lambda-path))
114-
'(lambda (x) (#%app displayln '"hi") x))
115-
(check-equal? (syntax->datum (syntax-ref expanded displayln-path)) '(#%app displayln '"hi"))
116-
(check-equal? (syntax->datum (syntax-ref expanded displayln-id-path)) 'displayln)
117-
(check-equal? (syntax->datum (syntax-ref expanded hi-path)) ''"hi")
118-
(check-equal? (syntax->datum (syntax-ref expanded x-path)) 'x)
119-
120-
(define actual (expansion-analyze ignored-result-values-analyzer expanded))
121-
122-
(define expected
123-
(syntax-property-bundle
124-
(syntax-property-entry lambda-path 'expression-result 'used)
125-
(syntax-property-entry displayln-path 'expression-result 'ignored)
126-
(syntax-property-entry displayln-id-path 'expression-result 'used)
127-
(syntax-property-entry hi-path 'expression-result 'used)
128-
(syntax-property-entry x-path 'expression-result 'used)))
129-
(check-equal? actual expected)))

private/source.rkt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,19 @@
237237

238238
(define property-selection-table
239239
(transduce movement-table
240-
(filtering-values (λ (exp-paths) (equal? (sorted-set-size exp-paths) 1)))
240+
(filtering
241+
(λ (e)
242+
(match-define (entry orig-path exp-paths) e)
243+
(match (sorted-set-size exp-paths)
244+
[1 #true]
245+
[0 #false]
246+
[_
247+
(log-resyntax-debug
248+
(string-append
249+
"ignoring expansion analyzer properties for original path ~a because"
250+
" multiple expanded forms claim to originate from that path")
251+
orig-path)
252+
#false])))
241253
(mapping-values (λ (exp-paths) (present-value (sorted-set-least-element exp-paths))))
242254
#:into (into-sorted-map syntax-path<=>)))
243255

test/private/rackunit.rkt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@
246246
(with-check-info (['logs (build-logs-info)]
247247
['program (string-block-info (string-source-contents program-src))]
248248
['target (string-block-info (string-source-contents target-src))]
249+
['target-path target-path]
249250
['target-properties target-properties]
250251
['property-key property-key])
251252
(fail-check "analysis did not assign a value for the given syntax property key")))
@@ -257,6 +258,7 @@
257258
(with-check-info (['logs (build-logs-info)]
258259
['program (string-block-info (string-source-contents program-src))]
259260
['target (string-block-info (string-source-contents target-src))]
261+
['target-path target-path]
260262
['property-key property-key]
261263
['actual actual-value]
262264
['expected expected-value])

0 commit comments

Comments
 (0)