aboutsummaryrefslogtreecommitdiff
path: root/archive/tests
diff options
context:
space:
mode:
Diffstat (limited to 'archive/tests')
-rw-r--r--archive/tests/1/a.f9011
-rw-r--r--archive/tests/1/b.f9010
-rw-r--r--archive/tests/1/fpm.toml2
-rw-r--r--archive/tests/1/main.f908
-rw-r--r--archive/tests/2/fpm.toml2
-rw-r--r--archive/tests/2/main.f905
-rw-r--r--archive/tests/cli.rs103
7 files changed, 141 insertions, 0 deletions
diff --git a/archive/tests/1/a.f90 b/archive/tests/1/a.f90
new file mode 100644
index 0000000..a4f64a2
--- /dev/null
+++ b/archive/tests/1/a.f90
@@ -0,0 +1,11 @@
+module a
+use b, only: g
+implicit none
+
+contains
+
+ subroutine f()
+ call g()
+ end subroutine
+
+end module
diff --git a/archive/tests/1/b.f90 b/archive/tests/1/b.f90
new file mode 100644
index 0000000..8b57633
--- /dev/null
+++ b/archive/tests/1/b.f90
@@ -0,0 +1,10 @@
+module b
+implicit none
+
+contains
+
+ subroutine g()
+ print *, "g()"
+ end subroutine
+
+end module
diff --git a/archive/tests/1/fpm.toml b/archive/tests/1/fpm.toml
new file mode 100644
index 0000000..c7d48a4
--- /dev/null
+++ b/archive/tests/1/fpm.toml
@@ -0,0 +1,2 @@
+[dependencies]
+a = "4.0.0"
diff --git a/archive/tests/1/main.f90 b/archive/tests/1/main.f90
new file mode 100644
index 0000000..d886be3
--- /dev/null
+++ b/archive/tests/1/main.f90
@@ -0,0 +1,8 @@
+program test1
+use a, only: f
+implicit none
+
+call f()
+
+print *, "TEST1 OK"
+end
diff --git a/archive/tests/2/fpm.toml b/archive/tests/2/fpm.toml
new file mode 100644
index 0000000..c7d48a4
--- /dev/null
+++ b/archive/tests/2/fpm.toml
@@ -0,0 +1,2 @@
+[dependencies]
+a = "4.0.0"
diff --git a/archive/tests/2/main.f90 b/archive/tests/2/main.f90
new file mode 100644
index 0000000..bd820eb
--- /dev/null
+++ b/archive/tests/2/main.f90
@@ -0,0 +1,5 @@
+program test2
+implicit none
+
+print *, "TEST2 OK"
+end
diff --git a/archive/tests/cli.rs b/archive/tests/cli.rs
new file mode 100644
index 0000000..b099721
--- /dev/null
+++ b/archive/tests/cli.rs
@@ -0,0 +1,103 @@
+use assert_cmd::prelude::OutputAssertExt; // Add methods on commands
+use predicates::prelude::{predicate, PredicateBooleanExt}; // Used for writing assertions
+#[cfg(unix)]
+use std::os::unix::process::ExitStatusExt;
+
+pub trait Success2 {
+ // Our own function with better reporting of errors
+ fn success2(self) -> Self;
+}
+
+#[cfg(unix)]
+fn get_signal(status: std::process::ExitStatus) -> Option<i32> {
+ status.signal()
+}
+
+#[cfg(not(unix))]
+fn get_signal(_status: std::process::ExitStatus) -> Option<i32> {
+ None
+}
+
+impl Success2 for assert_cmd::assert::Assert {
+ fn success2(self) -> Self {
+ if !self.get_output().status.success() {
+ let output = self.get_output();
+ let code = output.status.code();
+ println!("status: {}", output.status);
+ println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
+ println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
+ if cfg!(unix) {
+ if code.is_none() {
+ let signal = get_signal(output.status).unwrap();
+ panic!("INTERRUPTED with signal: {}", signal);
+ }
+ }
+ let actual_code = code.unwrap();
+ println!("code: {}", actual_code);
+ panic!("Non zero exit code");
+ }
+ self
+ }
+}
+
+fn fpm_bin() -> std::process::Command {
+ let mut fpm_bin_relative: std::path::PathBuf = ["target", "debug", "fpm"].iter().collect();
+ fpm_bin_relative.set_extension(std::env::consts::EXE_EXTENSION);
+ let fpm_bin_absolute = std::fs::canonicalize(fpm_bin_relative).unwrap();
+ std::process::Command::new(fpm_bin_absolute.to_str().unwrap())
+}
+
+#[test]
+fn test_help() {
+ let mut cmd = fpm_bin();
+ cmd.arg("--help");
+ cmd.assert()
+ .success2()
+ .stdout(
+ predicate::str::contains("--help Prints help information"));
+}
+
+
+#[test]
+fn test_1() {
+ let mut build = fpm_bin();
+ build.arg("build")
+ .arg("--target-dir")
+ .arg("build-test")
+ .current_dir("tests/1");
+ build.assert()
+ .success2()
+ .stdout(predicate::str::contains("Built target p1")
+ .and(predicate::str::contains("TEST1 OK").not()));
+
+ let mut run = fpm_bin();
+ run.arg("run")
+ .arg("--target-dir")
+ .arg("build-test")
+ .current_dir("tests/1");
+ run.assert()
+ .success2()
+ .stdout(predicate::str::contains("TEST1 OK"));
+}
+
+#[test]
+fn test_2() {
+ let mut build = fpm_bin();
+ build.arg("build")
+ .arg("--target-dir")
+ .arg("build-test")
+ .current_dir("tests/2");
+ build.assert()
+ .success2()
+ .stdout(predicate::str::contains("Built target p1")
+ .and(predicate::str::contains("TEST2 OK").not()));
+
+ let mut run = fpm_bin();
+ run.arg("run")
+ .arg("--target-dir")
+ .arg("build-test")
+ .current_dir("tests/2");
+ run.assert()
+ .success2()
+ .stdout(predicate::str::contains("TEST2 OK"));
+}