|
| 1 | +import { readdirSync, readFileSync } from "node:fs"; |
| 2 | +import { join } from "node:path"; |
| 3 | + |
| 4 | +const fixturesDir = join(import.meta.dirname, "../fixtures"); |
| 5 | + |
| 6 | +const readFixture = (name: string) => readFileSync(join(fixturesDir, "bench", name), "utf8"); |
| 7 | + |
| 8 | +function readDir(subdir: string, ext: string): string[] { |
| 9 | + const dir = join(fixturesDir, subdir); |
| 10 | + const out: string[] = []; |
| 11 | + try { |
| 12 | + for (const f of readdirSync(dir)) { |
| 13 | + if (f.endsWith(ext)) out.push(readFileSync(join(dir, f), "utf8")); |
| 14 | + } |
| 15 | + } catch {} |
| 16 | + return out; |
| 17 | +} |
| 18 | + |
| 19 | +export const short = [ |
| 20 | + "echo hello", |
| 21 | + "program -short --long args", |
| 22 | + "npm run script", |
| 23 | + "pnpm install", |
| 24 | + "node script.js", |
| 25 | + "tsx ./main.ts", |
| 26 | + "bun test", |
| 27 | + "eslint .", |
| 28 | + "program -x && exec -y -- program2 -z", |
| 29 | + "cross-env NODE_ENV=production node -r pkg/config ./script.js", |
| 30 | + "dotenv -e .env3 -v VARIABLE=somevalue -- program", |
| 31 | + "npx --package @scope/pkg@0.6.0 --package pkg -- curl", |
| 32 | + "pnpm --silent run program script.js", |
| 33 | + "c8 --reporter=lcov --reporter text node --test --test-reporter=@org/rep", |
| 34 | + "NODE_ENV=production cross-env -- program --cache", |
| 35 | + "yarn --cwd components vitest -c vitest.components.config.ts", |
| 36 | + "changeset version && node ./scripts/deps/update-example-versions.js && pnpm install --no-frozen-lockfile && pnpm run format", |
| 37 | + 'turbo run build --filter=astro --filter=create-astro --filter="@astrojs/*"', |
| 38 | + "biome ci --formatter-enabled=false --enforce-assist=false --reporter=github && eslint . --concurrency=auto && knip", |
| 39 | + 'if test "$NODE_ENV" = "production" ; then make install ; fi', |
| 40 | + 'f() { vite build "$@" || (echo content; exit 1;) }; f', |
| 41 | + "var=$(node ./script.js)", |
| 42 | + "var=`node ./script.js`;var=`node ./require.js`", |
| 43 | + '#!/bin/sh\n. "$(dirname "$0")/_/husky.sh"\nnpx lint-staged', |
| 44 | + 'for S in "s"; do\n\tnpx rc@0.6.0\n\tnpx @scope/rc@0.6.0\ndone', |
| 45 | + "NODE_OPTIONS='--require pkg-a --require pkg-b' program", |
| 46 | +]; |
| 47 | + |
| 48 | +export const advanced = [ |
| 49 | + "for (( c=1; c<=5; c++ )); do echo $c; done", |
| 50 | + "select i in 1 2 3; do echo $i; done", |
| 51 | + '[[ "$lsb_dist" != "Ubuntu" || "$ver" < "14.04" ]]', |
| 52 | + "case a in a) echo A ;& *) echo star ;; esac", |
| 53 | + 'echo $"hello world"', |
| 54 | + 'declare -A map\nmap[key]="value"\necho "${map[key]}"', |
| 55 | + 'if [[ $(cat $file) =~ $regex ]]; then\n version="${BASH_REMATCH[1]}"\nfi', |
| 56 | + "node --maxWorkers=\"$(node -e 'process.stdout.write(os.cpus().length.toString())')\"", |
| 57 | + '[ "$CF_PAGES" = "1" ] && find dist -mindepth 2 -type f -name \'index.html\' -exec bash -c \'f="$1"; d=$(dirname "$f"); bn=$(basename "$d"); mv -v "$f" "$d/../$bn.html"\' _ {} \\; || true', |
| 58 | + 'caddy run --config - <<< \'{"apps":{"http":{"servers":{"srv0":{"listen":[":8003"]}}}}}\'', |
| 59 | + 'pnpm exec "cat package.json | jq -r \'\\\"\\\\(.name)@\\\\(.version)\\\"\'" | sort', |
| 60 | + "echo data | tee >(grep pattern > matches.txt) >(wc -l > count.txt) > /dev/null", |
| 61 | + "wc -c <(echo abc && echo def)", |
| 62 | + 'case "$Z" in\n ab*|cd*) ef ;;\nesac', |
| 63 | +]; |
| 64 | + |
| 65 | +export const installers = readDir("installers", ".sh"); |
| 66 | + |
| 67 | +export const large = readDir("large", ".sh"); |
| 68 | + |
| 69 | +export const specialized: [string, string[]][] = [ |
| 70 | + ["word-parts", [readFixture("word-parts.sh")]], |
| 71 | + ["param-expansion", [readFixture("param-expansion.sh")]], |
| 72 | + ["arithmetic", [readFixture("arithmetic.sh")]], |
| 73 | + ["test-expressions", [readFixture("test-expressions.sh")]], |
| 74 | + ["heredoc-expansion", [readFixture("heredoc-expansion.sh")]], |
| 75 | + ["assignments", [readFixture("assignments.sh")]], |
| 76 | + ["dedicated-nodes", [readFixture("dedicated-nodes.sh")]], |
| 77 | +]; |
0 commit comments