aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--build.zig13
-rw-r--r--patches/01_hello.patch4
-rw-r--r--patches/02_std.patch4
-rw-r--r--patches/03_assignment.patch1
-rw-r--r--patches/04_arrays.patch1
-rw-r--r--patches/05_arrays2.patch1
-rw-r--r--patches/06_strings.patch1
-rw-r--r--patches/07_strings2.patch1
-rw-r--r--patches/08_quiz.patch1
-rw-r--r--patches/09_if.patch1
-rw-r--r--patches/10_if2.patch1
-rw-r--r--patches/11_while.patch1
-rw-r--r--patches/12_while2.patch1
-rw-r--r--patches/13_while3.patch1
-rw-r--r--patches/14_while4.patch1
-rw-r--r--patches/15_for.patch1
-rw-r--r--patches/16_for2.patch1
-rw-r--r--patches/17_quiz2.patch1
-rw-r--r--patches/18_functions.patch1
-rw-r--r--patches/19_functions2.patch1
-rw-r--r--patches/20_quiz3.patch1
-rw-r--r--patches/21_errors.patch1
-rw-r--r--patches/22_errors2.patch1
-rw-r--r--patches/23_errors3.patch1
-rw-r--r--patches/24_errors4.patch1
-rw-r--r--patches/25_errors5.patch1
-rw-r--r--patches/26_hello2.patch1
-rw-r--r--patches/27_defer.patch1
-rw-r--r--patches/28_defer2.patch1
-rw-r--r--patches/29_errdefer.patch1
-rw-r--r--patches/30_switch.patch1
-rw-r--r--patches/31_switch2.patch1
-rw-r--r--patches/32_unreachable.patch1
-rw-r--r--patches/33_iferror.patch1
-rw-r--r--patches/34_quiz4.patch1
-rw-r--r--patches/35_enums.patch1
-rw-r--r--patches/36_enums2.patch1
-rw-r--r--patches/37_structs.patch1
-rw-r--r--patches/38_structs2.patch1
-rw-r--r--patches/39_pointers.patch1
-rw-r--r--patches/40_pointers2.patch1
-rw-r--r--patches/41_pointers3.patch1
-rw-r--r--patches/42_pointers4.patch1
-rw-r--r--patches/43_pointers5.patch1
-rw-r--r--patches/44_quiz5.patch1
-rw-r--r--patches/README.md36
-rwxr-xr-xpatches/eowyn.sh45
-rwxr-xr-xpatches/gollum.sh24
49 files changed, 160 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index 85939f4..eeb5eef 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
*.swp
zig-cache/
answers/
+patches/healed/
diff --git a/build.zig b/build.zig
index e80e98e..a9c4783 100644
--- a/build.zig
+++ b/build.zig
@@ -330,15 +330,17 @@ pub fn build(b: *Builder) void {
var prev_chain_verify = verify_all;
+ const use_healed = b.option(bool, "healed", "Run exercises from patches/healed") orelse false;
+
for (exercises) |ex| {
const base_name = ex.baseName();
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;
const build_step = b.addExecutable(base_name, file_path);
build_step.install();
- const verify_step = ZiglingStep.create(b, ex);
+ const verify_step = ZiglingStep.create(b, ex, use_healed);
const key = ex.key();
@@ -375,13 +377,15 @@ const ZiglingStep = struct {
step: Step,
exercise: Exercise,
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;
self.* = .{
.step = Step.init(.Custom, exercise.main_file, builder.allocator, make),
.exercise = exercise,
.builder = builder,
+ .use_healed = use_healed,
};
return self;
}
@@ -490,7 +494,8 @@ const ZiglingStep = struct {
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("--cache-dir") catch unreachable;
diff --git a/patches/01_hello.patch b/patches/01_hello.patch
new file mode 100644
index 0000000..fb360a7
--- /dev/null
+++ b/patches/01_hello.patch
@@ -0,0 +1,4 @@
+19c19
+< fn main() void {
+---
+> pub fn main() void {
diff --git a/patches/02_std.patch b/patches/02_std.patch
new file mode 100644
index 0000000..6c97adb
--- /dev/null
+++ b/patches/02_std.patch
@@ -0,0 +1,4 @@
+14c14
+< ??? = @import("std");
+---
+> const std = @import("std");
diff --git a/patches/03_assignment.patch b/patches/03_assignment.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/03_assignment.patch
@@ -0,0 +1 @@
+
diff --git a/patches/04_arrays.patch b/patches/04_arrays.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/04_arrays.patch
@@ -0,0 +1 @@
+
diff --git a/patches/05_arrays2.patch b/patches/05_arrays2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/05_arrays2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/06_strings.patch b/patches/06_strings.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/06_strings.patch
@@ -0,0 +1 @@
+
diff --git a/patches/07_strings2.patch b/patches/07_strings2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/07_strings2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/08_quiz.patch b/patches/08_quiz.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/08_quiz.patch
@@ -0,0 +1 @@
+
diff --git a/patches/09_if.patch b/patches/09_if.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/09_if.patch
@@ -0,0 +1 @@
+
diff --git a/patches/10_if2.patch b/patches/10_if2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/10_if2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/11_while.patch b/patches/11_while.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/11_while.patch
@@ -0,0 +1 @@
+
diff --git a/patches/12_while2.patch b/patches/12_while2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/12_while2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/13_while3.patch b/patches/13_while3.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/13_while3.patch
@@ -0,0 +1 @@
+
diff --git a/patches/14_while4.patch b/patches/14_while4.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/14_while4.patch
@@ -0,0 +1 @@
+
diff --git a/patches/15_for.patch b/patches/15_for.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/15_for.patch
@@ -0,0 +1 @@
+
diff --git a/patches/16_for2.patch b/patches/16_for2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/16_for2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/17_quiz2.patch b/patches/17_quiz2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/17_quiz2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/18_functions.patch b/patches/18_functions.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/18_functions.patch
@@ -0,0 +1 @@
+
diff --git a/patches/19_functions2.patch b/patches/19_functions2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/19_functions2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/20_quiz3.patch b/patches/20_quiz3.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/20_quiz3.patch
@@ -0,0 +1 @@
+
diff --git a/patches/21_errors.patch b/patches/21_errors.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/21_errors.patch
@@ -0,0 +1 @@
+
diff --git a/patches/22_errors2.patch b/patches/22_errors2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/22_errors2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/23_errors3.patch b/patches/23_errors3.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/23_errors3.patch
@@ -0,0 +1 @@
+
diff --git a/patches/24_errors4.patch b/patches/24_errors4.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/24_errors4.patch
@@ -0,0 +1 @@
+
diff --git a/patches/25_errors5.patch b/patches/25_errors5.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/25_errors5.patch
@@ -0,0 +1 @@
+
diff --git a/patches/26_hello2.patch b/patches/26_hello2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/26_hello2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/27_defer.patch b/patches/27_defer.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/27_defer.patch
@@ -0,0 +1 @@
+
diff --git a/patches/28_defer2.patch b/patches/28_defer2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/28_defer2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/29_errdefer.patch b/patches/29_errdefer.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/29_errdefer.patch
@@ -0,0 +1 @@
+
diff --git a/patches/30_switch.patch b/patches/30_switch.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/30_switch.patch
@@ -0,0 +1 @@
+
diff --git a/patches/31_switch2.patch b/patches/31_switch2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/31_switch2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/32_unreachable.patch b/patches/32_unreachable.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/32_unreachable.patch
@@ -0,0 +1 @@
+
diff --git a/patches/33_iferror.patch b/patches/33_iferror.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/33_iferror.patch
@@ -0,0 +1 @@
+
diff --git a/patches/34_quiz4.patch b/patches/34_quiz4.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/34_quiz4.patch
@@ -0,0 +1 @@
+
diff --git a/patches/35_enums.patch b/patches/35_enums.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/35_enums.patch
@@ -0,0 +1 @@
+
diff --git a/patches/36_enums2.patch b/patches/36_enums2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/36_enums2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/37_structs.patch b/patches/37_structs.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/37_structs.patch
@@ -0,0 +1 @@
+
diff --git a/patches/38_structs2.patch b/patches/38_structs2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/38_structs2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/39_pointers.patch b/patches/39_pointers.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/39_pointers.patch
@@ -0,0 +1 @@
+
diff --git a/patches/40_pointers2.patch b/patches/40_pointers2.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/40_pointers2.patch
@@ -0,0 +1 @@
+
diff --git a/patches/41_pointers3.patch b/patches/41_pointers3.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/41_pointers3.patch
@@ -0,0 +1 @@
+
diff --git a/patches/42_pointers4.patch b/patches/42_pointers4.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/42_pointers4.patch
@@ -0,0 +1 @@
+
diff --git a/patches/43_pointers5.patch b/patches/43_pointers5.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/43_pointers5.patch
@@ -0,0 +1 @@
+
diff --git a/patches/44_quiz5.patch b/patches/44_quiz5.patch
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/patches/44_quiz5.patch
@@ -0,0 +1 @@
+
diff --git a/patches/README.md b/patches/README.md
index 09fecbd..0a4e8e0 100644
--- a/patches/README.md
+++ b/patches/README.md
@@ -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.)
diff --git a/patches/eowyn.sh b/patches/eowyn.sh
new file mode 100755
index 0000000..53b87d2
--- /dev/null
+++ b/patches/eowyn.sh
@@ -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
diff --git a/patches/gollum.sh b/patches/gollum.sh
new file mode 100755
index 0000000..78c7756
--- /dev/null
+++ b/patches/gollum.sh
@@ -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