|
| 1 | +#!/bin/env bash |
| 2 | + |
| 3 | +# This tool generates the tests in spec/std/file/match-fast-glob_spec.cr |
| 4 | +# from https://github.com/oxc-project/fast-glob/blob/main/tests/test.rs |
| 5 | +# converted to Crystal |
| 6 | + |
| 7 | +set -euo pipefail |
| 8 | + |
| 9 | +target=spec/std/file/match-fast-glob_spec.cr |
| 10 | +URL="https://raw.githubusercontent.com/oxc-project/fast-glob/refs/heads/main/tests/test.rs" |
| 11 | + |
| 12 | +curl -L "$URL" | |
| 13 | +( |
| 14 | + echo ' |
| 15 | +# This file was automatically generated by running: |
| 16 | +# |
| 17 | +# scripts/generate_glob_specs.cr |
| 18 | +# |
| 19 | +# DO NOT EDIT |
| 20 | +' |
| 21 | + |
| 22 | +echo " |
| 23 | +# These tests are autogenerated from $URL |
| 24 | +# They are are collection of tests from bash and micromatch |
| 25 | +# https://github.com/micromatch/picomatch/blob/master/test/bash.js. |
| 26 | +" |
| 27 | + |
| 28 | + echo ' |
| 29 | +require "spec" |
| 30 | +
|
| 31 | +private def assert_file_matches(pattern, path : String, *, file = __FILE__, line = __LINE__) |
| 32 | + File.match?(pattern, path).should be_true, file: file, line: line |
| 33 | + File.match?(pattern, Path.posix(path)).should be_true, file: file, line: line |
| 34 | + File.match?(pattern, Path.posix(path).to_windows(mappings: false)).should be_true, file: file, line: line |
| 35 | +end |
| 36 | +
|
| 37 | +private def refute_file_matches(pattern, path : String, *, file = __FILE__, line = __LINE__) |
| 38 | + File.match?(pattern, path).should be_false, file: file, line: line |
| 39 | + File.match?(pattern, Path.posix(path)).should be_false, file: file, line: line |
| 40 | + File.match?(pattern, Path.posix(path).to_windows(mappings: false)).should be_false, file: file, line: line |
| 41 | +end |
| 42 | +' |
| 43 | + |
| 44 | + echo 'describe "File .match? bash tests" do' |
| 45 | + |
| 46 | + sed -E '1,5d' | |
| 47 | + sed '/let patterns/,/#\[test\]/d; s/fn not_paired_braces/end\n\nfn not_paired_braces/' | # drop complex patterns implementation |
| 48 | + sed '/fn fuzz_tests/,$d' | # drop complex fuzz tests implementation |
| 49 | + sed '/^\s*#\[/d' | |
| 50 | + sed -E 's/fn (.*)\(\) \{/it "\1" do/' | |
| 51 | + sed -E 's/\}$/end/' | |
| 52 | + sed -E 's|^\s*//|#|' | |
| 53 | + sed -E 's/assert!\(!glob_match\("(.*)", "(.*)"\)\);/refute_file_matches "\1", "\2"/' | |
| 54 | + sed -E 's/assert!\(glob_match\("(.*)", "(.*)"\)\);/assert_file_matches "\1", "\2"/' | |
| 55 | + # multiline assertions: |
| 56 | + sed -E 's/assert!\(glob_match\(/assert_file_matches(/' | |
| 57 | + sed -E 's/assert!\(!glob_match\(/refute_file_matches(/' | |
| 58 | + sed -E 's/\)\);/)/' | |
| 59 | + sed -E 's/let //' | |
| 60 | + sed -E 's/it "negation"/pending "negation"/' | # File.match? currently does not support negated patterns |
| 61 | + sed -E '/it "generic_input"/,/end$/d' # Generic input tests are specific to Rust types |
| 62 | + |
| 63 | + echo 'end' |
| 64 | +) > "$target" |
| 65 | + |
| 66 | +crystal tool format "$target" |
0 commit comments