Compare commits

..

No commits in common. "6449aed9ec0e41fdfb816788d8825a046bc02c81" and "9f509a929f0c76d20030cd0eeca43181ff9842e6" have entirely different histories.

20 changed files with 21 additions and 169 deletions

1
Cargo.lock generated
View File

@ -209,7 +209,6 @@ name = "tester"
version = "0.1.0"
dependencies = [
"clap",
"serde",
"serde_yaml",
]

View File

@ -7,5 +7,4 @@ edition = "2021"
[dependencies]
clap = { version = "4.4.16", features = ["derive"] }
serde = { version = "1.0.195", features = ["derive"] }
serde_yaml = "0.9.30"

View File

@ -1,7 +1,5 @@
use std::path::Path;
use std::path::{Path, PathBuf};
use crate::util;
pub fn grade(verbosity: u8, config: util::config::Config, grade_config: Option<&Path>) {
pub fn grade(verbosity: u8, config_file: PathBuf, grade_config: Option<&Path>) {
println!("Grading!");
}

View File

@ -5,7 +5,6 @@ use clap::{Parser, Subcommand};
mod validate;
mod run;
mod grade;
pub mod util;
fn main() {
// get cli args
@ -13,15 +12,11 @@ fn main() {
// parse the verbosity and eliminate the Option<>
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 {
Command::Validate => validate::validate(verbosity, config),
Command::Run => run::run(verbosity, config),
Command::Grade => grade::grade(verbosity, config, cli.grading_conf.as_deref()),
Command::Validate => validate::validate(verbosity, cli.config_file),
Command::Run => run::run(verbosity, cli.config_file),
Command::Grade => grade::grade(verbosity, cli.config_file, cli.grading_conf.as_deref()),
}
}
@ -33,8 +28,6 @@ struct Cli {
#[arg(short, long, action = clap::ArgAction::Count)]
verbosity: Option<u8>,
//TODO implement a thread count variable for the runner
/// Set the config file
#[arg(short, long, value_name = "CONFIG")]
config_file: PathBuf,

View File

@ -1,10 +1,5 @@
use crate::util;
use std::path::PathBuf;
pub fn run(verbosity: u8, config: util::config::Config) {
pub fn run(verbosity: u8, config_file: PathBuf) {
println!("Running!");
}
#[cfg(test)]
mod tests {
}

View File

@ -1 +1 @@
pub mod config;
mod config;

View File

@ -1,84 +1,32 @@
use std::path::PathBuf;
use std::{path::PathBuf, collections::HashMap};
use serde::Deserialize;
use serde_yaml::{self};
use serde_yaml;
#[derive(Debug, Deserialize)]
pub struct Config {
tested_executables: Vec<Team>,
#[derive(Default)]
struct Config {
executable_paths: HashMap<String, PathBuf>,
input_path: PathBuf,
output_path: PathBuf,
in_stream_path: PathBuf,
runtimes: Option<Vec<Team>>,
toolchains: Vec<Toolchain>,
}
#[derive(Debug, Deserialize)]
pub struct Team {
#[derive(Default)]
struct Toolchain {
name: String,
executable: PathBuf,
steps: Vec<Step>,
}
#[derive(Debug, Deserialize)]
pub struct Toolchain {
name: String,
steps: Vec<Step>,}
#[derive(Debug, Deserialize)]
pub struct Step {
#[derive(Default)]
struct Step {
name: String,
executable_path: Option<PathBuf>, // if None then we use the current executable path
arguments: Vec<String>, // special string $INPUT corresponds to previous step output
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) -> 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),
};
pub fn parse_config(path: PathBuf) {
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);
}
}

View File

@ -1,37 +0,0 @@
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: "-"

View File

@ -1,37 +0,0 @@
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: "-"

View File

@ -1,11 +1,5 @@
use crate::util;
use std::path::PathBuf;
pub fn validate(verbosity: u8, config: util::config::Config) {
pub fn validate(verbosity: u8, config_file: PathBuf) {
println!("Validating");
}
#[cfg(test)]
mod tests {
}