| author | |
| committer | |
| log | f0711a7e22d94c87706a83c255e41f1821bdac92 |
| tree | dd5011ad876ad090c433d2331624124fd5ce657a |
| parent | f1bb7611d250bae8a3c7a217387c74a0061e2f77 |
5 files changed, 34 insertions(+), 2 deletions(-)
build.zig+12| ... | @@ -22,4 +22,16 @@ pub fn build(b: *std.Build) void { | ... | @@ -22,4 +22,16 @@ pub fn build(b: *std.Build) void { |
| 22 | 22 | ||
| 23 | const run_step = b.step("run", "Run the app"); | 23 | const run_step = b.step("run", "Run the app"); |
| 24 | run_step.dependOn(&run_cmd.step); | 24 | run_step.dependOn(&run_cmd.step); |
| 25 | |||
| 26 | const tests = b.addTest(.{ | ||
| 27 | .root_source_file = b.path("test.zig"), | ||
| 28 | .target = target, | ||
| 29 | .optimize = mode, | ||
| 30 | }); | ||
| 31 | deps.addAllTo(tests); | ||
| 32 | |||
| 33 | const test_step = b.step("test", "Run all library tests"); | ||
| 34 | const tests_run = b.addRunArtifact(tests); | ||
| 35 | tests_run.has_side_effects = true; | ||
| 36 | test_step.dependOn(&tests_run.step); | ||
| 25 | } | 37 | } |
licenses.txt+1| ... | @@ -1,5 +1,6 @@ | ... | @@ -1,5 +1,6 @@ |
| 1 | MIT: | 1 | MIT: |
| 2 | = https://spdx.org/licenses/MIT | 2 | = https://spdx.org/licenses/MIT |
| 3 | - This | 3 | - This |
| 4 | - git https://github.com/nektro/zig-expect | ||
| 4 | - git https://github.com/nektro/zig-leven | 5 | - git https://github.com/nektro/zig-leven |
| 5 | - git https://github.com/nektro/zig-licenses-text | 6 | - git https://github.com/nektro/zig-licenses-text |
src/lib.zig-2| ... | @@ -14,7 +14,6 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 { | ... | @@ -14,7 +14,6 @@ pub fn detect(alloc: std.mem.Allocator, license_src: []const u8) ![]const u8 { |
| 14 | ind = i; | 14 | ind = i; |
| 15 | } | 15 | } |
| 16 | } | 16 | } |
| 17 | |||
| 18 | return licenses.spdx[ind.?][0]; | 17 | return licenses.spdx[ind.?][0]; |
| 19 | } | 18 | } |
| 20 | 19 | ||
| ... | @@ -23,7 +22,6 @@ pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 { | ... | @@ -23,7 +22,6 @@ pub fn detectInDir(alloc: std.mem.Allocator, dir: std.fs.Dir) !?[]const u8 { |
| 23 | (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse | 22 | (try testLicenseFile(alloc, dir, "LICENSE.md")) orelse |
| 24 | (try testLicenseFile(alloc, dir, "LICENSE.txt")) orelse | 23 | (try testLicenseFile(alloc, dir, "LICENSE.txt")) orelse |
| 25 | return null; | 24 | return null; |
| 26 | |||
| 27 | defer alloc.free(b); | 25 | defer alloc.free(b); |
| 28 | return try detect(alloc, b); | 26 | return try detect(alloc, b); |
| 29 | } | 27 | } |
test.zig created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const detect = @import("detect-license"); | ||
| 3 | const expect = @import("expect").expect; | ||
| 4 | |||
| 5 | test { | ||
| 6 | std.testing.refAllDeclsRecursive(detect); | ||
| 7 | } | ||
| 8 | test { | ||
| 9 | const alloc = std.testing.allocator; | ||
| 10 | const src = @embedFile("./LICENSE"); | ||
| 11 | const license = try detect.detect(alloc, src); | ||
| 12 | try expect(license).toEqualString("MIT"); | ||
| 13 | } | ||
| 14 | test { | ||
| 15 | const alloc = std.testing.allocator; | ||
| 16 | const dir = std.fs.cwd(); | ||
| 17 | const license = try detect.detectInDir(alloc, dir); | ||
| 18 | try expect(license).toEqualString("MIT"); | ||
| 19 | } | ||
zig.mod+2| ... | @@ -6,3 +6,5 @@ description: Given an input text guess which SPDX license it most likely is an i | ... | @@ -6,3 +6,5 @@ description: Given an input text guess which SPDX license it most likely is an i |
| 6 | dependencies: | 6 | dependencies: |
| 7 | - src: git https://github.com/nektro/zig-licenses-text | 7 | - src: git https://github.com/nektro/zig-licenses-text |
| 8 | - src: git https://github.com/nektro/zig-leven | 8 | - src: git https://github.com/nektro/zig-leven |
| 9 | root_dependencies: | ||
| 10 | - src: git https://github.com/nektro/zig-expect |