-
Notifications
You must be signed in to change notification settings - Fork 18
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
Extend check-location to also compare basenames #3
Open
jkoser
wants to merge
2
commits into
mwand:master
Choose a base branch
from
jkoser:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 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 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 |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
rackunit/log) | ||
(provide begin-for-test) | ||
(provide provide rename-out struct-out check-error) | ||
(provide check-location) | ||
(provide check-location check-location-actual) | ||
(provide check-within) | ||
|
||
(define extras-version "Wed Sep 14 08:52:19 2016") | ||
|
@@ -90,39 +90,66 @@ | |
|
||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | ||
|
||
;; check-location : String String -> Void | ||
;; GIVEN: a 2 digit problem set number NN and the name of the file | ||
;; being qualified. | ||
;; EFFECT: throws an error if this file is not a directory of the form | ||
;; pdp-*./setNN | ||
(define (check-location NN correct-file-name) | ||
(define path-elements (explode-path (current-directory))) | ||
;; (check-location NN correct-file-name) : module-level form | ||
(define-syntax (check-location stx) | ||
(syntax-case stx () | ||
[(_ NN correct-file-name) | ||
(case (syntax-local-context) | ||
[(module) | ||
#`(check-location-actual (#%expression NN) | ||
(#%expression correct-file-name) | ||
(quote #,(syntax-source stx))) | ||
] | ||
[(top-level) | ||
(raise-syntax-error #f | ||
"`check-location' may only be used inside a module" | ||
stx)] | ||
[else | ||
(raise-syntax-error #f | ||
"found a use of `check-location' that is not at the top level" | ||
stx)])])) | ||
|
||
;; check-location-actual : String String Path -> Void | ||
;; GIVEN: a 2 digit problem set number NN, the expected name of the file | ||
;; being qualified, and the actual path to the file | ||
;; EFFECT: throws an error if this file is not in a directory of the form | ||
;; pdp-*./setNN or does not have the correct name. | ||
(define (check-location-actual NN correct-file-name actual-file-path) | ||
(define path-elements (explode-path actual-file-path)) | ||
(define path-len (length path-elements)) | ||
(define correct-folder-name (string-append "set" NN)) | ||
(cond | ||
[(>= path-len 2) | ||
(define set-folder (path->string (last path-elements))) | ||
(define pdp-folder (path->string (list-ref path-elements (- path-len 2)))) | ||
[(>= path-len 3) | ||
(define actual-file-name (path->string (last path-elements))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider |
||
(define set-folder (path->string (list-ref path-elements (- path-len 2)))) | ||
(define pdp-folder (path->string (list-ref path-elements (- path-len 3)))) | ||
(define set-regexp (regexp correct-folder-name)) | ||
(define pdp-regexp (regexp "pdp-.*")) | ||
(match* ((regexp-match? set-regexp set-folder) | ||
(match* ((string=? actual-file-name correct-file-name) | ||
(regexp-match? set-regexp set-folder) | ||
(regexp-match? pdp-regexp pdp-folder)) | ||
[(_ #f) | ||
[(_ _ #f) | ||
(error | ||
(format | ||
"File is in folder \"~a/~a\", which does not appear to be a local repo" | ||
pdp-folder set-folder))] | ||
[(#f _) | ||
[(_ #f _) | ||
(error | ||
(format | ||
"File should be in a folder named ~a, but is in a folder named ~a" | ||
correct-folder-name | ||
set-folder))] | ||
[(#t #t) | ||
[(#f _ _) | ||
(error | ||
(format | ||
"File should be named ~a, but is named ~a" | ||
correct-file-name | ||
actual-file-name))] | ||
[(#t #t #t) | ||
(printf | ||
"~a appears to be in a correctly named folder. Running tests...~n" | ||
correct-file-name)] | ||
[(_ _) (void)])] | ||
[(_ _ _) (void)])] | ||
[else | ||
(error | ||
(format | ||
|
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.
Might want to say something more like "in an unexpected location"
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.
While it is true, that message would not offer any guidance on how to fix the problem.