Skip to content
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

Add test runner #22

Merged
merged 3 commits into from
Nov 4, 2024
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/book/build
/book/build
Gemfile.lock
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ unsafe_code = "forbid"

[features]
stage0 = []
stage1 = []
stage2 = []
stage3 = []
stage4 = []
stage5 = []
stage1 = ["stage0"]
hernangonzalez marked this conversation as resolved.
Show resolved Hide resolved
stage2 = ["stage1"]
stage3 = ["stage2"]
stage4 = ["stage3"]
stage5 = ["stage4"]
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gem 'toml-rb'
28 changes: 28 additions & 0 deletions run_tests.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'toml-rb'

# Helper functions
def ensure_build
system "cargo build --release"
if $?.exitstatus != 0
puts "Oops, we could not build the project!"
exit 1
end
end

def select_stage
path = File.join(File.dirname(__FILE__), 'Course.toml')
toml_data = TomlRB.load_file(path)
return toml_data['test']['level']
end

# Build the project
puts "Building the project..."
ensure_build

# Run the tests
puts "Running tests..."
stage = select_stage
system "cargo test --release --features stage#{stage}"

# Congrats!
puts "All Done!"
2 changes: 2 additions & 0 deletions tests/helpers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

/// Splits the outbut by space, newline, tab or null characters
pub fn split_ls_output(output: &[u8]) -> Vec<&str> {
std::str::from_utf8(output)
Expand Down
5 changes: 4 additions & 1 deletion tests/stage0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ fn test_stage_0() {
.expect("failed to execute process");

assert!(output.status.success());
assert_eq!(output.stdout, b"Hola Oxidar!\n")
assert_eq!(
std::str::from_utf8(&output.stdout).expect("a utf8 string output"),
"Hola Oxidar!\n"
)
}
1 change: 0 additions & 1 deletion tests/stage4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

mod helpers;

use helpers::{split_ls_column_output, split_ls_output_by_newline};
use rstest::rstest;
use std::process::Command;

Expand Down
16 changes: 16 additions & 0 deletions upgrade_stage.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'toml-rb'

# Load the toml file
path = File.join(File.dirname(__FILE__), 'Course.toml')
toml_data = TomlRB.load_file(path)

# Upgrade the stage
stage = toml_data['test']['level']
next_stage = Integer(stage) + 1
puts "Upgrading to stage #{next_stage}..."
toml_data['test']['level'] = next_stage.to_s

# Save the file
data = TomlRB.dump(toml_data)
File.write(path, data)
puts "All done!"
Loading