Skip to content

travis: Enforce that stubs compile, supporting commit (add unimplemented) #372

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 2 commits into from
Oct 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ language: rust
script:
- "./_test/check-exercises.sh"
- "sh ./_test/ensure-lib-src-rs-exist.sh"
- "sh ./_test/ensure-stubs-compile.sh"
- "sh ./_test/count-ignores.sh"
- "./bin/fetch-configlet"
- "./bin/configlet lint ."
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ Note that:

- The stub file and test suite should use only the Rust core libraries. `Cargo.toml` should not list any external dependencies as we don't want to make the student assume required crates. If an `example.rs` uses external crates, include `Cargo-example.toml` so that `_tests/check-exercises.sh` can compile with these when testing.

- Except in extraordinary circumstances, the stub file should compile under `cargo test --no-run`.
This allows us to check that the signatures in the stub file match the signatures expected by the tests.
Use `unimplemented!()` as the body of each function to achieve this.
If there is a justified reason why this is not possible, instead include a `.meta/ALLOWED_TO_NOT_COMPILE` containing the reason.

- If porting an existing exercise from problem-specifications that has a `canonical-data.json` file, use the version in `canonical-data.json` for that exercise as your `Cargo.toml` version. Otherwise, use "0.0.0".

- An exercise may contain `.meta/hints.md`. This is optional and will appear after the normal exercise
Expand Down
26 changes: 26 additions & 0 deletions _test/ensure-stubs-compile.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh

repo=$(cd "$(dirname "$0")/.." && pwd)

broken=""

for dir in $repo/exercises/*/; do
exercise=$(basename "$dir")

# If src/lib.rs contains any non-comment line that contains any non-spaces,
# it probably contains function signatures, and these should compile.
if grep -v '^//' $dir/src/lib.rs | grep '\S' > /dev/null; then
allowed_file=$dir/.meta/ALLOWED_TO_NOT_COMPILE
if [ -f $allowed_file ]; then
echo "$exercise's stub is allowed to not compile"
elif ! (cd $dir && cargo test --quiet --no-run); then
echo "$exercise's stub does not compile; please make it compile or remove all non-commented lines"
broken="$broken\n$exercise"
fi
fi
done

if [ -n "$broken" ]; then
echo "Exercises that don't compile:$broken"
exit 1
fi
4 changes: 2 additions & 2 deletions exercises/beer-song/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub fn verse(n: i32) -> String {

unimplemented!()
}

pub fn sing(start: i32, end: i32) -> String {

unimplemented!()
}
2 changes: 1 addition & 1 deletion exercises/bob/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn reply(message: &str) -> &str {

unimplemented!()
}
2 changes: 1 addition & 1 deletion exercises/collatz-conjecture/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// return Ok(x) where x is the number of steps required to reach 1
pub fn collatz(n: u64) -> Result<u64, &'static str> {

unimplemented!()
}
2 changes: 2 additions & 0 deletions exercises/decimal/.meta/ALLOWED_TO_NOT_COMPILE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Stub doesn't compile because operations like +, - are not found.
However, giving stubs to the traits would reduce the student's learning.
6 changes: 3 additions & 3 deletions exercises/difference-of-squares/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pub fn square_of_sum(n: usize) -> usize {

unimplemented!()
}

pub fn sum_of_squares(n: usize) -> usize {

unimplemented!()
}

pub fn difference(n: usize) -> usize {

unimplemented!()
}
3 changes: 3 additions & 0 deletions exercises/forth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ pub enum Error {

impl Forth {
pub fn new() -> Forth {
unimplemented!()
}

pub fn stack(&self) -> Vec<Value> {
unimplemented!()
}

pub fn eval(&mut self, input: &str) -> ForthResult {
unimplemented!()
}
}
2 changes: 1 addition & 1 deletion exercises/leap/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn is_leap_year(year: i32) -> bool {

unimplemented!()
}
2 changes: 1 addition & 1 deletion exercises/proverb/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn build_proverb(list: Vec<&str>) -> String {

unimplemented!()
}
2 changes: 1 addition & 1 deletion exercises/raindrops/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn raindrops(n: usize) -> String {

unimplemented!()
}
2 changes: 1 addition & 1 deletion exercises/sum-of-multiples/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub fn sum_of_multiples(limit: u32, factors: &[u32]) -> u32 {

unimplemented!()
}