3434
3535# Test default (std) template
3636
37+ test_std () {
38+ local pkg=$1 ; local mod=$2 ; local exe=${3:- $1 }
39+ test_exp -f $pkg /Main.lean
40+ test_exp -f $pkg /$mod .lean
41+ test_exp -f $pkg /$mod /Basic.lean
42+ test_run -d $pkg exe $exe
43+ test_exp -f $pkg /.lake/build/lib/lean/$mod .olean
44+ }
45+
3746echo " # TEST: default template"
3847test_run new hello .lean
39- test_run -d hello exe hello
40- test -f hello/.lake/build/lib/lean/Hello.olean
48+ test_std hello Hello
4149rm -rf hello
4250test_run new hello .toml
43- test_run -d hello exe hello
44- test -f hello/.lake/build/lib/lean/Hello.olean
51+ test_std hello Hello
4552rm -rf hello
4653
4754# Test exe template
4855
56+ test_exe () {
57+ local pkg=$1 ; local mod=${2:- $1 } ; local exe=${3:- $1 }
58+ test_exp ! -d $pkg /$mod
59+ test_exp -f $pkg /Main.lean
60+ test_run -d $pkg exe $exe
61+ }
62+
4963echo " # TEST: exe template"
5064test_run new hello exe.lean
51- test -f hello/Main.lean
52- test_run -d hello exe hello
65+ test_exe hello Hello
5366rm -rf hello
5467test_run new hello exe.toml
55- test -f hello/Main.lean
56- test_run -d hello exe hello
68+ test_exe hello Hello
5769rm -rf hello
5870
5971# Test lib template
6072
73+ test_lib () {
74+ local pkg=$1 ; local mod=$2
75+ test_exp -f $pkg /$mod .lean
76+ test_exp -f $pkg /$mod /Basic.lean
77+ test_exp ! -f $pkg /Main.lean
78+ test_run -d $pkg build $mod
79+ test_exp -f $pkg /.lake/build/lib/lean/$mod .olean
80+ }
81+
6182echo " # TEST: lib template"
6283test_run new hello lib.lean
63- test_run -d hello build Hello
64- test -f hello/.lake/build/lib/lean/Hello.olean
84+ test_lib hello Hello
6585rm -rf hello
6686test_run new hello lib.toml
67- test_run -d hello build Hello
68- test -f hello/.lake/build/lib/lean/Hello.olean
87+ test_lib hello Hello
6988rm -rf hello
7089
7190# Test math & math-lax template
7291
7392test_math_tmp () {
74- tmp=$1 ; pkg=$2 ; mod=$3
93+ local tmp=$1 ; local pkg=$2 ; local mod=$3
7594 echo " # TEST: $tmp template"
7695 # Use `--offline` and remove the `require`,
7796 # since we do not wish to download mathlib during tests
7897 ELAN_TOOLCHAIN=" v4.0.0-test" test_run new $pkg $tmp .lean --offline
7998 sed_i ' /^require.*/{N;d;}' $pkg /lakefile.lean
8099 test_cmd_out " v4.0.0-test" cat $pkg /lean-toolchain
81- test_run -d $pkg build $mod
82- test -f $pkg /.lake/build/lib/lean/$mod .olean
100+ test_lib $pkg $mod
83101 rm -rf $pkg
84102 # Use `--offline` and remove the `require`,
85103 # since we do not wish to download mathlib during tests
86104 test_out " creating a new math package with a non-release Lean toolchain" \
87105 new $pkg $tmp .toml --offline
88106 sed_i ' /^\[\[require\]\]/{N;N;N;d;}' $pkg /lakefile.toml
89- test_run -d $pkg build $mod
90- test -f $pkg /.lake/build/lib/lean/$mod .olean
107+ test_lib $pkg $mod
91108}
92109
93110test_math_tmp math-lax qed-lax QedLax
@@ -99,39 +116,38 @@ echo "# TEST: init ."
99116mkdir hello
100117pushd hello
101118test_run init .
102- test_run exe hello
119+ test_std . Hello hello
103120popd
104121
105122# Test creating packages with uppercase names
106123# https://github.com/leanprover/lean4/issues/2540
107124
108125echo " # TEST: Uppercase package names"
109126test_run new HelloWorld
110- test_run -d HelloWorld exe helloworld
127+ test_std HelloWorld HelloWorld helloworld
111128
112129# Test creating multi-level packages with a `.`
113130
114131echo " # TEST: Packages with a ` .` "
115132test_run new hello.world
116- test_run -d hello-world exe hello-world
117- test -f hello-world/Hello/World/Basic.lean
133+ test_std hello-world Hello/World
118134
119135test_run new hello.exe exe
120- test_run -d hello-exe exe hello-exe
136+ test_exe hello-exe Hello
121137
122138# Test creating packages with a `-` (i.e., a non-identifier package name)
123139# https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/lake.20new.20lean-data
124140
125141echo " # TEST: Non-identifier package names"
126142test_run new lean-data
127- test_run -d lean-data exe lean-data
143+ test_std lean-data LeanData
128144
129145# Test creating packages starting with digits (i.e., a non-identifier library name)
130146# https://github.com/leanprover/lean4/issues/2865
131147
132148echo " # TEST: Non-identifier library names"
133149test_run new 123-hello
134- test_run -d 123-hello exe 123-hello
150+ test_std 123-hello 123Hello
135151
136152# Test creating packages with components that contain `.`s
137153# https://github.com/leanprover/lean4/issues/2999
@@ -140,23 +156,23 @@ test_run -d 123-hello exe 123-hello
140156if [ " $OSTYPE " != " cygwin" -a " $OSTYPE " != " msys" ]; then
141157 echo " # TEST: Escaped names"
142158 test_run new «A.B».«C.D»
143- test_run -d A-B-C-D exe a-b-c-d
159+ test_std A-B-C-D A.B/C.D a-b-c-d
144160fi
145161
146162# Test creating packages with keyword names
147163# https://github.com/leanprover/lake/issues/128
148164
149165echo " # TEST: Keyword names"
150166test_run new meta
151- test_run -d meta exe meta
167+ test_std meta Meta
152168
153169# Test `init` with name
154170
155171echo " # TEST: init <name>"
156172mkdir hello_world
157173pushd hello_world
158174test_run init hello_world exe
159- test_run exe hello_world
175+ test_exe . HelloWorld hello_world
160176popd
161177
162178# Test bare `init` on existing package (should error)
0 commit comments