From 7e9ba20ece1986654568b3810c36f66be0522a02 Mon Sep 17 00:00:00 2001 From: nk9 Date: Sat, 8 Oct 2022 12:42:02 +0100 Subject: [PATCH 1/8] Test suite justfile --- examples/test-suite.just | 185 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 185 insertions(+) create mode 100644 examples/test-suite.just diff --git a/examples/test-suite.just b/examples/test-suite.just new file mode 100644 index 0000000000..6ae9d0c2e8 --- /dev/null +++ b/examples/test-suite.just @@ -0,0 +1,185 @@ +set shell := ["sh", "-c"] +set windows-shell := ["powershell.exe", "-NoLogo", "-Command"] +set positional-arguments +set dotenv-load +set export + +tmpdir := `mktemp` +version := "0.2.7" +tardir := tmpdir / "awesomesauce-" + version +foo1 := / "tmp" +foo2_3 := "a/" +tarball := tardir + ".tar.gz" + +export RUST_BACKTRACE_2 := "1" +string-with-tab := "\t" +string-with-newline := "\n" +string-with-carriage-return := "\r" +string-with-double-quote := "\"" +string-with-slash := "\\" +string-with-no-newline := "\ +" + +# Newlines in variables +single := ' +hello +' + +double := " +goodbye +" +escapes := '\t\n\r\"\\' + + +shebang := if os() == 'windows' { + 'powershell.exe' +} else { + '/usr/bin/env pwsh' +} + +# this string will evaluate to `foo\nbar\n` +x := ''' + foo + bar +''' + +# this string will evaluate to `abc\n wuv\nbar\n` +y := """ + abc + wuv + xyz +""" + +serve: + touch {{tmpdir}}/file + +# This backtick evaluates the command `echo foo\necho bar\n`, which produces the value `foo\nbar\n`. +stuff := ``` + echo foo + echo bar + ``` + + +an_arch := trim(lowercase(justfile())) + arch() +trim_end := trim_end("99.99954% ") +home_dir := replace(env_var('HOME') / "yep", 'yep', '') +quoted := quote("some things beyond\"$()^%#@!|-+=_*&'`") +smartphone := trim_end_match('blah.txt', 'txt') +museum := trim_start_match(trim_start(trim_end_matches(' yep_blah.txt.txt', '.txt')), 'yep_') +water := trim_start_matches('ssssssoup.txt', 's') +congress := uppercase(os()) +path_1 := absolute_path('test') +path_2 := '/tmp/subcommittee.txt' +ext_z := extension(path_2) +exe_name := file_name(just_executable()) +a_stem := file_stem(path_2) +a_parent := parent_directory(path_2) +sans_ext := without_extension(path_2) +camera := join('tmp', 'dir1', 'dir2', path_2) +cleaned := clean('/tmp/blah/..///thing.txt') +id__path := '/tmp' / sha256('blah') / sha256_file(justfile()) +_another_var := env_var_or_default("HOME", justfile_directory()) +python := `which python` + +exists := if path_exists(just_executable()) =~ '^/User' { uuid() } else { 'yeah' } + +foo := if env_var("_") == "/usr/bin/env" { `touch /tmp/a_file` } else { "dummy-value" } +foo_b := if "hello" == "goodbye" { "xyz" } else { if "no" == "no" { "yep"} else { error("123") } } +foo_c := if "hello" == "goodbye" { + "xyz" +} else if "a" == "a" { + "abc" +} else { + "123" +} + +bar: + @echo {{foo}} + + +bar2 foo_stuff: + echo {{ if foo_stuff == "bar" { "hello" } else { "goodbye" } }} + +executable: + @echo The executable is at: {{just_executable()}} + + +rustfmt: + find {{invocation_directory()}} -name \*.rs -exec rustfmt {} \; + +test: + echo "{{home_dir}}" + + +linewise: + Write-Host "Hello, world!" + +serve2: + @echo "Starting server with database $DATABASE_ADDRESS on port $SERVER_PORT…" + +shebang: + #!{{shebang}} + $PSV = $PSVersionTable.PSVersion | % {"$_" -split "\." } + $psver = $PSV[0] + "." + $PSV[1] + if ($PSV[2].Length -lt 4) { + $psver += "." + $PSV[2] + " Core" + } else { + $psver += " Desktop" + } + echo "PowerShell $psver" + +@foo: + echo bar + +@test5 *args='': + bash -c 'while (( "$#" )); do echo - $1; shift; done' -- "$@" + +test2 $RUST_BACKTRACE="1": + # will print a stack trace if it crashes + cargo test + + +notify m="": + keybase chat send --topic-type "chat" --channel "upd(): {{m}}" + +# Sample project script 2 +script2 *ARGS: + {{ python }} script2.py {{ ARGS }} + +braces: + echo 'I {{{{LOVE}} curly braces!' + +braces2: + echo '{{'I {{LOVE}} curly braces!'}}' + +braces3: + echo 'I {{ "{{" }}LOVE}} curly braces!' + +foo2: + -cat foo + echo 'Done!' + +test3 target tests=path_1: + @echo 'Testing {{target}}:{{tests}}…' + ./test --tests {{tests}} {{target}} + +test4 triple=(an_arch + "-unknown-unknown") input=(an_arch / "input.dat"): + ./test {{triple}} + +variadic $VAR1_1 VAR2 VAR3 VAR4=("a") +$FLAGS='-q': foo2 braces + cargo test {{FLAGS}} + + +# Subsequent dependencies +# https://just.systems/man/en/chapter_37.html +a: + echo 'A!' + +b: a && c d + echo 'B!' + +c: + echo 'C!' + +d: + echo 'D!' \ No newline at end of file From 769da559e0f71731d5bdc556fd9030a9efd22437 Mon Sep 17 00:00:00 2001 From: nk9 Date: Sat, 8 Oct 2022 12:53:18 +0100 Subject: [PATCH 2/8] Add some missing functions/variables/features. --- examples/test-suite.just | 49 +++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/examples/test-suite.just b/examples/test-suite.just index 6ae9d0c2e8..983572eb1f 100644 --- a/examples/test-suite.just +++ b/examples/test-suite.just @@ -1,9 +1,20 @@ set shell := ["sh", "-c"] set windows-shell := ["powershell.exe", "-NoLogo", "-Command"] +set allow-duplicate-recipes set positional-arguments set dotenv-load set export +alias s := serve + +bt := '0' + +export RUST_BACKTRACE_1 := bt + +log := "warn" + +export JUST_LOG := log + tmpdir := `mktemp` version := "0.2.7" tardir := tmpdir / "awesomesauce-" + version @@ -30,13 +41,6 @@ goodbye " escapes := '\t\n\r\"\\' - -shebang := if os() == 'windows' { - 'powershell.exe' -} else { - '/usr/bin/env pwsh' -} - # this string will evaluate to `foo\nbar\n` x := ''' foo @@ -50,6 +54,11 @@ y := """ xyz """ +for: + for file in `ls .`; do \ + echo $file; \ + done + serve: touch {{tmpdir}}/file @@ -68,6 +77,7 @@ smartphone := trim_end_match('blah.txt', 'txt') museum := trim_start_match(trim_start(trim_end_matches(' yep_blah.txt.txt', '.txt')), 'yep_') water := trim_start_matches('ssssssoup.txt', 's') congress := uppercase(os()) +fam := os_family() path_1 := absolute_path('test') path_2 := '/tmp/subcommittee.txt' ext_z := extension(path_2) @@ -117,6 +127,13 @@ linewise: serve2: @echo "Starting server with database $DATABASE_ADDRESS on port $SERVER_PORT…" + +shebang := if os() == 'windows' { + 'powershell.exe' +} else { + '/usr/bin/env pwsh' +} + shebang: #!{{shebang}} $PSV = $PSVersionTable.PSVersion | % {"$_" -split "\." } @@ -149,14 +166,14 @@ script2 *ARGS: braces: echo 'I {{{{LOVE}} curly braces!' -braces2: +_braces2: echo '{{'I {{LOVE}} curly braces!'}}' -braces3: +_braces3: echo 'I {{ "{{" }}LOVE}} curly braces!' foo2: - -cat foo + -@cat foo echo 'Done!' test3 target tests=path_1: @@ -169,17 +186,23 @@ test4 triple=(an_arch + "-unknown-unknown") input=(an_arch / "input.dat"): variadic $VAR1_1 VAR2 VAR3 VAR4=("a") +$FLAGS='-q': foo2 braces cargo test {{FLAGS}} +time: + @-date +"%H:%S" + @echo "finished" # Subsequent dependencies # https://just.systems/man/en/chapter_37.html +# To test, run `$ just -f test-suite.just b` a: echo 'A!' -b: a && c d - echo 'B!' +b: a && d + echo 'B start!' + just -f {{justfile()}} c + echo 'B end!' c: echo 'C!' d: - echo 'D!' \ No newline at end of file + echo 'D!' From 1077ec8bcbe2292c696819589a292623b82c36bb Mon Sep 17 00:00:00 2001 From: nk9 Date: Sat, 8 Oct 2022 13:47:02 +0100 Subject: [PATCH 3/8] Add line prefix to the grammar. --- GRAMMAR.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/GRAMMAR.md b/GRAMMAR.md index 6bb4afc12e..94936e9613 100644 --- a/GRAMMAR.md +++ b/GRAMMAR.md @@ -22,6 +22,7 @@ RAW_STRING = '[^']*' INDENTED_RAW_STRING = '''[^(''')]*''' STRING = "[^"]*" # also processes \n \r \t \" \\ escapes INDENTED_STRING = """[^("""]*""" # also processes \n \r \t \" \\ escapes +LINE_PREFIX = `@|-|@-|-@` TEXT = recipe text, only matches in a recipe body ``` @@ -105,7 +106,7 @@ dependency : NAME body : INDENT line+ DEDENT -line : LINE (TEXT | interpolation)+ NEWLINE +line : LINE LINE_PREFIX (TEXT | interpolation)+ NEWLINE | NEWLINE interpolation : '{{' expression '}}' From b042726a9610f3cd7fb5838bfe5f137f72e94639 Mon Sep 17 00:00:00 2001 From: nk9 Date: Sat, 8 Oct 2022 13:52:17 +0100 Subject: [PATCH 4/8] Add recipe line with lone - --- examples/test-suite.just | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/test-suite.just b/examples/test-suite.just index 983572eb1f..d42091d997 100644 --- a/examples/test-suite.just +++ b/examples/test-suite.just @@ -188,6 +188,7 @@ variadic $VAR1_1 VAR2 VAR3 VAR4=("a") +$FLAGS='-q': foo2 braces time: @-date +"%H:%S" + -cat /tmp/nonexistant_file.txt @echo "finished" # Subsequent dependencies From 477d0cbac9fd586e42b0a0050e9fa7d349256ea3 Mon Sep 17 00:00:00 2001 From: nk9 Date: Sat, 8 Oct 2022 13:53:10 +0100 Subject: [PATCH 5/8] Mark line prefix as optional in grammar. --- GRAMMAR.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRAMMAR.md b/GRAMMAR.md index 94936e9613..d6990e520f 100644 --- a/GRAMMAR.md +++ b/GRAMMAR.md @@ -106,7 +106,7 @@ dependency : NAME body : INDENT line+ DEDENT -line : LINE LINE_PREFIX (TEXT | interpolation)+ NEWLINE +line : LINE LINE_PREFIX? (TEXT | interpolation)+ NEWLINE | NEWLINE interpolation : '{{' expression '}}' From 145f57c2c58e0ae6a19d8bc651992f90f2b52212 Mon Sep 17 00:00:00 2001 From: nk9 Date: Sat, 8 Oct 2022 14:44:42 +0100 Subject: [PATCH 6/8] Add parens to variable declaration and a multi-line recipe with incidental leading hyphens --- examples/test-suite.just | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/test-suite.just b/examples/test-suite.just index d42091d997..5921cc4f24 100644 --- a/examples/test-suite.just +++ b/examples/test-suite.just @@ -13,7 +13,7 @@ export RUST_BACKTRACE_1 := bt log := "warn" -export JUST_LOG := log +export JUST_LOG := (log + "ing" + `grep loop /etc/networks | cut -f2`) tmpdir := `mktemp` version := "0.2.7" @@ -191,6 +191,11 @@ time: -cat /tmp/nonexistant_file.txt @echo "finished" +justwords: + grep just \ + --text /usr/share/dict/words \ + > /tmp/justwords + # Subsequent dependencies # https://just.systems/man/en/chapter_37.html # To test, run `$ just -f test-suite.just b` From a839c3f0b94b6a86baf2062447700ba87e334e2f Mon Sep 17 00:00:00 2001 From: nk9 Date: Sat, 8 Oct 2022 14:12:46 +0100 Subject: [PATCH 7/8] Correct grammar to account for greedy regex patterns. --- GRAMMAR.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GRAMMAR.md b/GRAMMAR.md index d6990e520f..c32cb6a9e4 100644 --- a/GRAMMAR.md +++ b/GRAMMAR.md @@ -22,7 +22,7 @@ RAW_STRING = '[^']*' INDENTED_RAW_STRING = '''[^(''')]*''' STRING = "[^"]*" # also processes \n \r \t \" \\ escapes INDENTED_STRING = """[^("""]*""" # also processes \n \r \t \" \\ escapes -LINE_PREFIX = `@|-|@-|-@` +LINE_PREFIX = @-|-@|@|- TEXT = recipe text, only matches in a recipe body ``` From 01d64350cd28edfd7af918664fd1dc1b5dc7cc90 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Sat, 8 Oct 2022 13:45:13 -0700 Subject: [PATCH 8/8] =?UTF-8?q?test-suite.just=20=E2=86=92=20kitchen-sink.?= =?UTF-8?q?just?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/{test-suite.just => kitchen-sink.just} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{test-suite.just => kitchen-sink.just} (100%) diff --git a/examples/test-suite.just b/examples/kitchen-sink.just similarity index 100% rename from examples/test-suite.just rename to examples/kitchen-sink.just