aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelody Horn <melody@boringcactus.com>2021-06-28 17:02:45 -0600
committerMelody Horn <melody@boringcactus.com>2021-06-28 17:02:45 -0600
commit2e3930b4c7c26e91c1341d7d04d33d91758f8009 (patch)
treeeabac3a8e760e2dc91a548b337f5f2ffe51a6285
parent8852f0b7090c612f1d04a60becb55bbe56441eda (diff)
downloadtosin-2e3930b4c7c26e91c1341d7d04d33d91758f8009.tar.gz
tosin-2e3930b4c7c26e91c1341d7d04d33d91758f8009.zip
work properly on windows too
-rw-r--r--Cargo.toml2
-rw-r--r--src/bin/tosin-admin.rs16
-rw-r--r--tests/tutorial/mod.rs86
3 files changed, 74 insertions, 30 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 6b9d7fb..14f00f0 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -11,6 +11,8 @@ barrel = { version = "0.6.5", features = ["sqlite3"] }
chrono = "0.4"
diesel = { version = "1.4.4", features = ["sqlite", "chrono"] }
hyper = { version = "0.14", features = ["full"] }
+# TODO not this
+libsqlite3-sys = { version = "0.22.2", features = ["bundled-windows"] }
quote = "1.0"
structopt = "0.3.21"
syn = { version = "1.0", features = ["full", "extra-traits"] }
diff --git a/src/bin/tosin-admin.rs b/src/bin/tosin-admin.rs
index 034e4a9..e108207 100644
--- a/src/bin/tosin-admin.rs
+++ b/src/bin/tosin-admin.rs
@@ -6,8 +6,12 @@ use std::process::Command;
use structopt::StructOpt;
-const TOSIN_DEPENDENCY: &str = concat!(r#"tosin = { path = ""#, env!("CARGO_MANIFEST_DIR"), r#"" }
-diesel = { version = "1.4.4", features = ["sqlite"] }"#);
+const TOSIN_DEPENDENCY: &str = concat!(
+ r#"tosin = { path = '"#,
+ env!("CARGO_MANIFEST_DIR"),
+ r#"' }
+diesel = { version = "1.4.4", features = ["sqlite"] }"#
+);
const PROJECT_MAIN: &str = r#"
#[macro_use] extern crate diesel;
@@ -79,14 +83,10 @@ todo!("write some views");
#[derive(StructOpt, Debug)]
enum Opt {
/// Start a new project/site (can contain multiple apps)
- StartProject {
- name: Option<String>,
- },
+ StartProject { name: Option<String> },
/// Start a new app
- StartApp {
- name: String,
- }
+ StartApp { name: String },
}
fn main() {
diff --git a/tests/tutorial/mod.rs b/tests/tutorial/mod.rs
index 25f251b..8a602a3 100644
--- a/tests/tutorial/mod.rs
+++ b/tests/tutorial/mod.rs
@@ -63,9 +63,13 @@ pub fn step1() {
.check();
set_current_dir("tutorial").unwrap();
assert!(fs::metadata("Cargo.toml").is_ok());
- assert!(fs::read_to_string("Cargo.toml").unwrap().contains("tosin = "));
+ assert!(fs::read_to_string("Cargo.toml")
+ .unwrap()
+ .contains("tosin = "));
assert!(fs::metadata("src/main.rs").is_ok());
- assert!(fs::read_to_string("src/main.rs").unwrap().contains("tosin::main!"));
+ assert!(fs::read_to_string("src/main.rs")
+ .unwrap()
+ .contains("tosin::main!"));
// cargo run run-server
let port = thread_rng().gen_range(8081u16..9000u16);
@@ -90,20 +94,28 @@ pub fn step1() {
// tosin-admin start-app polls
Command::new(TOSIN_ADMIN)
.args(&["start-app", "polls"])
- .status().unwrap().check();
+ .status()
+ .unwrap()
+ .check();
assert!(fs::metadata("src/polls/mod.rs").is_ok());
// write views.rs
- fs::write("src/polls/views.rs", r#"
+ fs::write(
+ "src/polls/views.rs",
+ r#"
use tosin::http::{Reply, Response};
pub fn index() -> Response {
"Hello, world. You're at the polls index.".into_response()
}
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// write urls.rs
- fs::write("src/polls/urls.rs", r#"
+ fs::write(
+ "src/polls/urls.rs",
+ r#"
use tosin::urls::{UrlMap, url_map};
use super::views;
@@ -113,10 +125,14 @@ pub fn urls() -> UrlMap {
=> views::index, // TODO name: "index"
}
}
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// update main.rs
- fs::write("src/main.rs", r#"
+ fs::write(
+ "src/main.rs",
+ r#"
#[macro_use] extern crate diesel;
use tosin::Settings;
@@ -140,7 +156,9 @@ fn settings() -> Settings<impl Connectable> {
}
tosin::main!(urls(), settings());
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// poke that new route
let port = thread_rng().gen_range(8081u16..9000u16);
@@ -163,7 +181,14 @@ tosin::main!(urls(), settings());
// vibe check
let test_tutorial1 = Path::new("src");
let example_tutorial1 = Path::new(PROJECT_DIR).join("examples/tutorial01");
- for file in &["main.rs", "polls/mod.rs", "polls/migrations/mod.rs", "polls/models.rs", "polls/urls.rs", "polls/views.rs"] {
+ for file in &[
+ "main.rs",
+ "polls/mod.rs",
+ "polls/migrations/mod.rs",
+ "polls/models.rs",
+ "polls/urls.rs",
+ "polls/views.rs",
+ ] {
let test_path = test_tutorial1.join(file);
let test_file = fs::read_to_string(test_path).unwrap();
let example_path = example_tutorial1.join(file);
@@ -175,7 +200,9 @@ tosin::main!(urls(), settings());
pub fn step2() {
step1();
// update main.rs
- fs::write("src/main.rs", r#"
+ fs::write(
+ "src/main.rs",
+ r#"
#[macro_use] extern crate diesel;
use tosin::Settings;
@@ -202,7 +229,9 @@ fn settings() -> Settings<impl Connectable> {
}
tosin::main!(urls(), settings());
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// cargo run migrate
Command::new(CARGO)
@@ -210,9 +239,11 @@ tosin::main!(urls(), settings());
.status()
.unwrap()
.check();
-
+
// update Cargo.toml
- fs::write("Cargo.toml", r#"
+ fs::write(
+ "Cargo.toml",
+ r#"
[package]
name = "tutorial"
version = "0.1.0"
@@ -221,13 +252,18 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+chrono = "0.4"
diesel = { version = "1.4.4", features = ["sqlite"] }
time = "0.2.27"
-tosin = { path = "/home/cactus/Documents/tosin" }
- "#).unwrap();
-
+tosin = { path = "../../.." }
+ "#,
+ )
+ .unwrap();
+
// update polls/models.rs
- fs::write("src/polls/models.rs", r#"
+ fs::write(
+ "src/polls/models.rs",
+ r#"
use tosin::db::models::{Model, Id, gather};
#[derive(Model)]
@@ -236,7 +272,7 @@ pub struct Question {
#[model(max_length=200)]
question_text: String,
/// date published
- pub_date: time::PrimitiveDateTime,
+ pub_date: chrono::NaiveDateTime,
}
#[derive(Model)]
@@ -251,10 +287,14 @@ pub struct Choice {
}
gather!();
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// update main.rs
- fs::write("src/main.rs", r#"
+ fs::write(
+ "src/main.rs",
+ r#"
#[macro_use] extern crate diesel;
use tosin::Settings;
@@ -282,7 +322,9 @@ fn settings() -> Settings<impl Connectable> {
}
tosin::main!(urls(), settings());
- "#).unwrap();
+ "#,
+ )
+ .unwrap();
// cargo run make-migrations
Command::new(CARGO)