Compare commits

...

25 Commits

Author SHA1 Message Date
Chris Boesch 62ad50b71e Merge pull request 'Switched to new reader' (#305) from i304 into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/305
2025-09-03 10:57:17 +02:00
Chris Boesch ed93882b19
Switched to new reader 2025-09-03 10:45:19 +02:00
Chris Boesch a4c1774847 Merge pull request 'formating contributing' (#301) from contributing into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/301
2025-08-25 21:50:29 +02:00
Chris Boesch e12ee5cb9e
formating contributing 2025-08-25 21:46:25 +02:00
Chris Boesch 0dbe83b20e Merge pull request 'fixes some minor typos' (#300) from i122 into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/300
2025-08-24 19:30:51 +02:00
Chris Boesch e422e24215
fixes some minor typos 2025-08-24 19:26:30 +02:00
Chris Boesch 4134d4fa6f Merge pull request 'Formatting' (#299) from gollum into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/299
2025-08-24 17:55:46 +02:00
Chris Boesch ad361c4b18
Formatting 2025-08-24 17:55:03 +02:00
Chris Boesch d4215ce5c6 Merge pull request 'Added instructions for patch files' (#298) from gollum into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/298
2025-08-24 16:31:54 +02:00
Chris Boesch fd9e9aa36e
Added instructions for patch files 2025-08-24 16:31:22 +02:00
Chris Boesch b3178e81a8 Merge pull request 'Added instructions for patch files' (#297) from gollum into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/297
2025-08-24 16:27:03 +02:00
Chris Boesch c36fe8007d
Added instructions for patch files 2025-08-24 16:23:51 +02:00
Chris Boesch 7488727625 Merge pull request 'testing exercise, fix order of parameters to expectEqual' (#281) from cstyan/exercises:test-expect into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/281
2025-08-24 15:08:32 +02:00
Chris Boesch a46db7e0e8 Merge branch 'main' into test-expect 2025-08-24 14:59:26 +02:00
Chris Boesch 564ea3405d Merge pull request 'fixed typo and broken link' (#296) from readme into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/296
2025-08-24 14:54:05 +02:00
Chris Boesch 16ec207471
fixed typo and broken link 2025-08-24 14:50:42 +02:00
Chris Boesch 04857aa75e Merge pull request 'fixed version numbers' (#295) from readme into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/295
2025-08-24 14:44:25 +02:00
Chris Boesch 6364087569
fixed version numbers 2025-08-24 14:42:03 +02:00
Chris Boesch ad32e402a5 Merge pull request 'pass -freference-trace to executed compile command' (#294) from SimonLSchlee/exercises:pass-reference-trace into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/294
2025-08-24 14:37:57 +02:00
Chris Boesch 470f695968 Merge branch 'main' into pass-reference-trace 2025-08-24 13:48:18 +02:00
Chris Boesch 5b3b0eb26b Merge pull request '[Exercise 019] fix: typo in example function, missing return type' (#290) from imomaliev/ziglings:chore/fix-019-function-description into main
Reviewed-on: https://codeberg.org/ziglings/exercises/pulls/290
2025-08-24 13:40:04 +02:00
Chris Boesch 0661d4fd48 Merge branch 'main' into chore/fix-019-function-description 2025-08-24 13:19:25 +02:00
Simon 'Sze' L. Schlee 02db832677 pass -freference-trace to executed compile command
Currently users executing `zig build` to run the exercises,
may encounter compiler output that tells them to use
`-freference-trace=[num]` to see more of the hidden
reference traces, so we should pass this parameter to
the zigling exercise being compiled, so that the learner
can provide this parameter like they would normally, when
using `zig build` directly in normal Zig programs.
2025-08-24 03:08:17 +02:00
Sardorbek Imomaliev 06e56be9c5 fix: 019 typo in example function, missing return type 2025-08-11 21:01:47 +01:00
Callum Styan f5d2c5124c for expectEqual the first param is expected
Signed-off-by: Callum Styan <callumstyan@gmail.com>
2025-07-13 17:02:50 -07:00
9 changed files with 52 additions and 21 deletions

View File

@ -12,10 +12,10 @@ the current Zig snapshot, setup a copy of Ziglings, and knows
common language building blocks (if/then/else, loops, and common language building blocks (if/then/else, loops, and
functions) is ready for Ziglings. functions) is ready for Ziglings.
Ziglings is intended to be completely self-contained. If you Zigling's excercises are self-contained. If you can't solve
can't solve an exercise from the information you've gleaned so an exercise from the information you've gleaned so far from
far from Ziglings, then the exercise probably needs some Ziglings, then the exercise probably needs some additional work.
additional work. Please file an issue! Please file an issue!
If an example doesn't match a description or if something is If an example doesn't match a description or if something is
unclear, please file an issue! unclear, please file an issue!
@ -52,6 +52,8 @@ If you run into an error in Ziglings caused by breaking changes
in the latest development build of Zig, that's a new bug in in the latest development build of Zig, that's a new bug in
Ziglings. Please file an issue...or make a pull request! Ziglings. Please file an issue...or make a pull request!
For the latter, also read "The Secrets” section.
## Formatting ## Formatting
@ -89,3 +91,23 @@ contribution for any other purpose.
If you want to peek at the secrets, take a look at the `patches/` If you want to peek at the secrets, take a look at the `patches/`
directory. directory.
Every Ziglings exercise contains mistakes on purpose.
To keep our automated tests happy, each exercise also
has a patch in `patches/healed` that “heals” it.
When you change an exercise, you will usually need to update
its patch too. Thats where our little helper Gollum comes in:
1. In the project root, create a folder called `answers/`
2. Put your solved version of the exercise file in there
3. Back in the root, run:
`./patches/gollum <exercise-number>`<br>
For example: `./patches/gollum 106`
This will generate a shiny new patch.
Double-check everything by asking the magical Eowyn:
`./patches/eowyn`<br>
If all tests pass: You are done!
Dont forget to commit the patch file.

View File

@ -25,10 +25,9 @@ language such as C.
Each exercise is self-contained and self-explained. However, Each exercise is self-contained and self-explained. However,
you're encouraged to also check out these Zig language resources you're encouraged to also check out these Zig language resources
for more detail: for more details:
* https://ziglang.org/learn/ * https://ziglang.org/learn/
* https://ziglearn.org/
* https://ziglang.org/documentation/master/ * https://ziglang.org/documentation/master/
* [Zig in Depth! (video series)](https://www.youtube.com/watch?v=MMtvGA1YhW4&list=PLtB7CL7EG7pCw7Xy1SQC53Gl8pI7aDg9t&pp=iAQB) * [Zig in Depth! (video series)](https://www.youtube.com/watch?v=MMtvGA1YhW4&list=PLtB7CL7EG7pCw7Xy1SQC53Gl8pI7aDg9t&pp=iAQB)
@ -45,7 +44,7 @@ Verify the installation and build number of `zig` like so:
``` ```
$ zig version $ zig version
0.15.0-dev.xxxx+xxxxxxxxx 0.16.0-dev.xxxx+xxxxxxxxx
``` ```
Clone this repository with Git: Clone this repository with Git:
@ -73,8 +72,8 @@ the appropriate tag.
The Zig language is under very active development. In order to be The Zig language is under very active development. In order to be
current, Ziglings tracks **development** builds of the Zig current, Ziglings tracks **development** builds of the Zig
compiler rather than versioned **release** builds. The last compiler rather than versioned **release** builds. The last
stable release was `0.14.1`, but Ziglings needs a dev build with stable release was `0.15.1`, but Ziglings needs a dev build with
pre-release version "0.15.0" and a build number at least as high pre-release version "0.16.0" and a build number at least as high
as that shown in the example version check above. as that shown in the example version check above.
It is likely that you'll download a build which is _greater_ than It is likely that you'll download a build which is _greater_ than
@ -87,6 +86,7 @@ that if you update one, you may need to also update the other.
### Version Changes ### Version Changes
* *2025-09-03* zig 0.16.0-dev.164 - changes in reader, see [#25077](https://github.com/ziglang/zig/pull/25077)
* *2025-08-15* zig 0.15.0-dev.1519 - changes in array list, see [#24801](https://github.com/ziglang/zig/pull/24801) * *2025-08-15* zig 0.15.0-dev.1519 - changes in array list, see [#24801](https://github.com/ziglang/zig/pull/24801)
* *2025-08-08* zig 0.15.0-dev.1380 - changes in build system, see [#24588](https://github.com/ziglang/zig/pull/24588) * *2025-08-08* zig 0.15.0-dev.1380 - changes in build system, see [#24588](https://github.com/ziglang/zig/pull/24588)
* *2025-07-22* zig 0.15.0-dev.1092 - various changes due to new I/O API, see [#24488](https://github.com/ziglang/zig/pull/24488) * *2025-07-22* zig 0.15.0-dev.1092 - various changes due to new I/O API, see [#24488](https://github.com/ziglang/zig/pull/24488)

View File

@ -15,7 +15,7 @@ const print = std.debug.print;
// 1) Getting Started // 1) Getting Started
// 2) Version Changes // 2) Version Changes
comptime { comptime {
const required_zig = "0.15.0-dev.1519"; const required_zig = "0.16.0-dev.164";
const current_zig = builtin.zig_version; const current_zig = builtin.zig_version;
const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable; const min_zig = std.SemanticVersion.parse(required_zig) catch unreachable;
if (current_zig.order(min_zig) == .lt) { if (current_zig.order(min_zig) == .lt) {
@ -276,8 +276,12 @@ pub fn build(b: *Build) !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){}; var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit(); defer _ = gpa.deinit();
const allocator = gpa.allocator(); const allocator = gpa.allocator();
const contents = try progress_file.readToEndAlloc(allocator, progress_file_size); const contents = try allocator.alloc(u8, progress_file_size);
defer allocator.free(contents); defer allocator.free(contents);
const bytes_read = try progress_file.read(contents);
if (bytes_read != progress_file_size) {
return error.UnexpectedEOF;
}
starting_exercise = try std.fmt.parseInt(u32, contents, 10); starting_exercise = try std.fmt.parseInt(u32, contents, 10);
} else |err| { } else |err| {
@ -508,6 +512,10 @@ const ZiglingStep = struct {
zig_args.append("-lc") catch @panic("OOM"); zig_args.append("-lc") catch @panic("OOM");
} }
if (b.reference_trace) |rt| {
zig_args.append(b.fmt("-freference-trace={}", .{rt})) catch @panic("OOM");
}
zig_args.append(b.pathFromRoot(path)) catch @panic("OOM"); zig_args.append(b.pathFromRoot(path)) catch @panic("OOM");
zig_args.append("--cache-dir") catch @panic("OOM"); zig_args.append("--cache-dir") catch @panic("OOM");
@ -562,7 +570,7 @@ const ZiglingStep = struct {
// Render compile errors at the bottom of the terminal. // Render compile errors at the bottom of the terminal.
// TODO: use the same ttyconf from the builder. // TODO: use the same ttyconf from the builder.
const ttyconf: std.io.tty.Config = if (use_color_escapes) const ttyconf: std.Io.tty.Config = if (use_color_escapes)
.escape_codes .escape_codes
else else
.no_color; .no_color;

View File

@ -3,7 +3,7 @@
// example that takes two parameters. As you can see, parameters // example that takes two parameters. As you can see, parameters
// are declared just like any other types ("name": "type"): // are declared just like any other types ("name": "type"):
// //
// fn myFunction(number: u8, is_lucky: bool) { // fn myFunction(number: u8, is_lucky: bool) void {
// ... // ...
// } // }
// //

View File

@ -58,7 +58,7 @@ test "add" {
// Another way to perform this test // Another way to perform this test
// is as follows: // is as follows:
try testing.expectEqual(add(41, 1), 42); try testing.expectEqual(42, add(41, 1));
// This time a test with the addition // This time a test with the addition
// of a negative number: // of a negative number:

View File

@ -63,8 +63,9 @@ pub fn main() !void {
} }
// to check if you actually write to the file, you can either, // to check if you actually write to the file, you can either,
// 1. open the file in your text editor, or // 1. open the file in your text editor, or
// 2. print the content of the file in the console with the following command // 2. print the content of the file in the console with one of these commands
// >> cat ./output/zigling.txt // Linux/macOS: >> cat ./output/zigling.txt
// Windows (CMD): >> type .\output\zigling.txt
// //
// //
// More on Creating files // More on Creating files

View File

@ -2,7 +2,7 @@
// Prerequisite : // Prerequisite :
// - exercise/106_files.zig, or // - exercise/106_files.zig, or
// - create a file {project_root}/output/zigling.txt // - create a file {project_root}/output/zigling.txt
// with content `It's zigling time!`(18 byte total) // with content `It's zigling time!`(18 bytes total)
// //
// Now there's no point in writing to a file if we don't read from it, am I right? // Now there's no point in writing to a file if we don't read from it, am I right?
// Let's write a program to read the content of the file that we just created. // Let's write a program to read the content of the file that we just created.

View File

@ -1,5 +1,5 @@
--- exercises/106_files.zig 2025-03-13 15:26:59.532367792 +0200 --- exercises/106_files.zig 2025-08-24 19:23:55.168565003 +0200
+++ answers/106_files.zig 2025-03-14 22:04:52.243435159 +0200 +++ answers/106_files.zig 2025-08-24 19:25:37.745597511 +0200
@@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
// by doing nothing // by doing nothing
// //

View File

@ -1,5 +1,5 @@
--- exercises/107_files2.zig 2025-03-13 15:26:59.532367792 +0200 --- exercises/107_files2.zig 2025-08-24 19:15:17.789371332 +0200
+++ answers/107_files2.zig 2025-03-14 22:08:35.167953736 +0200 +++ answers/107_files2.zig 2025-08-24 19:17:58.897538288 +0200
@@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
// initialize an array of u8 with all letter 'A' // initialize an array of u8 with all letter 'A'
// we need to pick the size of the array, 64 seems like a good number // we need to pick the size of the array, 64 seems like a good number