Skip to content

Commit

Permalink
Tests for softlink nested path and env export
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Jun 24, 2020
1 parent 4248e00 commit 967b056
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
project Checkenv is

for Source_Dirs use ("src");
for Object_Dir use "obj";
for Exec_Dir use ".";
for Main use ("checkenv.adb");

package Builder is
for Switches ("ada") use ("-j0", "-g");
end Builder;

package Compiler is
for Switches ("ada") use
("-gnatVa", "-gnatwa", "-g", "-O2",
"-gnata", "-gnato", "-fstack-check");
end Compiler;

package Binder is
for Switches ("ada") use ("-Es");
end Binder;

end Checkenv;
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
with GNAT.IO; use GNAT.IO;
with GNAT.OS_Lib; use GNAT.OS_Lib;

procedure Checkenv is
begin
-- Check that "CHECKENV_TEST_VAR" is defined and print message accordingly
-- to stderr
if Getenv ("CHECKENV_TEST_VAR").all /= "" then
Put_Line (Standard_Error, "CHECKENV_TEST_VAR exists");
else
Put_Line (Standard_Error, "CHECKENV_TEST_VAR does NOT exist");
end if;
end Checkenv;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[general]
description = "Sample crate"
licenses = []
maintainers = ["any@bo.dy"]
maintainers-logins = ["someone"]

environment.CHECKENV_TEST_VAR.set = "defined"

[[general.actions]]
type = "post-fetch"
command = ["gprbuild", "-p"]

[[general.actions]]
type = "post-fetch"
command = ["./checkenv"] # self-run to verify the env var exists

['1.0']
origin = "file://../../crates/checkenv"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[general]
description = "Sample crate"
licenses = []
maintainers = ["any@bo.dy"]
maintainers-logins = ["someone"]

['1.0']
origin = "file://."
depends-on.checkenv = "*"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "0.2"
33 changes: 33 additions & 0 deletions testsuite/tests/setenv/env-during-fetch/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""
Check that an env var is defined during dependency retrieval (get and with)
"""

import os
import re

from drivers.alr import run_alr
from drivers.asserts import assert_match
from drivers.helpers import path_separator


def verify_output(text):
assert_match('.*CHECKENV_TEST_VAR exists\n.*',
text, flags=re.S)

# The "checkenv" crate defines CHECKENV_TEST_VAR. Also, its executable prints
# "CHECKENV_TEST_VAR exists" or "CHECKENV_TEST_VAR does NOT exist" when run.
# The crate defines post-fetch actions to self-build and self-run, so the
# output is generated at the moment we want to check.

# Retrieve a crate that depends on checkenv: checkparent --> checkenv
p = run_alr("get", "checkparent")
verify_output(p.out)

# Create a crate from scratch and add the same dependency to perform the check
# during retrieval by `with`
run_alr("init", "--bin", "xxx")
os.chdir("xxx")
p = run_alr("with", "checkenv")
verify_output(p.out)

print('SUCCESS')
4 changes: 4 additions & 0 deletions testsuite/tests/setenv/env-during-fetch/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
indexes:
my_index:
in_fixtures: false
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[context]
advisory = "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT MANUALLY"
solved = true

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
["0.0.0"]
origin = "file://.."
[general]
description = "Shiny new project"
maintainers = [
"your@email.here",
]
maintainers-logins = [
"github-username",
]

project-files = ["nested/project.gpr"]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "0.2"
29 changes: 29 additions & 0 deletions testsuite/tests/setenv/linked-paths/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"""
Check that both base path, and a extra project path for a softlinked crate is
properly added to the environment
"""

import os
import re

from drivers.alr import run_alr
from drivers.asserts import assert_match
from drivers.helpers import path_separator

# Initialize test crate
run_alr("init", "--bin", "xxx")
os.chdir("xxx")

# Link a folder with also contains crate definitions
run_alr("with", "--use=../my_index/crates/crate_1234")

# Check paths are proper (base and one extra nested)
s = path_separator()
p = run_alr("setenv")
assert_match('export GPR_PROJECT_PATH=".*/my_index/crates/crate_1234'
':.*/my_index/crates/crate_1234/nested/"\n'
'export ALIRE="True"\n'.replace('/', re.escape(path_separator())),
p.out)


print('SUCCESS')
4 changes: 4 additions & 0 deletions testsuite/tests/setenv/linked-paths/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: python-script
indexes:
my_index:
in_fixtures: false

0 comments on commit 967b056

Please sign in to comment.