Compare commits
3 Commits
9f509a929f
...
6449aed9ec
Author | SHA1 | Date |
---|---|---|
Ayrton Chilibeck | 6449aed9ec | |
Ayrton Chilibeck | 6e9b15571c | |
Ayrton Chilibeck | bb968d770e |
|
@ -209,6 +209,7 @@ name = "tester"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
|
"serde",
|
||||||
"serde_yaml",
|
"serde_yaml",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -7,4 +7,5 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "4.4.16", features = ["derive"] }
|
clap = { version = "4.4.16", features = ["derive"] }
|
||||||
|
serde = { version = "1.0.195", features = ["derive"] }
|
||||||
serde_yaml = "0.9.30"
|
serde_yaml = "0.9.30"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::Path;
|
||||||
|
|
||||||
pub fn grade(verbosity: u8, config_file: PathBuf, grade_config: Option<&Path>) {
|
use crate::util;
|
||||||
|
|
||||||
|
pub fn grade(verbosity: u8, config: util::config::Config, grade_config: Option<&Path>) {
|
||||||
println!("Grading!");
|
println!("Grading!");
|
||||||
}
|
}
|
||||||
|
|
13
src/main.rs
13
src/main.rs
|
@ -5,6 +5,7 @@ use clap::{Parser, Subcommand};
|
||||||
mod validate;
|
mod validate;
|
||||||
mod run;
|
mod run;
|
||||||
mod grade;
|
mod grade;
|
||||||
|
pub mod util;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// get cli args
|
// get cli args
|
||||||
|
@ -12,11 +13,15 @@ fn main() {
|
||||||
|
|
||||||
// parse the verbosity and eliminate the Option<>
|
// parse the verbosity and eliminate the Option<>
|
||||||
let verbosity = get_verbosity(cli.verbosity);
|
let verbosity = get_verbosity(cli.verbosity);
|
||||||
|
let config = util::config::parse_config(cli.config_file);
|
||||||
|
|
||||||
|
//parse the config file
|
||||||
|
// let config = parse_config(cli.config_file);
|
||||||
|
|
||||||
match &cli.command {
|
match &cli.command {
|
||||||
Command::Validate => validate::validate(verbosity, cli.config_file),
|
Command::Validate => validate::validate(verbosity, config),
|
||||||
Command::Run => run::run(verbosity, cli.config_file),
|
Command::Run => run::run(verbosity, config),
|
||||||
Command::Grade => grade::grade(verbosity, cli.config_file, cli.grading_conf.as_deref()),
|
Command::Grade => grade::grade(verbosity, config, cli.grading_conf.as_deref()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +33,8 @@ struct Cli {
|
||||||
#[arg(short, long, action = clap::ArgAction::Count)]
|
#[arg(short, long, action = clap::ArgAction::Count)]
|
||||||
verbosity: Option<u8>,
|
verbosity: Option<u8>,
|
||||||
|
|
||||||
|
//TODO implement a thread count variable for the runner
|
||||||
|
|
||||||
/// Set the config file
|
/// Set the config file
|
||||||
#[arg(short, long, value_name = "CONFIG")]
|
#[arg(short, long, value_name = "CONFIG")]
|
||||||
config_file: PathBuf,
|
config_file: PathBuf,
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
use std::path::PathBuf;
|
use crate::util;
|
||||||
|
|
||||||
pub fn run(verbosity: u8, config_file: PathBuf) {
|
pub fn run(verbosity: u8, config: util::config::Config) {
|
||||||
println!("Running!");
|
println!("Running!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
mod config;
|
pub mod config;
|
||||||
|
|
|
@ -1,32 +1,84 @@
|
||||||
use std::{path::PathBuf, collections::HashMap};
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use serde_yaml;
|
use serde::Deserialize;
|
||||||
|
use serde_yaml::{self};
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Config {
|
pub struct Config {
|
||||||
executable_paths: HashMap<String, PathBuf>,
|
tested_executables: Vec<Team>,
|
||||||
|
|
||||||
input_path: PathBuf,
|
input_path: PathBuf,
|
||||||
output_path: PathBuf,
|
output_path: PathBuf,
|
||||||
|
in_stream_path: PathBuf,
|
||||||
|
|
||||||
|
runtimes: Option<Vec<Team>>,
|
||||||
|
|
||||||
toolchains: Vec<Toolchain>,
|
toolchains: Vec<Toolchain>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Toolchain {
|
pub struct Team {
|
||||||
name: String,
|
name: String,
|
||||||
steps: Vec<Step>,
|
executable: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Debug, Deserialize)]
|
||||||
struct Step {
|
pub struct Toolchain {
|
||||||
|
name: String,
|
||||||
|
steps: Vec<Step>,}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Step {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
||||||
executable_path: Option<PathBuf>, // if None then we use the current executable path
|
executable_path: Option<PathBuf>, // if None then we use the current executable path
|
||||||
arguments: Vec<String>, // special string $INPUT corresponds to previous step output
|
arguments: Vec<String>, // special string $INPUT corresponds to previous step output
|
||||||
output: String, // the output file name
|
output: String, // the output file name
|
||||||
|
|
||||||
|
uses_runtime: Option<bool>,
|
||||||
|
uses_in_stream: Option<bool>,
|
||||||
|
allow_error: Option<bool>
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_config(path: PathBuf) {
|
pub fn parse_config(path: PathBuf) -> Config {
|
||||||
|
// load the yaml from the system path, if it fails, tell the user and exit
|
||||||
|
let yaml_load = std::fs::File::open(path);
|
||||||
|
let yaml_file = match yaml_load {
|
||||||
|
Ok(file) => file,
|
||||||
|
Err(error) => panic!("Failed to load configuration file 🤮, error thrown: {:?}", error),
|
||||||
|
};
|
||||||
|
|
||||||
|
let config: Config = match serde_yaml::from_reader(yaml_file) {
|
||||||
|
Ok(conf) => conf,
|
||||||
|
Err(error) => panic!("Failed to parse YAML file 😕, error: {}", error),
|
||||||
|
};
|
||||||
|
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn test_nonexistant_config() {
|
||||||
|
let path: PathBuf = PathBuf::from("src/util/test/parse_config/non_existant.yaml");
|
||||||
|
parse_config(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_load_config() {
|
||||||
|
let path: PathBuf = PathBuf::from("src/util/test/parse_config/config.yaml");
|
||||||
|
let config = parse_config(path);
|
||||||
|
println!("{:?}", config);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
#[should_panic]
|
||||||
|
fn test_load_bad_config() {
|
||||||
|
let path: PathBuf = PathBuf::from("src/util/test/parse_config/bad_config.yaml");
|
||||||
|
let config = parse_config(path);
|
||||||
|
println!("{:?}", config);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
|
||||||
|
input_path: "/path/to/dir"
|
||||||
|
in_stream_path: "/path/to/in/stream"
|
||||||
|
|
||||||
|
tested_executables:
|
||||||
|
- name: "team1"
|
||||||
|
executable: "/path/to/exec"
|
||||||
|
- name: "team2"
|
||||||
|
executable: "/path/to/exec2"
|
||||||
|
|
||||||
|
runtimes:
|
||||||
|
- name: "team1"
|
||||||
|
executable: "/path/to/exec"
|
||||||
|
- name: "team1"
|
||||||
|
executable: "/path/to/exec"
|
||||||
|
|
||||||
|
toolchains:
|
||||||
|
- name: "toolchain1"
|
||||||
|
steps:
|
||||||
|
- name: "step1"
|
||||||
|
executable_path: "$EXE"
|
||||||
|
arguments:
|
||||||
|
- $INPUT
|
||||||
|
- $OUTPUT
|
||||||
|
output: "out.test"
|
||||||
|
- name: "step2"
|
||||||
|
executable_path: "/bin/bash"
|
||||||
|
arguments:
|
||||||
|
- echo "Hello World"
|
||||||
|
output: "-"
|
||||||
|
- name: "toolchain2"
|
||||||
|
steps:
|
||||||
|
- name: "step1"
|
||||||
|
executable_path: "/bin/bash"
|
||||||
|
arguments:
|
||||||
|
- echo "Hello toolchain 2!"
|
||||||
|
output: "-"
|
|
@ -0,0 +1,37 @@
|
||||||
|
input_path: "/path/to/dir"
|
||||||
|
output_path: "/path/to/out/dir"
|
||||||
|
in_stream_path: "/path/to/in/stream"
|
||||||
|
|
||||||
|
tested_executables:
|
||||||
|
- name: "team1"
|
||||||
|
executable: "/path/to/exec"
|
||||||
|
- name: "team2"
|
||||||
|
executable: "/path/to/exec2"
|
||||||
|
|
||||||
|
runtimes:
|
||||||
|
- name: "team1"
|
||||||
|
executable: "/path/to/exec"
|
||||||
|
- name: "team1"
|
||||||
|
executable: "/path/to/exec"
|
||||||
|
|
||||||
|
toolchains:
|
||||||
|
- name: "toolchain1"
|
||||||
|
steps:
|
||||||
|
- name: "step1"
|
||||||
|
executable_path: "$EXE"
|
||||||
|
arguments:
|
||||||
|
- $INPUT
|
||||||
|
- $OUTPUT
|
||||||
|
output: "out.test"
|
||||||
|
- name: "step2"
|
||||||
|
executable_path: "/bin/bash"
|
||||||
|
arguments:
|
||||||
|
- echo "Hello World"
|
||||||
|
output: "-"
|
||||||
|
- name: "toolchain2"
|
||||||
|
steps:
|
||||||
|
- name: "step1"
|
||||||
|
executable_path: "/bin/bash"
|
||||||
|
arguments:
|
||||||
|
- echo "Hello toolchain 2!"
|
||||||
|
output: "-"
|
|
@ -1,5 +1,11 @@
|
||||||
use std::path::PathBuf;
|
use crate::util;
|
||||||
|
|
||||||
pub fn validate(verbosity: u8, config_file: PathBuf) {
|
pub fn validate(verbosity: u8, config: util::config::Config) {
|
||||||
println!("Validating");
|
println!("Validating");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue