mirror of
https://codeberg.org/andyscott/ziglings.git
synced 2024-12-22 14:03:10 -05:00
Added testing ability
For the full details, see patches/README.md :-)
This commit is contained in:
parent
654437c0bc
commit
03a09639c6
49 changed files with 160 additions and 9 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
*.swp
|
*.swp
|
||||||
zig-cache/
|
zig-cache/
|
||||||
answers/
|
answers/
|
||||||
|
patches/healed/
|
||||||
|
|
13
build.zig
13
build.zig
|
@ -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;
|
||||||
|
|
4
patches/01_hello.patch
Normal file
4
patches/01_hello.patch
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
19c19
|
||||||
|
< fn main() void {
|
||||||
|
---
|
||||||
|
> pub fn main() void {
|
4
patches/02_std.patch
Normal file
4
patches/02_std.patch
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
14c14
|
||||||
|
< ??? = @import("std");
|
||||||
|
---
|
||||||
|
> const std = @import("std");
|
1
patches/03_assignment.patch
Normal file
1
patches/03_assignment.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/04_arrays.patch
Normal file
1
patches/04_arrays.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/05_arrays2.patch
Normal file
1
patches/05_arrays2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/06_strings.patch
Normal file
1
patches/06_strings.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/07_strings2.patch
Normal file
1
patches/07_strings2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/08_quiz.patch
Normal file
1
patches/08_quiz.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/09_if.patch
Normal file
1
patches/09_if.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/10_if2.patch
Normal file
1
patches/10_if2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/11_while.patch
Normal file
1
patches/11_while.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/12_while2.patch
Normal file
1
patches/12_while2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/13_while3.patch
Normal file
1
patches/13_while3.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/14_while4.patch
Normal file
1
patches/14_while4.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/15_for.patch
Normal file
1
patches/15_for.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/16_for2.patch
Normal file
1
patches/16_for2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/17_quiz2.patch
Normal file
1
patches/17_quiz2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/18_functions.patch
Normal file
1
patches/18_functions.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/19_functions2.patch
Normal file
1
patches/19_functions2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/20_quiz3.patch
Normal file
1
patches/20_quiz3.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/21_errors.patch
Normal file
1
patches/21_errors.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/22_errors2.patch
Normal file
1
patches/22_errors2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/23_errors3.patch
Normal file
1
patches/23_errors3.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/24_errors4.patch
Normal file
1
patches/24_errors4.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/25_errors5.patch
Normal file
1
patches/25_errors5.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/26_hello2.patch
Normal file
1
patches/26_hello2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/27_defer.patch
Normal file
1
patches/27_defer.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/28_defer2.patch
Normal file
1
patches/28_defer2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/29_errdefer.patch
Normal file
1
patches/29_errdefer.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/30_switch.patch
Normal file
1
patches/30_switch.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/31_switch2.patch
Normal file
1
patches/31_switch2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/32_unreachable.patch
Normal file
1
patches/32_unreachable.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/33_iferror.patch
Normal file
1
patches/33_iferror.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/34_quiz4.patch
Normal file
1
patches/34_quiz4.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/35_enums.patch
Normal file
1
patches/35_enums.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/36_enums2.patch
Normal file
1
patches/36_enums2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/37_structs.patch
Normal file
1
patches/37_structs.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/38_structs2.patch
Normal file
1
patches/38_structs2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/39_pointers.patch
Normal file
1
patches/39_pointers.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/40_pointers2.patch
Normal file
1
patches/40_pointers2.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/41_pointers3.patch
Normal file
1
patches/41_pointers3.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/42_pointers4.patch
Normal file
1
patches/42_pointers4.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/43_pointers5.patch
Normal file
1
patches/43_pointers5.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
1
patches/44_quiz5.patch
Normal file
1
patches/44_quiz5.patch
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -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.)
|
|
||||||
|
|
45
patches/eowyn.sh
Executable file
45
patches/eowyn.sh
Executable file
|
@ -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
|
24
patches/gollum.sh
Executable file
24
patches/gollum.sh
Executable file
|
@ -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…
Reference in a new issue