Added testing ability

For the full details, see patches/README.md :-)
pull/2/head
Dave Gauer 4 years ago
parent 654437c0bc
commit 03a09639c6

1
.gitignore vendored

@ -2,3 +2,4 @@
*.swp *.swp
zig-cache/ zig-cache/
answers/ answers/
patches/healed/

@ -330,15 +330,17 @@ pub fn build(b: *Builder) void {
var prev_chain_verify = verify_all; var prev_chain_verify = verify_all;
const use_healed = b.option(bool, "healed", "Run exercises from patches/healed") orelse false;
for (exercises) |ex| { for (exercises) |ex| {
const base_name = ex.baseName(); const base_name = ex.baseName();
const file_path = std.fs.path.join(b.allocator, &[_][]const u8{ const file_path = std.fs.path.join(b.allocator, &[_][]const u8{
"exercises", ex.main_file, if (use_healed) "patches/healed" else "exercises", ex.main_file,
}) catch unreachable; }) catch unreachable;
const build_step = b.addExecutable(base_name, file_path); const build_step = b.addExecutable(base_name, file_path);
build_step.install(); build_step.install();
const verify_step = ZiglingStep.create(b, ex); const verify_step = ZiglingStep.create(b, ex, use_healed);
const key = ex.key(); const key = ex.key();
@ -375,13 +377,15 @@ const ZiglingStep = struct {
step: Step, step: Step,
exercise: Exercise, exercise: Exercise,
builder: *Builder, builder: *Builder,
use_healed: bool,
pub fn create(builder: *Builder, exercise: Exercise) *@This() { pub fn create(builder: *Builder, exercise: Exercise, use_healed: bool) *@This() {
const self = builder.allocator.create(@This()) catch unreachable; const self = builder.allocator.create(@This()) catch unreachable;
self.* = .{ self.* = .{
.step = Step.init(.Custom, exercise.main_file, builder.allocator, make), .step = Step.init(.Custom, exercise.main_file, builder.allocator, make),
.exercise = exercise, .exercise = exercise,
.builder = builder, .builder = builder,
.use_healed = use_healed,
}; };
return self; return self;
} }
@ -490,7 +494,8 @@ const ZiglingStep = struct {
zig_args.append(@tagName(builder.color)) catch unreachable; zig_args.append(@tagName(builder.color)) catch unreachable;
} }
const zig_file = std.fs.path.join(builder.allocator, &[_][]const u8{ "exercises", self.exercise.main_file }) catch unreachable; const zig_file = std.fs.path.join(builder.allocator, &[_][]const u8{
if (self.use_healed) "patches/healed" else "exercises", self.exercise.main_file }) catch unreachable;
zig_args.append(builder.pathFromRoot(zig_file)) catch unreachable; zig_args.append(builder.pathFromRoot(zig_file)) catch unreachable;
zig_args.append("--cache-dir") catch unreachable; zig_args.append("--cache-dir") catch unreachable;

@ -0,0 +1,4 @@
19c19
< fn main() void {
---
> pub fn main() void {

@ -0,0 +1,4 @@
14c14
< ??? = @import("std");
---
> const std = @import("std");

@ -1,9 +1,35 @@
# The ziglings/patches Directory # No Peeking! :-)
This is how ziglings is tested. Welcome to the ziglings/patches directory. This is how ziglings is tested.
The patches fix the broken exercises so that they work again. The patches fix the broken exercises so that they work again, which means the
answers are here, so no peeking!
No peeking! :-) ## Éowyn
A Bash shell script named `eowyn.sh` dwells here. She heals the little broken
programs and places them in a `healed` directory, which is not committed to the
repo.
```bash
$ ./eowyn.sh
```
(If you invoke her from elsewhere, she'll come here to ply her trade.)
The `build.zig` build script at the heart of Ziglings has a top-secret option
which tells it to test from the `patches/healed/` dir rather than `exercises/`:
```bash
$ zig build -Dhealed [step]
```
Éowyn tests all healed programs using this secret option.
## Gollum
Another Bash shell script named `gollum.sh` may also be found. He snatches the
original answers and stows them in his secret answers stash. If you leave him
alone, he'll leave you alone.
(Further tooling and explanation goes here.)

@ -0,0 +1,45 @@
#!/bin/bash
#
# "I will be a shieldmaiden no longer,
# nor vie with the great Riders, nor
# take joy only in the songs of slaying.
# I will be a healer, and love all things
# that grow and are not barren."
# Éowyn, The Return of the King
#
#
# This script shall heal the little broken programs
# using the patches in this directory and convey them
# to convalesce in the healed directory.
#
# We run from the patches dir. Go there now if not already.
cd $(dirname $(which $0))
pwd # Show it upon the screen so all shall be made apparent.
# Create healed/ directory here if it doesn't already exist.
mkdir -p healed
# Cycle through all the little broken Zig applications.
for broken in ../exercises/*.zig
do
# Remove the dir and extension, rendering the True Name.
true_name=$(basename $broken .zig)
if [[ -f $true_name.patch ]]
then
# Apply the bandages to the wounds, grow new limbs, let
# new life spring into the broken bodies of the fallen.
echo Healing $true_name...
patch --output=healed/$true_name.zig $broken $true_name.patch
else
echo Cannot heal $true_name. Making empty patch.
echo > $true_name.patch
fi
done
# Return to the home of our ancestors.
cd ..
# Test the healed exercises. May the compiler have mercy upon us.
zig build -Dhealed

@ -0,0 +1,24 @@
#!/bin/bash
#
# "It isn't fair, my precious, is it,
# to ask us what it's got in it's
# nassty little pocketsess?"
# Gollum, The Hobbit, or There and Back Again
#
cd $(dirname $(which $0))
f=$(basename ../exercises/$1*.zig .zig 2> /dev/null)
b=../exercises/$f.zig
a=../answers/$f.zig
p=$f.patch
printf "\tf: '$f'\n\tb: '$b'\n\ta: '$a'\n"
if [[ ! -f $b ]]; then echo "We hates it!"; exit 1; fi
if [[ ! -a $a ]]; then echo "Where is it? Where is the answer, precious?"; exit; fi
echo Hisssss!
diff $b $a > $p
cat $p
Loading…
Cancel
Save