Skip to content

Commit

Permalink
Make rust-skeptic doctests pass.
Browse files Browse the repository at this point in the history
They're REAL useful but I'm not actually sure they get
run as part of normal CI.  Fix this!
  • Loading branch information
icefoxen committed Jul 2, 2019
1 parent a87ce32 commit 0fb39f6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,23 @@ to common problems.

### Basic Project Template

```rust
use ggez::{Context, ContextBuilder, GameResult};
```rust,no_run
use ggez::{graphics, Context, ContextBuilder, GameResult};
use ggez::event::{self, EventHandler};
fn main() {
// Make a Context.
let ctx = &mut ContextBuilder::new("my_game", "Cool Game Author")
let (mut ctx, mut event_loop) = ContextBuilder::new("my_game", "Cool Game Author")
.build()
.expect("aieee, could not create ggez context!");
// Create an instance of your event handler.
// Usually, you should provide it with the Context object to
// use when setting your game up.
let mut my_game = MyGame::new(ctx);
let mut my_game = MyGame::new(&mut ctx);
// Run!
match event::run(ctx, &mut my_game) {
match event::run(&mut ctx, &mut event_loop, &mut my_game) {
Ok(_) => println!("Exited cleanly."),
Err(e) => println!("Error occured: {}", e)
}
Expand All @@ -137,13 +137,23 @@ struct MyGame {
// Your state here...
}
impl MyGame {
pub fn new(_ctx: &mut Context) -> MyGame {
// Load/create resources such as images here.
MyGame { }
}
}
impl EventHandler for MyGame {
fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
// Update code here...
Ok(())
}
fn draw(&mut self, _ctx: &mut Context) -> GameResult<()> {
fn draw(&mut self, ctx: &mut Context) -> GameResult<()> {
graphics::clear(ctx, graphics::WHITE);
// Draw code here...
graphics::present(ctx)
}
}
```
Expand Down
9 changes: 7 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
extern crate skeptic;
use skeptic;
use std::path::PathBuf;

fn main() {
// generates doc tests for guide.
// skeptic::generate_doc_tests(&[
// "docs/guides/HelloGgez.md",
// ]);

let mdbook_files = skeptic::markdown_files_of_directory("docs/guides/");
let mut mdbook_files = skeptic::markdown_files_of_directory("docs/guides/");
let other_files: Vec<PathBuf> = vec![
"README.md".into(),
];
mdbook_files.extend(other_files);
skeptic::generate_doc_tests(&mdbook_files);
}
2 changes: 1 addition & 1 deletion docs/guides/GenerativeArt.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::WHITE,
)?;
graphics::draw(ctx, &circle, graphics::DrawParam::default())?;
graphics::present(ctx)?
graphics::present(ctx)?;
Ok(())
}
```
Expand Down
2 changes: 1 addition & 1 deletion examples/transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl event::EventHandler for MainState {
fn draw(&mut self, ctx: &mut Context) -> GameResult {
graphics::clear(ctx, [0.1, 0.2, 0.3, 1.0].into());

let origin: na::Point2<f32> = na::origin();
let origin: na::Point2<f32> = na::Point2::origin();
graphics::draw(ctx, &self.gridmesh, (origin, graphics::WHITE))?;

let param = graphics::DrawParam::new()
Expand Down
14 changes: 8 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@
//! struct MyGame {
//! // Your state here...
//! }
//!
//! impl MyGame {
//! pub fn new(_ctx: &mut Context) -> MyGame {
//! // Load/create resources such as images here.
//! MyGame { }
//! }
//! }
//!
//! impl EventHandler for MyGame {
//! fn update(&mut self, _ctx: &mut Context) -> GameResult<()> {
Expand All @@ -70,12 +77,7 @@
//! graphics::present(ctx)
//! }
//! }
//! #
//! # impl MyGame {
//! # pub fn new(_ctx: &mut Context) -> MyGame {
//! # MyGame { }
//! # }
//! # }
//!
//! ```
#![deny(missing_docs)]
Expand Down

0 comments on commit 0fb39f6

Please sign in to comment.