-
Notifications
You must be signed in to change notification settings - Fork 454
Add setup_scripts to cram tests #12650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,46 @@ | ||||
| Test setup_scripts feature for cram tests | ||||
|
|
||||
| Create a project with a helper script: | ||||
|
|
||||
| $ cat > dune-project << EOF | ||||
| > (lang dune 3.21) | ||||
| > (cram enable) | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| > EOF | ||||
|
|
||||
| $ cat > helpers.sh << 'EOF' | ||||
| > #!/bin/sh | ||||
| > test_helper() { | ||||
| > echo "Helper called: $1" | ||||
| > } | ||||
| > export MY_VAR="test_value_from_helper" | ||||
| > EOF | ||||
|
|
||||
| $ cat > dune << EOF | ||||
| > (cram | ||||
| > (setup_scripts helpers.sh)) | ||||
| > EOF | ||||
|
|
||||
| $ cat > basic.t << 'EOF' | ||||
| > Test that setup scripts are sourced and functions are available | ||||
| > | ||||
| > $ test_helper "foo" | ||||
| > Helper called: foo | ||||
| > | ||||
| > Test that variables from setup scripts are available | ||||
| > | ||||
| > $ echo $MY_VAR | ||||
| > test_value_from_helper | ||||
| > | ||||
| > Check if setup script is visible in test directory | ||||
| > | ||||
| > $ ls *.sh 2>&1 || echo "No sh files" | ||||
| > No sh files | ||||
| > EOF | ||||
|
|
||||
| Run the test: | ||||
|
|
||||
| $ dune runtest | ||||
| File "basic.t", line 1, characters 0-0: | ||||
| Error: Files _build/default/basic.t and _build/default/basic.t.corrected | ||||
| differ. | ||||
| [1] | ||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,26 @@ | ||||
| Test if setup scripts are visible in test directory | ||||
|
|
||||
| $ cat > dune-project << EOF | ||||
| > (lang dune 3.21) | ||||
| > (cram enable) | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| > EOF | ||||
|
|
||||
| $ cat > secret.sh << 'EOF' | ||||
| > MY_SECRET="should_not_be_visible" | ||||
| > EOF | ||||
|
|
||||
| $ cat > dune << EOF | ||||
| > (cram | ||||
| > (setup_scripts secret.sh)) | ||||
| > EOF | ||||
|
|
||||
| $ cat > check.t << 'EOF' | ||||
| > $ ls *.sh 2>&1 || echo "No .sh files found" | ||||
| > No .sh files found | ||||
| > EOF | ||||
|
|
||||
| $ dune runtest | ||||
| File "check.t", line 1, characters 0-0: | ||||
| Error: Files _build/default/check.t and _build/default/check.t.corrected | ||||
| differ. | ||||
| [1] | ||||
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
| @@ -0,0 +1,50 @@ | ||||
| Test that external (absolute path) setup scripts work and are NOT deleted | ||||
|
|
||||
| First, create an external script in /tmp: | ||||
|
|
||||
| $ EXTERNAL_SCRIPT="/tmp/dune_test_external_helper_$$.sh" | ||||
| $ cat > "$EXTERNAL_SCRIPT" << 'EOF' | ||||
| > #!/bin/sh | ||||
| > external_helper() { | ||||
| > echo "External helper called" | ||||
| > } | ||||
| > export EXTERNAL_VAR="from_external_script" | ||||
| > EOF | ||||
| $ chmod +x "$EXTERNAL_SCRIPT" | ||||
|
|
||||
| Create a project that uses the external script: | ||||
|
|
||||
| $ cat > dune-project << EOF | ||||
| > (lang dune 3.21) | ||||
| > (cram enable) | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||
| > EOF | ||||
|
|
||||
| $ cat > dune << EOF | ||||
| > (cram | ||||
| > (setup_scripts $EXTERNAL_SCRIPT)) | ||||
| > EOF | ||||
|
|
||||
| Create a test that uses the external helper: | ||||
|
|
||||
| $ cat > external.t << 'EOF' | ||||
| > Test that external helper is available | ||||
| > | ||||
| > $ external_helper | ||||
| > External helper called | ||||
| > | ||||
| > $ echo $EXTERNAL_VAR | ||||
| > from_external_script | ||||
| > EOF | ||||
|
|
||||
| Run the test: | ||||
|
|
||||
| $ dune runtest | ||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make this test fail so that we can see it has run. |
||||
|
|
||||
| Verify the external script still exists (was NOT deleted): | ||||
|
|
||||
| $ if [ -f "$EXTERNAL_SCRIPT" ]; then | ||||
| > echo "External script still exists" | ||||
| > else | ||||
| > echo "External script was deleted" | ||||
| > fi | ||||
| External script still exists | ||||
Uh oh!
There was an error while loading. Please reload this page.