Skip to content

Commit

Permalink
Merge pull request #22 from rust-lang-ar/staged_testing
Browse files Browse the repository at this point in the history
Add test runner
  • Loading branch information
hernangonzalez authored Nov 4, 2024
2 parents 11356ba + d33464a commit 706bcec
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 8 deletions.
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"]
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!"

0 comments on commit 706bcec

Please sign in to comment.