Skip to content

Commit

Permalink
imp(clap-test): simplified make test invocation
Browse files Browse the repository at this point in the history
* assure `make test` works on OSX as well
* simplified entire makefile, by basically removing sed invocations to
  manipulate the Cargo.toml file under source control.
* *works for me* predicate

This should probably be tested on another system as well, just to be
sure it makes sense for everyone.
  • Loading branch information
Byron authored and kbknapp committed May 5, 2015
1 parent b249f96 commit d17dcb2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 31 deletions.
3 changes: 1 addition & 2 deletions clap-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ version = "0.0.1"
authors = ["Kevin K. <kbknapp@gmail.com>"]

[dependencies.clap]
git = "https://github.com/kbknapp/clap-rs"
branch = "master"
path = ".."
28 changes: 6 additions & 22 deletions clap-tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)
URL:=
BRANCH:=
.PHONY: build test clean

build:
cargo update
# It may be that this project was never built, and no Cargo.lock exists.
# Thus it may be ignored
cargo update 2>/dev/null || :
cargo build --release

test:
cd "$(THIS_DIR)"
cp Cargo.toml cargo.bak
@read -p "Fork URL: " URL; \
sed "/^git/c\git = \"$$URL\"" cargo.bak > Cargo.toml
@read -p "Branch [master]: " BRANCH; \
$(if $(strip $(BRANCH)), \
sed -i "/^branch/c\branch = \"master\"" Cargo.toml, \
sed -i "/^branch/c\branch = \"$$BRANCH\"" Cargo.toml)
(make clean) || (make clean && false)
cd "$(THIS_DIR)"
(make build) || (make clean && false)
cd "$(THIS_DIR)"
(./run_tests.py) || (make clean && false)
mv cargo.bak Cargo.toml
make clean

$(MAKE) build || ($(MAKE) clean && false)
./run_tests.py

clean:
cd "$(THIS_DIR)"
cargo clean
2 changes: 1 addition & 1 deletion clap-tests/run_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import sys
import subprocess

Expand Down
18 changes: 12 additions & 6 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,15 @@ macro_rules! arg_enum {
type Err = String;

fn from_str(s: &str) -> Result<Self,Self::Err> {
use ::std::ascii::AsciiExt;
match s {
$(stringify!($v) => Ok($e::$v),)+
$(stringify!($v) |
_ if s.eq_ignore_ascii_case(stringify!($v)) => Ok($e::$v),)+
_ => Err({
let v = vec![
$(stringify!($v),)+
];
format!("valid:{}",
format!("valid values:{}",
v.iter().fold(String::new(), |a, i| {
a + &format!(" {}", i)[..]
}))
Expand All @@ -422,13 +424,15 @@ macro_rules! arg_enum {
type Err = String;

fn from_str(s: &str) -> Result<Self,Self::Err> {
use ::std::ascii::AsciiExt;
match s {
$(stringify!($v) => Ok($e::$v),)+
$(stringify!($v) |
_ if s.eq_ignore_ascii_case(stringify!($v)) => Ok($e::$v),)+
_ => Err({
let v = vec![
$(stringify!($v),)+
];
format!("valid:{}",
format!("valid values:{}",
v.iter().fold(String::new(), |a, i| {
a + &format!(" {}", i)[..]
}))
Expand All @@ -447,13 +451,15 @@ macro_rules! arg_enum {
type Err = String;

fn from_str(s: &str) -> Result<Self,Self::Err> {
use ::std::ascii::AsciiExt;
match s {
$(stringify!($v) => Ok($e::$v),)+
$(stringify!($v) |
_ if s.eq_ignore_ascii_case(stringify!($v)) => Ok($e::$v),)+
_ => Err({
let v = vec![
$(stringify!($v),)+
];
format!("valid:{}",
format!("valid values:{}",
v.iter().fold(String::new(), |a, i| {
a + &format!(" {}", i)[..]
}))
Expand Down

0 comments on commit d17dcb2

Please sign in to comment.