From 4b32fb5a84fe76a5a0e9cc023d91ae0c42fcb60a Mon Sep 17 00:00:00 2001 From: nojaf Date: Wed, 21 Jan 2026 11:23:08 +0100 Subject: [PATCH] Split rewatch tests --- rewatch/tests/clean.sh | 157 --------------- .../tests/clean/01-clean-single-project.sh | 49 +++++ .../tests/clean/02-clean-dev-dependencies.sh | 39 ++++ rewatch/tests/clean/03-clean-node-modules.sh | 39 ++++ .../04-clean-rebuild-no-compiler-update.sh | 42 ++++ rewatch/tests/compile.sh | 188 ------------------ rewatch/tests/compile/01-basic-compile.sh | 34 ++++ .../tests/compile/02-standalone-package.sh | 21 ++ rewatch/tests/compile/03-rename-file.sh | 28 +++ .../compile/04-rename-file-internal-dep.sh | 26 +++ .../tests/compile/05-rename-file-namespace.sh | 26 +++ .../tests/compile/06-rename-interface-file.sh | 26 +++ .../compile/07-rename-file-with-interface.sh | 26 +++ rewatch/tests/compile/08-remove-file.sh | 26 +++ rewatch/tests/compile/09-dependency-cycle.sh | 26 +++ .../tests/compile/10-duplicate-module-name.sh | 28 +++ .../11-dev-dependency-non-dev-source.sh | 28 +++ .../compile/12-compile-dev-dependencies.sh | 35 ++++ .../compile/13-no-infinite-loop-with-cycle.sh | 13 ++ .../tests/compile/14-no-testrepo-changes.sh | 17 ++ rewatch/tests/compile/15-no-new-files.sh | 20 ++ .../tests/compile/16-snapshots-unchanged.sh | 21 ++ rewatch/tests/compiler-args.sh | 60 ------ .../01-compiler-args-cwd-invariant.sh | 37 ++++ .../02-warnings-in-parser-and-compiler.sh | 27 +++ .../01-invalid-experimental-key.sh} | 5 +- rewatch/tests/experimental.sh | 125 ------------ .../01-experimental-features-emit.sh | 40 ++++ .../02-experimental-features-parse-error.sh | 43 ++++ .../03-watch-invalid-experimental.sh | 50 +++++ rewatch/tests/format.sh | 59 ------ rewatch/tests/format/01-format-all-files.sh | 20 ++ rewatch/tests/format/02-format-single-file.sh | 18 ++ rewatch/tests/format/03-format-stdin.sh | 16 ++ .../tests/format/04-format-current-project.sh | 19 ++ .../01-lock-when-watching.sh} | 8 +- .../dev-dependency-used-by-non-dev-source.txt | 4 +- .../rename-file-internal-dep-namespace.txt | 6 +- .../snapshots/rename-file-internal-dep.txt | 4 +- .../snapshots/rename-file-with-interface.txt | 2 +- .../tests/snapshots/rename-interface-file.txt | 2 +- .../{suffix.sh => suffix/01-custom-suffix.sh} | 6 +- rewatch/tests/suite.sh | 54 ++++- .../{watch.sh => watch/01-watch-recompile.sh} | 8 +- 44 files changed, 918 insertions(+), 610 deletions(-) delete mode 100755 rewatch/tests/clean.sh create mode 100755 rewatch/tests/clean/01-clean-single-project.sh create mode 100755 rewatch/tests/clean/02-clean-dev-dependencies.sh create mode 100755 rewatch/tests/clean/03-clean-node-modules.sh create mode 100755 rewatch/tests/clean/04-clean-rebuild-no-compiler-update.sh delete mode 100755 rewatch/tests/compile.sh create mode 100755 rewatch/tests/compile/01-basic-compile.sh create mode 100755 rewatch/tests/compile/02-standalone-package.sh create mode 100755 rewatch/tests/compile/03-rename-file.sh create mode 100755 rewatch/tests/compile/04-rename-file-internal-dep.sh create mode 100755 rewatch/tests/compile/05-rename-file-namespace.sh create mode 100755 rewatch/tests/compile/06-rename-interface-file.sh create mode 100755 rewatch/tests/compile/07-rename-file-with-interface.sh create mode 100755 rewatch/tests/compile/08-remove-file.sh create mode 100755 rewatch/tests/compile/09-dependency-cycle.sh create mode 100755 rewatch/tests/compile/10-duplicate-module-name.sh create mode 100755 rewatch/tests/compile/11-dev-dependency-non-dev-source.sh create mode 100755 rewatch/tests/compile/12-compile-dev-dependencies.sh create mode 100755 rewatch/tests/compile/13-no-infinite-loop-with-cycle.sh create mode 100755 rewatch/tests/compile/14-no-testrepo-changes.sh create mode 100755 rewatch/tests/compile/15-no-new-files.sh create mode 100755 rewatch/tests/compile/16-snapshots-unchanged.sh delete mode 100755 rewatch/tests/compiler-args.sh create mode 100755 rewatch/tests/compiler-args/01-compiler-args-cwd-invariant.sh create mode 100755 rewatch/tests/compiler-args/02-warnings-in-parser-and-compiler.sh rename rewatch/tests/{experimental-invalid.sh => experimental-invalid/01-invalid-experimental-key.sh} (95%) delete mode 100755 rewatch/tests/experimental.sh create mode 100755 rewatch/tests/experimental/01-experimental-features-emit.sh create mode 100755 rewatch/tests/experimental/02-experimental-features-parse-error.sh create mode 100755 rewatch/tests/experimental/03-watch-invalid-experimental.sh delete mode 100755 rewatch/tests/format.sh create mode 100755 rewatch/tests/format/01-format-all-files.sh create mode 100755 rewatch/tests/format/02-format-single-file.sh create mode 100755 rewatch/tests/format/03-format-stdin.sh create mode 100755 rewatch/tests/format/04-format-current-project.sh rename rewatch/tests/{lock.sh => lock/01-lock-when-watching.sh} (91%) rename rewatch/tests/{suffix.sh => suffix/01-custom-suffix.sh} (94%) rename rewatch/tests/{watch.sh => watch/01-watch-recompile.sh} (94%) diff --git a/rewatch/tests/clean.sh b/rewatch/tests/clean.sh deleted file mode 100755 index 217be8a6071..00000000000 --- a/rewatch/tests/clean.sh +++ /dev/null @@ -1,157 +0,0 @@ -#!/bin/bash -cd $(dirname $0) -source "./utils.sh" -cd ../testrepo - -bold "Test: It should clean a single project" - -# First we build the entire monorepo -error_output=$(rewatch build 2>&1) -if [ $? -eq 0 ]; -then - success "Built monorepo" -else - error "Error building monorepo" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -# Then we clean a single project -error_output=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" clean 2>&1) -clean_status=$? -if [ $clean_status -ne 0 ]; -then - error "Error cleaning current project file-casing" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -# Count compiled files in the cleaned project -project_compiled_files=$(find packages/file-casing -type f -name '*.mjs' | wc -l | tr -d '[:space:]') -if [ "$project_compiled_files" -eq 0 ]; -then - success "file-casing cleaned" -else - error "Expected 0 .mjs files in file-casing after clean, got $project_compiled_files" - printf "%s\n" "$error_output" - exit 1 -fi - -# Ensure other project files were not cleaned -other_project_compiled_files=$(find packages/new-namespace -type f -name '*.mjs' | wc -l | tr -d '[:space:]') -if [ "$other_project_compiled_files" -gt 0 ]; -then - success "Didn't clean other project files" - git restore . -else - error "Expected files from new-namespace not to be cleaned" - exit 1 -fi - -bold "-should clean dev-dependencies of monorepo" - -# First we build the entire monorepo -error_output=$(rewatch build 2>&1) -if [ $? -eq 0 ]; -then - success "Built monorepo" -else - error "Error building monorepo" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -# Clean entire monorepo -error_output=$(rewatch clean 2>&1) -clean_status=$? -if [ $clean_status -ne 0 ]; -then - error "Error cleaning current project file-casing" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -# Count compiled files in dev-dependency project "pure-dev" -project_compiled_files=$(find packages/pure-dev -type f -name '*.mjs' | wc -l | tr -d '[:space:]') -if [ "$project_compiled_files" -eq 0 ]; -then - success "pure-dev cleaned" - git restore . -else - error "Expected 0 .mjs files in pure-dev after clean, got $project_compiled_files" - printf "%s\n" "$error_output" - exit 1 -fi - -bold "Test: It should clean dependencies from node_modules" - -# Build a package with external dependencies -error_output=$(cd packages/with-dev-deps && "$REWATCH_EXECUTABLE" build 2>&1) -if [ $? -eq 0 ]; -then - success "Built with-dev-deps" -else - error "Error building with-dev-deps" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -# Then we clean a single project -error_output=$(cd packages/with-dev-deps && "$REWATCH_EXECUTABLE" clean 2>&1) -clean_status=$? -if [ $clean_status -ne 0 ]; -then - error "Error cleaning current project file-casing" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -# Count compiled files in the cleaned project -compiler_assets=$(find node_modules/rescript-nodejs/lib/ocaml -type f -name '*.*' | wc -l | tr -d '[:space:]') -if [ $compiler_assets -eq 0 ]; -then - success "compiler assets from node_modules cleaned" - git restore . -else - error "Expected 0 files in node_modules/rescript-nodejs/lib/ocaml after clean, got $compiler_assets" - printf "%s\n" "$error_output" - exit 1 -fi - -# If we clean a package, we should not see a "Cleaned previous build due to compiler update" message. -# Clean the whole repo and rebuild, then ensure the compiler-update clean message is absent -bold "Test: Clean repo then rebuild should not log compiler update clean" - -# Clean repo -error_output=$(rewatch clean 2>&1) -if [ $? -eq 0 ]; -then - success "Repo Cleaned" -else - error "Error Cleaning Repo" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -# Rebuild with snapshot output -snapshot_file=../tests/snapshots/clean-rebuild.txt -rewatch build &> $snapshot_file -build_status=$? -normalize_paths $snapshot_file -if [ $build_status -eq 0 ]; -then - success "Repo Built" -else - error "Error Building Repo" - cat $snapshot_file >&2 - exit 1 -fi - -# Verify the undesired message is NOT present -if grep -q "Cleaned previous build due to compiler update" $snapshot_file; then - error "Unexpected compiler-update clean message present in rebuild logs" - cat $snapshot_file >&2 - exit 1 -else - success "No compiler-update clean message present after explicit clean" -fi diff --git a/rewatch/tests/clean/01-clean-single-project.sh b/rewatch/tests/clean/01-clean-single-project.sh new file mode 100755 index 00000000000..7d5aba613da --- /dev/null +++ b/rewatch/tests/clean/01-clean-single-project.sh @@ -0,0 +1,49 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should clean a single project" + +# First we build the entire monorepo +error_output=$(rewatch build 2>&1) +if [ $? -eq 0 ]; +then + success "Built monorepo" +else + error "Error building monorepo" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Then we clean a single project +error_output=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" clean 2>&1) +clean_status=$? +if [ $clean_status -ne 0 ]; +then + error "Error cleaning current project file-casing" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Count compiled files in the cleaned project +project_compiled_files=$(find packages/file-casing -type f -name '*.mjs' | wc -l | tr -d '[:space:]') +if [ "$project_compiled_files" -eq 0 ]; +then + success "file-casing cleaned" +else + error "Expected 0 .mjs files in file-casing after clean, got $project_compiled_files" + printf "%s\n" "$error_output" + exit 1 +fi + +# Ensure other project files were not cleaned +other_project_compiled_files=$(find packages/new-namespace -type f -name '*.mjs' | wc -l | tr -d '[:space:]') +if [ "$other_project_compiled_files" -gt 0 ]; +then + success "Didn't clean other project files" + git restore . +else + error "Expected files from new-namespace not to be cleaned" + exit 1 +fi diff --git a/rewatch/tests/clean/02-clean-dev-dependencies.sh b/rewatch/tests/clean/02-clean-dev-dependencies.sh new file mode 100755 index 00000000000..2d039a9243d --- /dev/null +++ b/rewatch/tests/clean/02-clean-dev-dependencies.sh @@ -0,0 +1,39 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Should clean dev-dependencies of monorepo" + +# First we build the entire monorepo +error_output=$(rewatch build 2>&1) +if [ $? -eq 0 ]; +then + success "Built monorepo" +else + error "Error building monorepo" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Clean entire monorepo +error_output=$(rewatch clean 2>&1) +clean_status=$? +if [ $clean_status -ne 0 ]; +then + error "Error cleaning monorepo" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Count compiled files in dev-dependency project "pure-dev" +project_compiled_files=$(find packages/pure-dev -type f -name '*.mjs' | wc -l | tr -d '[:space:]') +if [ "$project_compiled_files" -eq 0 ]; +then + success "pure-dev cleaned" + git restore . +else + error "Expected 0 .mjs files in pure-dev after clean, got $project_compiled_files" + printf "%s\n" "$error_output" + exit 1 +fi diff --git a/rewatch/tests/clean/03-clean-node-modules.sh b/rewatch/tests/clean/03-clean-node-modules.sh new file mode 100755 index 00000000000..03630c4d55a --- /dev/null +++ b/rewatch/tests/clean/03-clean-node-modules.sh @@ -0,0 +1,39 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should clean dependencies from node_modules" + +# Build a package with external dependencies +error_output=$(cd packages/with-dev-deps && "$REWATCH_EXECUTABLE" build 2>&1) +if [ $? -eq 0 ]; +then + success "Built with-dev-deps" +else + error "Error building with-dev-deps" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Then we clean a single project +error_output=$(cd packages/with-dev-deps && "$REWATCH_EXECUTABLE" clean 2>&1) +clean_status=$? +if [ $clean_status -ne 0 ]; +then + error "Error cleaning with-dev-deps" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Count compiled files in the cleaned project +compiler_assets=$(find node_modules/rescript-nodejs/lib/ocaml -type f -name '*.*' | wc -l | tr -d '[:space:]') +if [ $compiler_assets -eq 0 ]; +then + success "compiler assets from node_modules cleaned" + git restore . +else + error "Expected 0 files in node_modules/rescript-nodejs/lib/ocaml after clean, got $compiler_assets" + printf "%s\n" "$error_output" + exit 1 +fi diff --git a/rewatch/tests/clean/04-clean-rebuild-no-compiler-update.sh b/rewatch/tests/clean/04-clean-rebuild-no-compiler-update.sh new file mode 100755 index 00000000000..e2b5108221c --- /dev/null +++ b/rewatch/tests/clean/04-clean-rebuild-no-compiler-update.sh @@ -0,0 +1,42 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +# If we clean a package, we should not see a "Cleaned previous build due to compiler update" message. +# Clean the whole repo and rebuild, then ensure the compiler-update clean message is absent +bold "Test: Clean repo then rebuild should not log compiler update clean" + +# Clean repo +error_output=$(rewatch clean 2>&1) +if [ $? -eq 0 ]; +then + success "Repo Cleaned" +else + error "Error Cleaning Repo" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Rebuild with snapshot output +snapshot_file=../tests/snapshots/clean-rebuild.txt +rewatch build &> $snapshot_file +build_status=$? +normalize_paths $snapshot_file +if [ $build_status -eq 0 ]; +then + success "Repo Built" +else + error "Error Building Repo" + cat $snapshot_file >&2 + exit 1 +fi + +# Verify the undesired message is NOT present +if grep -q "Cleaned previous build due to compiler update" $snapshot_file; then + error "Unexpected compiler-update clean message present in rebuild logs" + cat $snapshot_file >&2 + exit 1 +else + success "No compiler-update clean message present after explicit clean" +fi diff --git a/rewatch/tests/compile.sh b/rewatch/tests/compile.sh deleted file mode 100755 index 5890c79942f..00000000000 --- a/rewatch/tests/compile.sh +++ /dev/null @@ -1,188 +0,0 @@ -#!/bin/bash -cd $(dirname $0) -source "./utils.sh" -cd ../testrepo - -bold "Test: It should compile" - -error_output=$(rewatch clean 2>&1) -if [ $? -eq 0 ]; -then - success "Repo Cleaned" -else - error "Error Cleaning Repo" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -error_output=$(rewatch 2>&1) -if [ $? -eq 0 ]; -then - success "Repo Built" -else - error "Error Building Repo" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - - -if git diff --exit-code ./; -then - success "Testrepo has no changes" -else - error "Build has changed" - exit 1 -fi - -# Build from standalone package folder using `rescript build` -bold "Test: Standalone package can build via rescript from package folder" -pushd ./packages/standalone > /dev/null -error_output=$("$REWATCH_EXECUTABLE" build 2>&1) -if [ $? -eq 0 ]; -then - success "Standalone package built" -else - error "Error building standalone package" - printf "%s\n" "$error_output" >&2 - popd > /dev/null - exit 1 -fi -popd > /dev/null - -node ./packages/main/src/Main.mjs > ./packages/main/src/output.txt - -mv ./packages/main/src/Main.res ./packages/main/src/Main2.res -rewatch build &> ../tests/snapshots/rename-file.txt -normalize_paths ../tests/snapshots/rename-file.txt -mv ./packages/main/src/Main2.res ./packages/main/src/Main.res - -# Rename a file with a dependent - this should trigger an error -mv ./packages/main/src/InternalDep.res ./packages/main/src/InternalDep2.res -rewatch build &> ../tests/snapshots/rename-file-internal-dep.txt -normalize_paths ../tests/snapshots/rename-file-internal-dep.txt -mv ./packages/main/src/InternalDep2.res ./packages/main/src/InternalDep.res - -# Rename a file with a dependent in a namespaced package - this should trigger an error (regression) -mv ./packages/new-namespace/src/Other_module.res ./packages/new-namespace/src/Other_module2.res -rewatch build &> ../tests/snapshots/rename-file-internal-dep-namespace.txt -normalize_paths ../tests/snapshots/rename-file-internal-dep-namespace.txt -mv ./packages/new-namespace/src/Other_module2.res ./packages/new-namespace/src/Other_module.res - -rewatch build &> /dev/null -mv ./packages/main/src/ModuleWithInterface.resi ./packages/main/src/ModuleWithInterface2.resi -rewatch build &> ../tests/snapshots/rename-interface-file.txt -normalize_paths ../tests/snapshots/rename-interface-file.txt -mv ./packages/main/src/ModuleWithInterface2.resi ./packages/main/src/ModuleWithInterface.resi -rewatch build &> /dev/null -mv ./packages/main/src/ModuleWithInterface.res ./packages/main/src/ModuleWithInterface2.res -rewatch build &> ../tests/snapshots/rename-file-with-interface.txt -normalize_paths ../tests/snapshots/rename-file-with-interface.txt -mv ./packages/main/src/ModuleWithInterface2.res ./packages/main/src/ModuleWithInterface.res -rewatch build &> /dev/null - -# when deleting a file that other files depend on, the compile should fail -rm packages/dep02/src/Dep02.res -rewatch build &> ../tests/snapshots/remove-file.txt -normalize_paths ../tests/snapshots/remove-file.txt -git checkout -- packages/dep02/src/Dep02.res -rewatch build &> /dev/null - -# it should show an error when we have a dependency cycle -echo 'Dep01.log()' >> packages/new-namespace/src/NS_alias.res -rewatch build &> ../tests/snapshots/dependency-cycle.txt -normalize_paths ../tests/snapshots/dependency-cycle.txt -git checkout -- packages/new-namespace/src/NS_alias.res - -# it should show an error for duplicate module names -mkdir -p packages/main/src/dupe-a packages/main/src/dupe-b -echo 'let value = 1' > packages/main/src/dupe-a/DuplicateModule.res -echo 'let value = 2' > packages/main/src/dupe-b/DuplicateModule.res -rewatch build &> ../tests/snapshots/duplicate-module-name.txt -normalize_paths ../tests/snapshots/duplicate-module-name.txt -rm -rf packages/main/src/dupe-a packages/main/src/dupe-b - -# this should not compile because "@rescript/webapi" is part of dev-dependencies -# and FileToTest.res is not listed as "type":"dev" -echo 'open WebAPI' >> packages/with-dev-deps/src/FileToTest.res -rewatch build &> ../tests/snapshots/dev-dependency-used-by-non-dev-source.txt -normalize_paths ../tests/snapshots/dev-dependency-used-by-non-dev-source.txt -git checkout -- packages/with-dev-deps/src/FileToTest.res - -# it should compile dev dependencies -rewatch clean &> /dev/null -rewatch build &> /dev/null; -if [ $? -ne 0 ]; -then - error "Failed to compile dev dependencies" - exit 1 -fi - -file_count=$(find ./packages/with-dev-deps/test -name *.mjs | wc -l) -expected_file_count=1 -if [ "$file_count" -eq $expected_file_count ]; -then - success "Compiled dev dependencies successfully" -else - error "Expected $expected_file_count files to be compiled, found $file_count" - exit 1 -fi - -error_output=$(rewatch clean 2>&1 >/dev/null) -file_count=$(find ./packages/with-dev-deps -name *.mjs | wc -l) -if [ "$file_count" -eq 0 ]; -then - success "Cleaned dev dependencies successfully" -else - error "Expected 0 files remaining after cleaning, found $file_count" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - - -# it should not loop (we had an infinite loop when clean building with a cycle) -rewatch clean &> /dev/null -echo 'Dep01.log()' >> packages/new-namespace/src/NS_alias.res -git checkout -- packages/new-namespace/src/NS_alias.res -rewatch build &> /dev/null - -# make sure we don't have changes in the test repo -if git diff --exit-code ./; -then - success "Output is correct" -else - error "Output is incorrect" - exit 1 -fi - -# make sure there are no new files created by the build -# this could happen because of not cleaning up .mjs files -# after we rename files -new_files=$(git ls-files --others --exclude-standard ./) -if [[ $new_files = "" ]]; -then - success "No new files created" -else - error "❌ - New files created" - printf "${new_files}\n" - exit 1 -fi - -# see if the snapshots have changed -changed_snapshots=$(git ls-files --modified ../tests/snapshots) -if git diff --exit-code ../tests/snapshots &> /dev/null; -then - success "Snapshots are correct" -else - error "Snapshots are incorrect:" - # print filenames in the snapshot dir call bold with the filename - # and then cat their contents - printf "\n\n" - for file in $changed_snapshots; do - bold $file - # show diff of file vs contents in git - git diff $file $file - printf "\n\n" - done - - exit 1 -fi diff --git a/rewatch/tests/compile/01-basic-compile.sh b/rewatch/tests/compile/01-basic-compile.sh new file mode 100755 index 00000000000..31ff8951c18 --- /dev/null +++ b/rewatch/tests/compile/01-basic-compile.sh @@ -0,0 +1,34 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should compile" + +error_output=$(rewatch clean 2>&1) +if [ $? -eq 0 ]; +then + success "Repo Cleaned" +else + error "Error Cleaning Repo" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +error_output=$(rewatch 2>&1) +if [ $? -eq 0 ]; +then + success "Repo Built" +else + error "Error Building Repo" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +if git diff --exit-code ./; +then + success "Testrepo has no changes" +else + error "Build has changed" + exit 1 +fi diff --git a/rewatch/tests/compile/02-standalone-package.sh b/rewatch/tests/compile/02-standalone-package.sh new file mode 100755 index 00000000000..7b8dcda7e2f --- /dev/null +++ b/rewatch/tests/compile/02-standalone-package.sh @@ -0,0 +1,21 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Standalone package can build via rescript from package folder" + +rewatch clean &> /dev/null + +pushd ./packages/standalone > /dev/null +error_output=$("$REWATCH_EXECUTABLE" build 2>&1) +if [ $? -eq 0 ]; +then + success "Standalone package built" +else + error "Error building standalone package" + printf "%s\n" "$error_output" >&2 + popd > /dev/null + exit 1 +fi +popd > /dev/null diff --git a/rewatch/tests/compile/03-rename-file.sh b/rewatch/tests/compile/03-rename-file.sh new file mode 100755 index 00000000000..a8ce36c3182 --- /dev/null +++ b/rewatch/tests/compile/03-rename-file.sh @@ -0,0 +1,28 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Rename file should trigger error" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +node ./packages/main/src/Main.mjs > ./packages/main/src/output.txt + +mv ./packages/main/src/Main.res ./packages/main/src/Main2.res +rewatch build &> ../tests/snapshots/rename-file.txt +normalize_paths ../tests/snapshots/rename-file.txt +mv ./packages/main/src/Main2.res ./packages/main/src/Main.res + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/rename-file.txt &> /dev/null; +then + success "Rename file snapshot is correct" +else + error "Rename file snapshot changed" + git diff ../tests/snapshots/rename-file.txt + exit 1 +fi diff --git a/rewatch/tests/compile/04-rename-file-internal-dep.sh b/rewatch/tests/compile/04-rename-file-internal-dep.sh new file mode 100755 index 00000000000..d3e3203e8ad --- /dev/null +++ b/rewatch/tests/compile/04-rename-file-internal-dep.sh @@ -0,0 +1,26 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Rename a file with a dependent should trigger an error" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +mv ./packages/main/src/InternalDep.res ./packages/main/src/InternalDep2.res +rewatch build &> ../tests/snapshots/rename-file-internal-dep.txt +normalize_paths ../tests/snapshots/rename-file-internal-dep.txt +mv ./packages/main/src/InternalDep2.res ./packages/main/src/InternalDep.res + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/rename-file-internal-dep.txt &> /dev/null; +then + success "Rename file internal dep snapshot is correct" +else + error "Rename file internal dep snapshot changed" + git diff ../tests/snapshots/rename-file-internal-dep.txt + exit 1 +fi diff --git a/rewatch/tests/compile/05-rename-file-namespace.sh b/rewatch/tests/compile/05-rename-file-namespace.sh new file mode 100755 index 00000000000..a7a06622d66 --- /dev/null +++ b/rewatch/tests/compile/05-rename-file-namespace.sh @@ -0,0 +1,26 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Rename a file with a dependent in a namespaced package should trigger an error (regression)" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +mv ./packages/new-namespace/src/Other_module.res ./packages/new-namespace/src/Other_module2.res +rewatch build &> ../tests/snapshots/rename-file-internal-dep-namespace.txt +normalize_paths ../tests/snapshots/rename-file-internal-dep-namespace.txt +mv ./packages/new-namespace/src/Other_module2.res ./packages/new-namespace/src/Other_module.res + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/rename-file-internal-dep-namespace.txt &> /dev/null; +then + success "Rename file namespace snapshot is correct" +else + error "Rename file namespace snapshot changed" + git diff ../tests/snapshots/rename-file-internal-dep-namespace.txt + exit 1 +fi diff --git a/rewatch/tests/compile/06-rename-interface-file.sh b/rewatch/tests/compile/06-rename-interface-file.sh new file mode 100755 index 00000000000..1fe3145a76e --- /dev/null +++ b/rewatch/tests/compile/06-rename-interface-file.sh @@ -0,0 +1,26 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Rename interface file should trigger error" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +mv ./packages/main/src/ModuleWithInterface.resi ./packages/main/src/ModuleWithInterface2.resi +rewatch build &> ../tests/snapshots/rename-interface-file.txt +normalize_paths ../tests/snapshots/rename-interface-file.txt +mv ./packages/main/src/ModuleWithInterface2.resi ./packages/main/src/ModuleWithInterface.resi + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/rename-interface-file.txt &> /dev/null; +then + success "Rename interface file snapshot is correct" +else + error "Rename interface file snapshot changed" + git diff ../tests/snapshots/rename-interface-file.txt + exit 1 +fi diff --git a/rewatch/tests/compile/07-rename-file-with-interface.sh b/rewatch/tests/compile/07-rename-file-with-interface.sh new file mode 100755 index 00000000000..9b859261f80 --- /dev/null +++ b/rewatch/tests/compile/07-rename-file-with-interface.sh @@ -0,0 +1,26 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Rename file with interface should trigger error" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +mv ./packages/main/src/ModuleWithInterface.res ./packages/main/src/ModuleWithInterface2.res +rewatch build &> ../tests/snapshots/rename-file-with-interface.txt +normalize_paths ../tests/snapshots/rename-file-with-interface.txt +mv ./packages/main/src/ModuleWithInterface2.res ./packages/main/src/ModuleWithInterface.res + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/rename-file-with-interface.txt &> /dev/null; +then + success "Rename file with interface snapshot is correct" +else + error "Rename file with interface snapshot changed" + git diff ../tests/snapshots/rename-file-with-interface.txt + exit 1 +fi diff --git a/rewatch/tests/compile/08-remove-file.sh b/rewatch/tests/compile/08-remove-file.sh new file mode 100755 index 00000000000..b38d6a8fba7 --- /dev/null +++ b/rewatch/tests/compile/08-remove-file.sh @@ -0,0 +1,26 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Deleting a file that other files depend on should fail compile" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +rm packages/dep02/src/Dep02.res +rewatch build &> ../tests/snapshots/remove-file.txt +normalize_paths ../tests/snapshots/remove-file.txt +git checkout -- packages/dep02/src/Dep02.res + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/remove-file.txt &> /dev/null; +then + success "Remove file snapshot is correct" +else + error "Remove file snapshot changed" + git diff ../tests/snapshots/remove-file.txt + exit 1 +fi diff --git a/rewatch/tests/compile/09-dependency-cycle.sh b/rewatch/tests/compile/09-dependency-cycle.sh new file mode 100755 index 00000000000..7c287b81d69 --- /dev/null +++ b/rewatch/tests/compile/09-dependency-cycle.sh @@ -0,0 +1,26 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should show an error when we have a dependency cycle" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +echo 'Dep01.log()' >> packages/new-namespace/src/NS_alias.res +rewatch build &> ../tests/snapshots/dependency-cycle.txt +normalize_paths ../tests/snapshots/dependency-cycle.txt +git checkout -- packages/new-namespace/src/NS_alias.res + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/dependency-cycle.txt &> /dev/null; +then + success "Dependency cycle snapshot is correct" +else + error "Dependency cycle snapshot changed" + git diff ../tests/snapshots/dependency-cycle.txt + exit 1 +fi diff --git a/rewatch/tests/compile/10-duplicate-module-name.sh b/rewatch/tests/compile/10-duplicate-module-name.sh new file mode 100755 index 00000000000..38da1a24de5 --- /dev/null +++ b/rewatch/tests/compile/10-duplicate-module-name.sh @@ -0,0 +1,28 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should show an error for duplicate module names" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +mkdir -p packages/main/src/dupe-a packages/main/src/dupe-b +echo 'let value = 1' > packages/main/src/dupe-a/DuplicateModule.res +echo 'let value = 2' > packages/main/src/dupe-b/DuplicateModule.res +rewatch build &> ../tests/snapshots/duplicate-module-name.txt +normalize_paths ../tests/snapshots/duplicate-module-name.txt +rm -rf packages/main/src/dupe-a packages/main/src/dupe-b + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/duplicate-module-name.txt &> /dev/null; +then + success "Duplicate module name snapshot is correct" +else + error "Duplicate module name snapshot changed" + git diff ../tests/snapshots/duplicate-module-name.txt + exit 1 +fi diff --git a/rewatch/tests/compile/11-dev-dependency-non-dev-source.sh b/rewatch/tests/compile/11-dev-dependency-non-dev-source.sh new file mode 100755 index 00000000000..5fe5d7b7b8d --- /dev/null +++ b/rewatch/tests/compile/11-dev-dependency-non-dev-source.sh @@ -0,0 +1,28 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Dev dependency used by non-dev source should not compile" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +# This should not compile because "@rescript/webapi" is part of dev-dependencies +# and FileToTest.res is not listed as "type":"dev" +echo 'open WebAPI' >> packages/with-dev-deps/src/FileToTest.res +rewatch build &> ../tests/snapshots/dev-dependency-used-by-non-dev-source.txt +normalize_paths ../tests/snapshots/dev-dependency-used-by-non-dev-source.txt +git checkout -- packages/with-dev-deps/src/FileToTest.res + +rewatch build &> /dev/null + +# Check snapshot +if git diff --exit-code ../tests/snapshots/dev-dependency-used-by-non-dev-source.txt &> /dev/null; +then + success "Dev dependency non-dev source snapshot is correct" +else + error "Dev dependency non-dev source snapshot changed" + git diff ../tests/snapshots/dev-dependency-used-by-non-dev-source.txt + exit 1 +fi diff --git a/rewatch/tests/compile/12-compile-dev-dependencies.sh b/rewatch/tests/compile/12-compile-dev-dependencies.sh new file mode 100755 index 00000000000..38e5dab5ced --- /dev/null +++ b/rewatch/tests/compile/12-compile-dev-dependencies.sh @@ -0,0 +1,35 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should compile dev dependencies" + +rewatch clean &> /dev/null +rewatch build &> /dev/null +if [ $? -ne 0 ]; +then + error "Failed to compile dev dependencies" + exit 1 +fi + +file_count=$(find ./packages/with-dev-deps/test -name *.mjs | wc -l) +expected_file_count=1 +if [ "$file_count" -eq $expected_file_count ]; +then + success "Compiled dev dependencies successfully" +else + error "Expected $expected_file_count files to be compiled, found $file_count" + exit 1 +fi + +error_output=$(rewatch clean 2>&1 >/dev/null) +file_count=$(find ./packages/with-dev-deps -name *.mjs | wc -l) +if [ "$file_count" -eq 0 ]; +then + success "Cleaned dev dependencies successfully" +else + error "Expected 0 files remaining after cleaning, found $file_count" + printf "%s\n" "$error_output" >&2 + exit 1 +fi diff --git a/rewatch/tests/compile/13-no-infinite-loop-with-cycle.sh b/rewatch/tests/compile/13-no-infinite-loop-with-cycle.sh new file mode 100755 index 00000000000..cf369ae749c --- /dev/null +++ b/rewatch/tests/compile/13-no-infinite-loop-with-cycle.sh @@ -0,0 +1,13 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should not loop when clean building with a cycle" + +rewatch clean &> /dev/null +echo 'Dep01.log()' >> packages/new-namespace/src/NS_alias.res +git checkout -- packages/new-namespace/src/NS_alias.res +rewatch build &> /dev/null + +success "No infinite loop detected" diff --git a/rewatch/tests/compile/14-no-testrepo-changes.sh b/rewatch/tests/compile/14-no-testrepo-changes.sh new file mode 100755 index 00000000000..452431aeac6 --- /dev/null +++ b/rewatch/tests/compile/14-no-testrepo-changes.sh @@ -0,0 +1,17 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Make sure we don't have changes in the test repo" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +if git diff --exit-code ./; +then + success "Output is correct" +else + error "Output is incorrect" + exit 1 +fi diff --git a/rewatch/tests/compile/15-no-new-files.sh b/rewatch/tests/compile/15-no-new-files.sh new file mode 100755 index 00000000000..41a3e3a201d --- /dev/null +++ b/rewatch/tests/compile/15-no-new-files.sh @@ -0,0 +1,20 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: Make sure there are no new files created by the build" + +rewatch clean &> /dev/null +rewatch build &> /dev/null + +# This could happen because of not cleaning up .mjs files after we rename files +new_files=$(git ls-files --others --exclude-standard ./) +if [[ $new_files = "" ]]; +then + success "No new files created" +else + error "New files created" + printf "${new_files}\n" + exit 1 +fi diff --git a/rewatch/tests/compile/16-snapshots-unchanged.sh b/rewatch/tests/compile/16-snapshots-unchanged.sh new file mode 100755 index 00000000000..48ad7d91e6a --- /dev/null +++ b/rewatch/tests/compile/16-snapshots-unchanged.sh @@ -0,0 +1,21 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: See if the snapshots have changed" + +changed_snapshots=$(git ls-files --modified ../tests/snapshots) +if git diff --exit-code ../tests/snapshots &> /dev/null; +then + success "Snapshots are correct" +else + error "Snapshots are incorrect:" + printf "\n\n" + for file in $changed_snapshots; do + bold $file + git diff $file $file + printf "\n\n" + done + exit 1 +fi diff --git a/rewatch/tests/compiler-args.sh b/rewatch/tests/compiler-args.sh deleted file mode 100755 index c1c8ac85787..00000000000 --- a/rewatch/tests/compiler-args.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -cd $(dirname $0) -source "./utils.sh" -cd ../testrepo - -bold "Test: It should not matter where we grab the compiler-args for a file" -# Capture stdout for both invocations -stdout_root=$(rewatch compiler-args packages/file-casing/src/Consume.res 2>/dev/null) -stdout_pkg=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" compiler-args src/Consume.res 2>/dev/null) - -error_output=$(rewatch compiler-args packages/file-casing/src/Consume.res 2>&1) -if [ $? -ne 0 ]; then - error "Error grabbing compiler args for packages/file-casing/src/Consume.res" - printf "%s\n" "$error_output" >&2 - exit 1 -fi -error_output=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" compiler-args src/Consume.res 2>&1) -if [ $? -ne 0 ]; then - error "Error grabbing compiler args for src/Consume.res in packages/file-casing" - printf "%s\n" "$error_output" >&2 - exit 1 -fi - -# Compare the stdout of both runs; must be exactly identical -tmp1=$(mktemp); tmp2=$(mktemp) -trap 'rm -f "$tmp1" "$tmp2"' EXIT -printf "%s" "$stdout_root" > "$tmp1" -printf "%s" "$stdout_pkg" > "$tmp2" -if git diff --no-index --exit-code "$tmp1" "$tmp2" > /dev/null; then - success "compiler-args stdout is identical regardless of cwd" -else - error "compiler-args stdout differs depending on cwd" - echo "---- diff ----" - git diff --no-index "$tmp1" "$tmp2" || true - exit 1 -fi - -# Additional check: warnings/error flags should be present in both parser_args and compiler_args (using namespace-casing package) -bold "Test: warnings/error flags appear in both parser_args and compiler_args (namespace-casing)" - -stdout=$(rewatch compiler-args packages/namespace-casing/src/Consume.res 2>/dev/null) -if [ $? -ne 0 ]; then - error "Error grabbing compiler args for packages/namespace-casing/src/Consume.res" - exit 1 -fi - -# The package has warnings.number = +1000 and warnings.error = -2000 -# Expect both parser_args and compiler_args to include -warn-error/-2000 and -w/+1000 -warn_error_flag_count=$(echo "$stdout" | grep -F -o '"-warn-error"' | wc -l | xargs) -warn_error_val_count=$(echo "$stdout" | grep -F -o '"-2000"' | wc -l | xargs) -warn_number_flag_count=$(echo "$stdout" | grep -F -o '"-w"' | wc -l | xargs) -warn_number_val_count=$(echo "$stdout" | grep -F -o '"+1000"' | wc -l | xargs) - -if [ "$warn_error_flag_count" -ne 2 ] || [ "$warn_error_val_count" -ne 2 ] || [ "$warn_number_flag_count" -ne 2 ] || [ "$warn_number_val_count" -ne 2 ]; then - error "Expected -w/+1000 and -warn-error/-2000 to appear twice (parser_args and compiler_args)" - echo "$stdout" - exit 1 -fi - -success "warnings/error flags present in both parser and compiler args (namespace-casing)" diff --git a/rewatch/tests/compiler-args/01-compiler-args-cwd-invariant.sh b/rewatch/tests/compiler-args/01-compiler-args-cwd-invariant.sh new file mode 100755 index 00000000000..fa48ebc77d4 --- /dev/null +++ b/rewatch/tests/compiler-args/01-compiler-args-cwd-invariant.sh @@ -0,0 +1,37 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should not matter where we grab the compiler-args for a file" + +# Capture stdout for both invocations +stdout_root=$(rewatch compiler-args packages/file-casing/src/Consume.res 2>/dev/null) +stdout_pkg=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" compiler-args src/Consume.res 2>/dev/null) + +error_output=$(rewatch compiler-args packages/file-casing/src/Consume.res 2>&1) +if [ $? -ne 0 ]; then + error "Error grabbing compiler args for packages/file-casing/src/Consume.res" + printf "%s\n" "$error_output" >&2 + exit 1 +fi +error_output=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" compiler-args src/Consume.res 2>&1) +if [ $? -ne 0 ]; then + error "Error grabbing compiler args for src/Consume.res in packages/file-casing" + printf "%s\n" "$error_output" >&2 + exit 1 +fi + +# Compare the stdout of both runs; must be exactly identical +tmp1=$(mktemp); tmp2=$(mktemp) +trap 'rm -f "$tmp1" "$tmp2"' EXIT +printf "%s" "$stdout_root" > "$tmp1" +printf "%s" "$stdout_pkg" > "$tmp2" +if git diff --no-index --exit-code "$tmp1" "$tmp2" > /dev/null; then + success "compiler-args stdout is identical regardless of cwd" +else + error "compiler-args stdout differs depending on cwd" + echo "---- diff ----" + git diff --no-index "$tmp1" "$tmp2" || true + exit 1 +fi diff --git a/rewatch/tests/compiler-args/02-warnings-in-parser-and-compiler.sh b/rewatch/tests/compiler-args/02-warnings-in-parser-and-compiler.sh new file mode 100755 index 00000000000..2a464878880 --- /dev/null +++ b/rewatch/tests/compiler-args/02-warnings-in-parser-and-compiler.sh @@ -0,0 +1,27 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: warnings/error flags appear in both parser_args and compiler_args (namespace-casing)" + +stdout=$(rewatch compiler-args packages/namespace-casing/src/Consume.res 2>/dev/null) +if [ $? -ne 0 ]; then + error "Error grabbing compiler args for packages/namespace-casing/src/Consume.res" + exit 1 +fi + +# The package has warnings.number = +1000 and warnings.error = -2000 +# Expect both parser_args and compiler_args to include -warn-error/-2000 and -w/+1000 +warn_error_flag_count=$(echo "$stdout" | grep -F -o '"-warn-error"' | wc -l | xargs) +warn_error_val_count=$(echo "$stdout" | grep -F -o '"-2000"' | wc -l | xargs) +warn_number_flag_count=$(echo "$stdout" | grep -F -o '"-w"' | wc -l | xargs) +warn_number_val_count=$(echo "$stdout" | grep -F -o '"+1000"' | wc -l | xargs) + +if [ "$warn_error_flag_count" -ne 2 ] || [ "$warn_error_val_count" -ne 2 ] || [ "$warn_number_flag_count" -ne 2 ] || [ "$warn_number_val_count" -ne 2 ]; then + error "Expected -w/+1000 and -warn-error/-2000 to appear twice (parser_args and compiler_args)" + echo "$stdout" + exit 1 +fi + +success "warnings/error flags present in both parser and compiler args (namespace-casing)" diff --git a/rewatch/tests/experimental-invalid.sh b/rewatch/tests/experimental-invalid/01-invalid-experimental-key.sh similarity index 95% rename from rewatch/tests/experimental-invalid.sh rename to rewatch/tests/experimental-invalid/01-invalid-experimental-key.sh index 6c739765fe0..ae52f70ae7d 100755 --- a/rewatch/tests/experimental-invalid.sh +++ b/rewatch/tests/experimental-invalid/01-invalid-experimental-key.sh @@ -1,7 +1,7 @@ #!/bin/bash cd $(dirname $0) -source "./utils.sh" -cd ../testrepo +source "../utils.sh" +cd ../../testrepo bold "Test: invalid experimental-features keys produce helpful error" @@ -33,4 +33,3 @@ if [ $? -ne 0 ]; then fi success "invalid experimental-features produces helpful error" - diff --git a/rewatch/tests/experimental.sh b/rewatch/tests/experimental.sh deleted file mode 100755 index c584f11c1bf..00000000000 --- a/rewatch/tests/experimental.sh +++ /dev/null @@ -1,125 +0,0 @@ -#!/bin/bash -cd $(dirname $0) -source "./utils.sh" -cd ../testrepo - -bold "Test: experimental-features in rescript.json emits -enable-experimental as string list" - -# Backup rescript.json -cp rescript.json rescript.json.bak - -# Inject experimental-features enabling LetUnwrap using node for portability -node -e ' -const fs=require("fs"); -const j=JSON.parse(fs.readFileSync("rescript.json","utf8")); -j["experimental-features"]={LetUnwrap:true}; -fs.writeFileSync("rescript.json", JSON.stringify(j,null,2)); -' - -stdout=$(rewatch compiler-args packages/file-casing/src/Consume.res 2>/dev/null) -if [ $? -ne 0 ]; then - mv rescript.json.bak rescript.json - error "Error grabbing compiler args with experimental-features enabled" - exit 1 -fi - -# Expect repeated string-list style: two "-enable-experimental" entries and "LetUnwrap" present -enable_count=$(echo "$stdout" | grep -o '"-enable-experimental"' | wc -l | xargs) -echo "$stdout" | grep -q '"LetUnwrap"' -letunwrap_ok=$? -if [ "$enable_count" -ne 2 ] || [ $letunwrap_ok -ne 0 ]; then - mv rescript.json.bak rescript.json - error "Expected two occurrences of -enable-experimental and presence of LetUnwrap in compiler-args output" - echo "$stdout" - exit 1 -fi - -# Restore original rescript.json -mv rescript.json.bak rescript.json - -success "experimental-features emits -enable-experimental twice as string list" - -bold "Test: build surfaces experimental-features list parse error" - -cp rescript.json rescript.json.bak - -node -e ' -const fs = require("fs"); -const j = JSON.parse(fs.readFileSync("rescript.json", "utf8")); -j["experimental-features"] = ["LetUnwrap"]; -fs.writeFileSync("rescript.json", JSON.stringify(j, null, 2)); -' - -out=$(rewatch build 2>&1) -status=$? - -mv rescript.json.bak rescript.json -rm -f lib/rescript.lock - -if [ $status -eq 0 ]; then - error "Expected build to fail for experimental-features list input" - echo "$out" - exit 1 -fi - -echo "$out" | grep -q "Could not read rescript.json" -if [ $? -ne 0 ]; then - error "Missing rescript.json path context in build error" - echo "$out" - exit 1 -fi - -echo "$out" | grep -qi "experimental-features.*invalid type" -if [ $? -ne 0 ]; then - error "Missing detailed parse error in build output" - echo "$out" - exit 1 -fi - -success "Experimental-features list produces detailed build error" - -bold "Test: watch reports invalid experimental-features without panicking" - -cp rescript.json rescript.json.bak - -node -e ' -const fs = require("fs"); -const cfg = JSON.parse(fs.readFileSync("rescript.json", "utf8")); -cfg["experimental-features"] = ["LetUnwrap"]; -fs.writeFileSync("rescript.json", JSON.stringify(cfg, null, 2)); -' - -out=$(rewatch watch 2>&1) -status=$? - -mv rescript.json.bak rescript.json -rm -f lib/rescript.lock - -if [ $status -eq 0 ]; then - error "Expected watch to fail for invalid experimental-features list" - echo "$out" - exit 1 -fi - -echo "$out" | grep -q "Could not read rescript.json" -if [ $? -ne 0 ]; then - error "Missing rescript.json path context in watch error" - echo "$out" - exit 1 -fi - -echo "$out" | grep -qi "experimental-features.*invalid type" -if [ $? -ne 0 ]; then - error "Missing detailed parse error for experimental-features list" - echo "$out" - exit 1 -fi - -echo "$out" | grep -q "panicked" -if [ $? -eq 0 ]; then - error "Watcher should not panic when config is invalid" - echo "$out" - exit 1 -fi - -success "Invalid experimental-features list handled without panic" diff --git a/rewatch/tests/experimental/01-experimental-features-emit.sh b/rewatch/tests/experimental/01-experimental-features-emit.sh new file mode 100755 index 00000000000..1cd7f1db993 --- /dev/null +++ b/rewatch/tests/experimental/01-experimental-features-emit.sh @@ -0,0 +1,40 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: experimental-features in rescript.json emits -enable-experimental as string list" + +# Backup rescript.json +cp rescript.json rescript.json.bak + +# Inject experimental-features enabling LetUnwrap using node for portability +node -e ' +const fs=require("fs"); +const j=JSON.parse(fs.readFileSync("rescript.json","utf8")); +j["experimental-features"]={LetUnwrap:true}; +fs.writeFileSync("rescript.json", JSON.stringify(j,null,2)); +' + +stdout=$(rewatch compiler-args packages/file-casing/src/Consume.res 2>/dev/null) +if [ $? -ne 0 ]; then + mv rescript.json.bak rescript.json + error "Error grabbing compiler args with experimental-features enabled" + exit 1 +fi + +# Expect repeated string-list style: two "-enable-experimental" entries and "LetUnwrap" present +enable_count=$(echo "$stdout" | grep -o '"-enable-experimental"' | wc -l | xargs) +echo "$stdout" | grep -q '"LetUnwrap"' +letunwrap_ok=$? +if [ "$enable_count" -ne 2 ] || [ $letunwrap_ok -ne 0 ]; then + mv rescript.json.bak rescript.json + error "Expected two occurrences of -enable-experimental and presence of LetUnwrap in compiler-args output" + echo "$stdout" + exit 1 +fi + +# Restore original rescript.json +mv rescript.json.bak rescript.json + +success "experimental-features emits -enable-experimental twice as string list" diff --git a/rewatch/tests/experimental/02-experimental-features-parse-error.sh b/rewatch/tests/experimental/02-experimental-features-parse-error.sh new file mode 100755 index 00000000000..fd55f2dc0c4 --- /dev/null +++ b/rewatch/tests/experimental/02-experimental-features-parse-error.sh @@ -0,0 +1,43 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: build surfaces experimental-features list parse error" + +cp rescript.json rescript.json.bak + +node -e ' +const fs = require("fs"); +const j = JSON.parse(fs.readFileSync("rescript.json", "utf8")); +j["experimental-features"] = ["LetUnwrap"]; +fs.writeFileSync("rescript.json", JSON.stringify(j, null, 2)); +' + +out=$(rewatch build 2>&1) +status=$? + +mv rescript.json.bak rescript.json +rm -f lib/rescript.lock + +if [ $status -eq 0 ]; then + error "Expected build to fail for experimental-features list input" + echo "$out" + exit 1 +fi + +echo "$out" | grep -q "Could not read rescript.json" +if [ $? -ne 0 ]; then + error "Missing rescript.json path context in build error" + echo "$out" + exit 1 +fi + +echo "$out" | grep -qi "experimental-features.*invalid type" +if [ $? -ne 0 ]; then + error "Missing detailed parse error in build output" + echo "$out" + exit 1 +fi + +success "Experimental-features list produces detailed build error" diff --git a/rewatch/tests/experimental/03-watch-invalid-experimental.sh b/rewatch/tests/experimental/03-watch-invalid-experimental.sh new file mode 100755 index 00000000000..79557f26990 --- /dev/null +++ b/rewatch/tests/experimental/03-watch-invalid-experimental.sh @@ -0,0 +1,50 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: watch reports invalid experimental-features without panicking" + +cp rescript.json rescript.json.bak + +node -e ' +const fs = require("fs"); +const cfg = JSON.parse(fs.readFileSync("rescript.json", "utf8")); +cfg["experimental-features"] = ["LetUnwrap"]; +fs.writeFileSync("rescript.json", JSON.stringify(cfg, null, 2)); +' + +out=$(rewatch watch 2>&1) +status=$? + +mv rescript.json.bak rescript.json +rm -f lib/rescript.lock + +if [ $status -eq 0 ]; then + error "Expected watch to fail for invalid experimental-features list" + echo "$out" + exit 1 +fi + +echo "$out" | grep -q "Could not read rescript.json" +if [ $? -ne 0 ]; then + error "Missing rescript.json path context in watch error" + echo "$out" + exit 1 +fi + +echo "$out" | grep -qi "experimental-features.*invalid type" +if [ $? -ne 0 ]; then + error "Missing detailed parse error for experimental-features list" + echo "$out" + exit 1 +fi + +echo "$out" | grep -q "panicked" +if [ $? -eq 0 ]; then + error "Watcher should not panic when config is invalid" + echo "$out" + exit 1 +fi + +success "Invalid experimental-features list handled without panic" diff --git a/rewatch/tests/format.sh b/rewatch/tests/format.sh deleted file mode 100755 index 2b409f85c2c..00000000000 --- a/rewatch/tests/format.sh +++ /dev/null @@ -1,59 +0,0 @@ -source "./utils.sh" -cd ../testrepo - -bold "Test: It should format all files" - -git diff --name-only ./ -error_output=$("$REWATCH_EXECUTABLE" format) -git_diff_file_count=$(git diff --name-only ./ | wc -l | xargs) -if [ $? -eq 0 ] && [ $git_diff_file_count -eq 9 ]; -then - success "Test package formatted. Got $git_diff_file_count changed files." - git restore . -else - error "Error formatting test package" - echo "Expected 8 files to be changed, got $git_diff_file_count" - echo $error_output - exit 1 -fi - -bold "Test: It should format a single file" - -error_output=$("$REWATCH_EXECUTABLE" format packages/dep01/src/Dep01.res) -git_diff_file_count=$(git diff --name-only ./ | wc -l | xargs) -if [ $? -eq 0 ] && [ $git_diff_file_count -eq 1 ]; -then - success "Single file formatted successfully" - git restore . -else - error "Error formatting single file" - echo $error_output - exit 1 -fi - -bold "Test: It should format from stdin" - -error_output=$(echo "let x = 1" | "$REWATCH_EXECUTABLE" format --stdin .res) -if [ $? -eq 0 ]; -then - success "Stdin formatted successfully" -else - error "Error formatting from stdin" - echo $error_output - exit 1 -fi - -bold "Test: It should format only the current project" - -error_output=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" format) -git_diff_file_count=$(git diff --name-only ./ | wc -l | xargs) -if [ $? -eq 0 ] && [ $git_diff_file_count -eq 2 ]; -then - success "file-casing formatted" - git restore . -else - error "Error formatting current project file-casing" - echo "Expected 2 files to be changed, got $git_diff_file_count" - echo $error_output - exit 1 -fi diff --git a/rewatch/tests/format/01-format-all-files.sh b/rewatch/tests/format/01-format-all-files.sh new file mode 100755 index 00000000000..ece245beab3 --- /dev/null +++ b/rewatch/tests/format/01-format-all-files.sh @@ -0,0 +1,20 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should format all files" + +git diff --name-only ./ +error_output=$("$REWATCH_EXECUTABLE" format) +git_diff_file_count=$(git diff --name-only ./ | wc -l | xargs) +if [ $? -eq 0 ] && [ $git_diff_file_count -eq 9 ]; +then + success "Test package formatted. Got $git_diff_file_count changed files." + git restore . +else + error "Error formatting test package" + echo "Expected 9 files to be changed, got $git_diff_file_count" + echo $error_output + exit 1 +fi diff --git a/rewatch/tests/format/02-format-single-file.sh b/rewatch/tests/format/02-format-single-file.sh new file mode 100755 index 00000000000..e5594956f2d --- /dev/null +++ b/rewatch/tests/format/02-format-single-file.sh @@ -0,0 +1,18 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should format a single file" + +error_output=$("$REWATCH_EXECUTABLE" format packages/dep01/src/Dep01.res) +git_diff_file_count=$(git diff --name-only ./ | wc -l | xargs) +if [ $? -eq 0 ] && [ $git_diff_file_count -eq 1 ]; +then + success "Single file formatted successfully" + git restore . +else + error "Error formatting single file" + echo $error_output + exit 1 +fi diff --git a/rewatch/tests/format/03-format-stdin.sh b/rewatch/tests/format/03-format-stdin.sh new file mode 100755 index 00000000000..091b3b99f62 --- /dev/null +++ b/rewatch/tests/format/03-format-stdin.sh @@ -0,0 +1,16 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should format from stdin" + +error_output=$(echo "let x = 1" | "$REWATCH_EXECUTABLE" format --stdin .res) +if [ $? -eq 0 ]; +then + success "Stdin formatted successfully" +else + error "Error formatting from stdin" + echo $error_output + exit 1 +fi diff --git a/rewatch/tests/format/04-format-current-project.sh b/rewatch/tests/format/04-format-current-project.sh new file mode 100755 index 00000000000..80fc751553c --- /dev/null +++ b/rewatch/tests/format/04-format-current-project.sh @@ -0,0 +1,19 @@ +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo + +bold "Test: It should format only the current project" + +error_output=$(cd packages/file-casing && "$REWATCH_EXECUTABLE" format) +git_diff_file_count=$(git diff --name-only ./ | wc -l | xargs) +if [ $? -eq 0 ] && [ $git_diff_file_count -eq 2 ]; +then + success "file-casing formatted" + git restore . +else + error "Error formatting current project file-casing" + echo "Expected 2 files to be changed, got $git_diff_file_count" + echo $error_output + exit 1 +fi diff --git a/rewatch/tests/lock.sh b/rewatch/tests/lock/01-lock-when-watching.sh similarity index 91% rename from rewatch/tests/lock.sh rename to rewatch/tests/lock/01-lock-when-watching.sh index 41b12a506fa..1f6953fcc70 100755 --- a/rewatch/tests/lock.sh +++ b/rewatch/tests/lock/01-lock-when-watching.sh @@ -1,5 +1,7 @@ -source "./utils.sh" -cd ../testrepo +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo bold "Test: It should lock - when watching" @@ -53,4 +55,4 @@ else exit_watcher fi -rm tmp.txt \ No newline at end of file +rm tmp.txt diff --git a/rewatch/tests/snapshots/dev-dependency-used-by-non-dev-source.txt b/rewatch/tests/snapshots/dev-dependency-used-by-non-dev-source.txt index 6476e9d1833..e998656d162 100644 --- a/rewatch/tests/snapshots/dev-dependency-used-by-non-dev-source.txt +++ b/rewatch/tests/snapshots/dev-dependency-used-by-non-dev-source.txt @@ -1,6 +1,6 @@ Cleaned 0/428 -Parsed 2 source files -Compiled 2 modules +Parsed 1 source files +Compiled 1 modules The field 'ignored-dirs' found in the package config of '@testrepo/deprecated-config' is not supported by ReScript 12's new build system. diff --git a/rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt b/rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt index 5d319818931..67b0ccfde2d 100644 --- a/rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt +++ b/rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt @@ -1,6 +1,6 @@ -Cleaned 2/428 -Parsed 2 source files -Compiled 3 modules +Cleaned 1/428 +Parsed 1 source files +Compiled 2 modules The field 'ignored-dirs' found in the package config of '@testrepo/deprecated-config' is not supported by ReScript 12's new build system. diff --git a/rewatch/tests/snapshots/rename-file-internal-dep.txt b/rewatch/tests/snapshots/rename-file-internal-dep.txt index 7f8e127a676..71376e15b94 100644 --- a/rewatch/tests/snapshots/rename-file-internal-dep.txt +++ b/rewatch/tests/snapshots/rename-file-internal-dep.txt @@ -1,5 +1,5 @@ -Cleaned 2/428 -Parsed 2 source files +Cleaned 1/428 +Parsed 1 source files Compiled 2 modules The field 'ignored-dirs' found in the package config of '@testrepo/deprecated-config' is not supported by ReScript 12's new build system. diff --git a/rewatch/tests/snapshots/rename-file-with-interface.txt b/rewatch/tests/snapshots/rename-file-with-interface.txt index 25a123d256a..22659e2b2de 100644 --- a/rewatch/tests/snapshots/rename-file-with-interface.txt +++ b/rewatch/tests/snapshots/rename-file-with-interface.txt @@ -1,7 +1,7 @@  No implementation file found for interface file (skipping): src/ModuleWithInterface.resi Cleaned 2/428 Parsed 1 source files -Compiled 2 modules +Compiled 1 modules The field 'ignored-dirs' found in the package config of '@testrepo/deprecated-config' is not supported by ReScript 12's new build system. diff --git a/rewatch/tests/snapshots/rename-interface-file.txt b/rewatch/tests/snapshots/rename-interface-file.txt index b45dfa121db..ef47166a40e 100644 --- a/rewatch/tests/snapshots/rename-interface-file.txt +++ b/rewatch/tests/snapshots/rename-interface-file.txt @@ -1,7 +1,7 @@  No implementation file found for interface file (skipping): src/ModuleWithInterface2.resi Cleaned 1/428 Parsed 1 source files -Compiled 2 modules +Compiled 1 modules The field 'ignored-dirs' found in the package config of '@testrepo/deprecated-config' is not supported by ReScript 12's new build system. diff --git a/rewatch/tests/suffix.sh b/rewatch/tests/suffix/01-custom-suffix.sh similarity index 94% rename from rewatch/tests/suffix.sh rename to rewatch/tests/suffix/01-custom-suffix.sh index fc5436ebdb5..b85e165a670 100755 --- a/rewatch/tests/suffix.sh +++ b/rewatch/tests/suffix/01-custom-suffix.sh @@ -1,5 +1,7 @@ -source "./utils.sh" -cd ../testrepo +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo bold "Test: It should support custom suffixes" diff --git a/rewatch/tests/suite.sh b/rewatch/tests/suite.sh index b484df0ee0e..210b7701786 100755 --- a/rewatch/tests/suite.sh +++ b/rewatch/tests/suite.sh @@ -53,4 +53,56 @@ else exit 1 fi -./compile.sh && ./watch.sh && ./lock.sh && ./suffix.sh && ./format.sh && ./clean.sh && ./experimental.sh && ./experimental-invalid.sh && ./compiler-args.sh +# Individual test files +# Comment out any test to skip it + +# Compile tests +./compile/01-basic-compile.sh && +./compile/02-standalone-package.sh && +./compile/03-rename-file.sh && +./compile/04-rename-file-internal-dep.sh && +./compile/05-rename-file-namespace.sh && +./compile/06-rename-interface-file.sh && +./compile/07-rename-file-with-interface.sh && +./compile/08-remove-file.sh && +./compile/09-dependency-cycle.sh && +./compile/10-duplicate-module-name.sh && +./compile/11-dev-dependency-non-dev-source.sh && +./compile/12-compile-dev-dependencies.sh && +./compile/13-no-infinite-loop-with-cycle.sh && +./compile/14-no-testrepo-changes.sh && +./compile/15-no-new-files.sh && +./compile/16-snapshots-unchanged.sh && + +# Watch tests +./watch/01-watch-recompile.sh && + +# Lock tests +./lock/01-lock-when-watching.sh && + +# Suffix tests +./suffix/01-custom-suffix.sh && + +# Format tests +./format/01-format-all-files.sh && +./format/02-format-single-file.sh && +./format/03-format-stdin.sh && +./format/04-format-current-project.sh && + +# Clean tests +./clean/01-clean-single-project.sh && +./clean/02-clean-dev-dependencies.sh && +./clean/03-clean-node-modules.sh && +./clean/04-clean-rebuild-no-compiler-update.sh && + +# Experimental tests +./experimental/01-experimental-features-emit.sh && +./experimental/02-experimental-features-parse-error.sh && +./experimental/03-watch-invalid-experimental.sh && + +# Experimental-invalid tests +./experimental-invalid/01-invalid-experimental-key.sh && + +# Compiler-args tests +./compiler-args/01-compiler-args-cwd-invariant.sh && +./compiler-args/02-warnings-in-parser-and-compiler.sh diff --git a/rewatch/tests/watch.sh b/rewatch/tests/watch/01-watch-recompile.sh similarity index 94% rename from rewatch/tests/watch.sh rename to rewatch/tests/watch/01-watch-recompile.sh index 2a5b36bb77d..008b490d959 100755 --- a/rewatch/tests/watch.sh +++ b/rewatch/tests/watch/01-watch-recompile.sh @@ -1,5 +1,7 @@ -source "./utils.sh" -cd ../testrepo +#!/bin/bash +cd $(dirname $0) +source "../utils.sh" +cd ../../testrepo bold "Test: It should watch" @@ -70,4 +72,4 @@ else exit 1 fi -exit_watcher \ No newline at end of file +exit_watcher