-
Notifications
You must be signed in to change notification settings - Fork 10
Add command line options for glj -e --version --help -h #88
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
e0fd9ca
Support 'glj -e ...' commands
ingydotnet f2a4335
Add *glojure-version* dynamic variable
ingydotnet 8c17b4c
Support 'glj --version'
ingydotnet 8a1ff0f
Support --help and -h CLI options
ingydotnet d18fcaf
Fix 'make test', add 'make build', 'make clean'
ingydotnet 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
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,77 @@ | ||
| (ns glojure.test-glojure.cli | ||
| (:use glojure.test) | ||
| (:require [glojure.string :as str])) | ||
|
|
||
| (defmacro #^{:private true} test-that | ||
| "Provides a useful way for specifying the purpose of tests. If the first-level | ||
| forms are lists that make a call to a glojure.test function, it supplies the | ||
| purpose as the msg argument to those functions. Otherwise, the purpose just | ||
| acts like a comment and the forms are run unchanged." | ||
| [purpose & test-forms] | ||
| (let [tests (map | ||
| #(if (= (:ns (meta (resolve (first %)))) | ||
| (the-ns 'glojure.test)) | ||
| (concat % (list purpose)) | ||
| %) | ||
| test-forms)] | ||
| `(do ~@tests))) | ||
|
|
||
| (defn run-cli-cmd [& args] | ||
| (let [bytes-to-string (fn [bytes] | ||
| (if (nil? bytes) | ||
| "" | ||
| (apply str (map char (seq bytes))))) | ||
| cmd (apply os$exec.Command args) | ||
| [output err] (.CombinedOutput cmd)] | ||
| [(bytes-to-string output) (bytes-to-string err)])) | ||
|
|
||
| (def glj | ||
| (let [[out err] (run-cli-cmd "find" "bin" "-name" "glj" "-executable")] | ||
| (if (and (seq out) (empty? err)) | ||
| (first (str/split-lines out)) | ||
| (throw (Exception. (str "Failed to find glj bin: " err)))))) | ||
|
|
||
| (deftest e-flag-test | ||
| (test-that | ||
| "glj -e flag works correctly" | ||
| (let [[out err] (run-cli-cmd glj "-e" "(* 6 7)")] | ||
| (is (= out "42\n") "Command should output 42") | ||
| (is (empty? err) "Command should not return an error")))) | ||
|
|
||
| (deftest version-flag-test | ||
| (test-that | ||
| "glj --version flag works correctly" | ||
| (let [[out err] (run-cli-cmd glj "--version")] | ||
| (is (re-matches #"glojure v\d+\.\d+\.\d+\n" out) | ||
| "Command should output version") | ||
| (is (empty? err) "Command should not return an error")))) | ||
|
|
||
| (deftest glojure-version-test | ||
| (test-that | ||
| "*glojure-version* should be set correctly" | ||
| (let [[out err] (run-cli-cmd glj "-e" "*glojure-version*")] | ||
| (is (= out "{:major 0, :minor 3, :incremental 0, :qualifier nil}\n") | ||
| "Version should match expected format") | ||
| (is (empty? err) "Command should not return an error")))) | ||
|
|
||
| (deftest help-flag-test | ||
| (test-that | ||
| "glj --help flag works correctly" | ||
| (let [[out err] (run-cli-cmd glj "--help")] | ||
| (is (re-matches | ||
| #"(?s).*Glojure v0\.3\.0.*Usage: glj.*Options:.*-e.*-h.*--help.*--version.*Examples:.*" | ||
| out) | ||
| "Command should output help information") | ||
| (is (empty? err) "Command should not return an error")))) | ||
|
|
||
| (deftest short-help-flag-test | ||
| (test-that | ||
| "glj -h flag works correctly" | ||
| (let [[out err] (run-cli-cmd glj "-h")] | ||
| (is (re-matches | ||
| #"(?s).*Glojure v0\.3\.0.*Usage: glj.*Options:.*-e.*-h.*--help.*--version.*Examples:.*" | ||
| out) | ||
| "Command should output help information") | ||
| (is (empty? err) "Command should not return an error")))) | ||
|
|
||
| (run-tests) | ||
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.
nice!