Skip to content

Run clj file as script & evaluate expression #45

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 4 commits into from
May 16, 2020

Conversation

zackteo
Copy link
Contributor

@zackteo zackteo commented May 15, 2020

Hardcoding based on arguments.len() == 3 for now

Examples:
--init/-i for script or --eval/-e for evaluate expression
cargo run -- --init examples/hello_world.clj
cargo run -- --eval "(println \"eh\")"
cargo run -- --eval "(+ 1 2)"

@erkkikeranen
Copy link
Member

Nice work!

}
}

pub fn parse_args() -> Action{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change this fn so that it takes the Vec env variables as input

src/main.rs Outdated
//
// Start repl
//
let cli_args: user_action::Action = user_action::parse_args();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to user_action::parse_args( env::args().collect() );


pub fn parse_args() -> Action{

let arguments: Vec<String> = env::args().collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now this can be removed,

So you can write trivial unit tests for the cases (Runscript, Evaluate and Nothing) to check that parse_args return correct enum

Copy link
Contributor Author

@zackteo zackteo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made changes in d848959

use crate::user_action;

#[test]
fn parse_args_test() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could group these test under a

mod parse_args_tests, and under that mod have one test per assertion, ie.

fn parses_args_given_path just asserts what it describes

you can see examples in other files, this makes nice and organized and descriptive test output and it’s also easy to run certain tests

zackteo and others added 4 commits May 16, 2020 05:43
Hardcoding based on arguments.len() == 3 for now

Examples:
--init/-i for script or --eval/-e for evaluate expression
cargo run -- --init examples/hello_world.clj
cargo run -- --eval "(println \"eh\")"
cargo run -- --eval "(+ 1 2)"
Changing output of
cargo run -- --eval "(+ 1 2)"
from I32(3) to 3
@Tko1 Tko1 force-pushed the feature/run-clj-file-as-script branch from ee6b46c to ee27d1a Compare May 16, 2020 10:21
@Tko1 Tko1 linked an issue May 16, 2020 that may be closed by this pull request
@Tko1 Tko1 merged commit 6fc04e0 into clojure-rs:master May 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle Results being returned in try_eval_file in Zach's PR
3 participants