mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-12-28 18:51:06 +00:00
Split tests into one file per test directory
This commit is contained in:
parent
331d5ea724
commit
5f01ff02fa
@ -1,51 +1,64 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# This is a script to generate "awkward" files and directories as test cases,
|
# This is a script to generate “awkward” files and directories that the
|
||||||
# to check that exa can actually handle them: symlinks that point at
|
# testing scripts use as integration test cases.
|
||||||
# themselves, directories that you aren't allowed to view, files with strange
|
#
|
||||||
# extended attributes, that sort of thing.
|
# Tests like these verify that exa is doing the right thing at every step,
|
||||||
|
# from command-line parsing to colourising the output properly -- especially
|
||||||
|
# on multiple or weird platforms!
|
||||||
|
#
|
||||||
|
# Examples of the things it generates are:
|
||||||
|
# - files with newlines in their name
|
||||||
|
# - files with invalid UTF-8 in their name
|
||||||
|
# - directories you aren’t allowed to open
|
||||||
|
# - files with users and groups that don’t exist
|
||||||
|
# - directories you aren’t allowed to read the xattrs for
|
||||||
|
|
||||||
|
|
||||||
## -- configuration --
|
## -- configuration --
|
||||||
|
|
||||||
# Directory that the files should be generated in.
|
# Directory that the files should be generated in.
|
||||||
DIR=testcases
|
DIR=testcases
|
||||||
|
|
||||||
if [[ -e "$DIR" ]]
|
|
||||||
then
|
|
||||||
echo "'$DIR' already exists - aborting" >&2
|
|
||||||
exit 2
|
|
||||||
fi
|
|
||||||
|
|
||||||
# You! Yes, you, the name of the user running this script.
|
# You! Yes, you, the name of the user running this script.
|
||||||
YOU=`whoami`
|
YOU=`whoami`
|
||||||
|
|
||||||
# Someone with *higher* privileges than yourself, such as root.
|
# Someone with *higher* privileges than yourself, such as root.
|
||||||
ROOT=root
|
ROOT=root
|
||||||
|
|
||||||
# A UID that doesn't map to any user on the system.
|
# A UID that doesn’t map to any user on the system.
|
||||||
INVALID_UID=666
|
INVALID_UID=666
|
||||||
|
|
||||||
# A GID that doesn't map to any group on the system.
|
# A GID that doesn’t map to any group on the system.
|
||||||
INVALID_GID=616
|
INVALID_GID=616
|
||||||
|
|
||||||
# List commands as they are run
|
# Get confirmation from the user before running.
|
||||||
# set -x
|
echo "This script will generate files into the $DIR directory."
|
||||||
|
echo "It requires sudo for the '$ROOT' user."
|
||||||
|
echo "You may want to edit this file before running it."
|
||||||
|
read -r -p "Continue? [y/N] " response
|
||||||
|
if [[ ! $response =~ ^([yY][eE][sS]|[yY])$ ]]
|
||||||
|
then
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
# Abort on any error!
|
# First things first, don’t try to overwrite the testcases if they already
|
||||||
|
# exist. It’s safer to just start again from scratch.
|
||||||
|
if [[ -e "$DIR" ]]
|
||||||
|
then
|
||||||
|
echo "'$DIR' already exists - aborting" >&2
|
||||||
|
echo "(you'll probably have to sudo rm it.)" >&2
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Abort if anything goes wrong past this point!
|
||||||
abort() { echo 'Hit an error - aborting' >&2; exit 1; }
|
abort() { echo 'Hit an error - aborting' >&2; exit 1; }
|
||||||
trap 'abort' ERR
|
trap 'abort' ERR
|
||||||
|
|
||||||
# Get confirmation from the user before running.
|
# List commands as they are run
|
||||||
|
set -x
|
||||||
# echo "This script will generate files into the $DIR directory."
|
|
||||||
# echo "It requires sudo for the '$ROOT' user."
|
|
||||||
# echo "You probably want to edit this file before running it."
|
|
||||||
# read -r -p "Continue? [y/N] " response
|
|
||||||
# if [[ ! $response =~ ^([yY][eE][sS]|[yY])$ ]]
|
|
||||||
# then
|
|
||||||
# exit 2
|
|
||||||
# fi
|
|
||||||
|
|
||||||
|
# Let’s go!
|
||||||
mkdir "$DIR"
|
mkdir "$DIR"
|
||||||
|
|
||||||
|
|
||||||
@ -61,8 +74,8 @@ ln -s nowhere "$DIR/links/broken"
|
|||||||
|
|
||||||
mkdir "$DIR/passwd"
|
mkdir "$DIR/passwd"
|
||||||
|
|
||||||
# sudo is needed for these because we technically aren't a member of the
|
# sudo is needed for these because we technically aren’t a member of the
|
||||||
# groups (because they don't exist), and chown and chgrp are smart enough to
|
# groups (because they don’t exist), and chown and chgrp are smart enough to
|
||||||
# disallow it!
|
# disallow it!
|
||||||
|
|
||||||
touch "$DIR/passwd/unknown-uid"
|
touch "$DIR/passwd/unknown-uid"
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
extern crate exa;
|
extern crate exa;
|
||||||
use exa::Exa;
|
use exa::Exa;
|
||||||
|
|
||||||
/// ---------------------------------------------------------------------------
|
/// --------------------------------------------------------------------------
|
||||||
/// These tests assume that the ‘generate annoying testcases’ script has been
|
/// These tests assume that the ‘generate annoying testcases’ script has been
|
||||||
/// run first. Otherwise, they will break!
|
/// run first. Otherwise, they will break!
|
||||||
/// ---------------------------------------------------------------------------
|
/// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
static DIRECTORIES: &'static str = concat!(
|
static DIRECTORIES: &'static str = concat!(
|
||||||
"\x1B[1;34m", "attributes", "\x1B[0m", '\n',
|
"\x1B[1;34m", "attributes", "\x1B[0m", '\n',
|
||||||
|
//"\x1B[1;34m", "filenames", "\x1B[0m", '\n',
|
||||||
"\x1B[1;34m", "links", "\x1B[0m", '\n',
|
"\x1B[1;34m", "links", "\x1B[0m", '\n',
|
||||||
"\x1B[1;34m", "passwd", "\x1B[0m", '\n',
|
"\x1B[1;34m", "passwd", "\x1B[0m", '\n',
|
||||||
"\x1B[1;34m", "permissions", "\x1B[0m", '\n',
|
"\x1B[1;34m", "permissions", "\x1B[0m", '\n',
|
||||||
@ -21,16 +22,3 @@ fn directories() {
|
|||||||
assert_eq!(output, DIRECTORIES.as_bytes());
|
assert_eq!(output, DIRECTORIES.as_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PERMISSIONS: &'static str = concat!(
|
|
||||||
"\x1B[1;32m", "all-permissions", "\x1B[0m", '\n',
|
|
||||||
"\x1B[1;34m", "forbidden-directory", "\x1B[0m", '\n',
|
|
||||||
"no-permissions", '\n',
|
|
||||||
);
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn permissions() {
|
|
||||||
let mut output = Vec::<u8>::new();
|
|
||||||
Exa::new( &[ "-1", "testcases/permissions" ], &mut output).unwrap().run().unwrap();
|
|
||||||
assert_eq!(output, PERMISSIONS.as_bytes());
|
|
||||||
}
|
|
21
tests/permissions.rs
Normal file
21
tests/permissions.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
extern crate exa;
|
||||||
|
use exa::Exa;
|
||||||
|
|
||||||
|
/// --------------------------------------------------------------------------
|
||||||
|
/// These tests assume that the ‘generate annoying testcases’ script has been
|
||||||
|
/// run first. Otherwise, they will break!
|
||||||
|
/// --------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
static PERMISSIONS: &'static str = concat!(
|
||||||
|
"\x1B[1;32m", "all-permissions", "\x1B[0m", '\n',
|
||||||
|
"\x1B[1;34m", "forbidden-directory", "\x1B[0m", '\n',
|
||||||
|
"no-permissions", '\n',
|
||||||
|
);
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn permissions() {
|
||||||
|
let mut output = Vec::<u8>::new();
|
||||||
|
Exa::new( &[ "-1", "testcases/permissions" ], &mut output).unwrap().run().unwrap();
|
||||||
|
assert_eq!(output, PERMISSIONS.as_bytes());
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user